Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update telemetry to use new errors information #5547

Merged
merged 11 commits into from
Jan 4, 2023
Merged

Conversation

Princesseuh
Copy link
Member

@Princesseuh Princesseuh commented Dec 6, 2022

Changes

This PR updates telemetry events so it uses our new AstroError's data when possible. Most importantly, this allows us to have much better information about our own errors in our stats, since we can safely extract the entire error message anonymized + have a cool name and errorCode to filter errors by. The previous anonymizing logic is kept for unknown errors, so we can still get a basic idea of what happened just in case

Additionally, this PR adds telemetry for errors encountered in dev, as previously we'd only get telemetry for dev server stops.

Testing

Added a test for a error event using our own errors, updated tests that needed it. Made it so telemetry doesn't work in tests to avoid triggering it unnecessarily

Docs

N/A

@changeset-bot
Copy link

changeset-bot bot commented Dec 6, 2022

⚠️ No Changeset found

Latest commit: 736ed5a

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@github-actions github-actions bot added the pkg: astro Related to the core `astro` package (scope) label Dec 6, 2022
* Safely get the error message from an error, even if it's a function.
*/
// eslint-disable-next-line @typescript-eslint/ban-types
function getSafeErrorMessage(message: string | Function): string {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The logic here is the same one that generates the error reference on the docs, which has been proven to work:tm:

@Princesseuh Princesseuh marked this pull request as draft December 6, 2022 22:16
@Princesseuh Princesseuh marked this pull request as ready for review December 27, 2022 21:06
@Princesseuh Princesseuh requested a review from a team as a code owner December 27, 2022 21:06
@Princesseuh Princesseuh self-assigned this Dec 27, 2022
@matthewp
Copy link
Contributor

Is this the first time we are sending errors to telemetry? Assuming so, can we have some tests that include non-anonymous error messages to verify that we are stripping them correctly (or just not sending the message, if that is the intent).

@Princesseuh
Copy link
Member Author

Is this the first time we are sending errors to telemetry? Assuming so, can we have some tests that include non-anonymous error messages to verify that we are stripping them correctly (or just not sending the message, if that is the intent).

It's actually not the first time! The code for reporting errors is from pre-1.0 and hasn't been changed (apart from the fact that we now exclusively use it for unknown errors, whereas before it was used for both known and unknown errors)

Copy link
Member

@delucis delucis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving as docs because this doesn’t actually require docs.

@matthewp
Copy link
Contributor

@Princesseuh Looked over the tests and the only one I think we should add for now is one to verify that the stack trace is not included. Looking at the code I'm pretty sure it will not be, but it would be good to have a test to verify and enforce that going forward.

return message;
} else {
return String.raw({
raw: extractStringFromFunction(message.toString()),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know this method 😃

@@ -145,7 +145,6 @@ export class AstroTelemetry {
// to preview what data would be sent.
return Promise.resolve();
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😎

Copy link
Contributor

@aFuzzyBear aFuzzyBear left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tel you what, this looks really good...💚

@Princesseuh Princesseuh merged commit 63745f8 into main Jan 4, 2023
@Princesseuh Princesseuh deleted the telemetry-errors branch January 4, 2023 16:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pkg: astro Related to the core `astro` package (scope)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants