Skip to content

feat(integrations): console.error is captured as an exception #4034

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

Merged
merged 6 commits into from
Oct 11, 2021
Merged

feat(integrations): console.error is captured as an exception #4034

merged 6 commits into from
Oct 11, 2021

Conversation

freekii
Copy link
Contributor

@freekii freekii commented Oct 7, 2021

Closes #4029.


Before submitting a pull request, please take a look at our
Contributing guidelines and verify:

  • If you've added code that should be tested, please add tests.
  • Ensure your code lints and the test suite passes (yarn lint) & (yarn test).

@freekii freekii requested a review from kamilogorek as a code owner October 7, 2021 14:39
@freekii freekii changed the title feature: console.error is captured as an exception feat(integrations): console.error is captured as an exception Oct 7, 2021
Capture only the first argument for error level logs rather than checking all arguments.

Co-authored-by: Kamil Ogórek <[email protected]>
@kamilogorek
Copy link
Contributor

Code looks good so +1, but before merging and releasing, we should discuss how it can impact creation of new issues in the event stream. cc @getsentry/team-webplatform

@iker-barriocanal
Copy link
Contributor

I don't agree, a console.error is for logging. If you want to capture an exception, you can use captureException.

@kamilogorek
Copy link
Contributor

Sure, that I agree with. Although it would be useful to quickly add integration and capture all console.errors as the first step to integrate Sentry IMO. We can maybe add this behind a configurable option?

Comment on lines 65 to 70
} else if (level === 'error') {
if (args[0] instanceof Error) {
hub.captureException(args[0]);
} else {
hub.captureMessage(message);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Code-wise this is the same as

Suggested change
} else if (level === 'error') {
if (args[0] instanceof Error) {
hub.captureException(args[0]);
} else {
hub.captureMessage(message);
}
} else if (level === 'error' && args[0] instanceof Error) {
hub.captureException(args[0]);

@rhcarvalho
Copy link
Contributor

Perhaps we can hear from @freekii what was the motivation behind this change?

If we understand the use case better we can discuss if the code change is appropriate or if there's something else we can do.

@freekii
Copy link
Contributor Author

freekii commented Oct 8, 2021

I don't believe that I am the best person to ask. I have very recently begun contributing to open source projects and found this issue which seemed like a good place to get started! Sorry I am unable to add more clarity.

@rhcarvalho
Copy link
Contributor

@freekii, got it. My bad I didn't realize the related issue 😓

Copy link
Contributor

@iker-barriocanal iker-barriocanal left a comment

Choose a reason for hiding this comment

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

LGTM, please update the branch.

@kamilogorek kamilogorek merged commit 1d8c500 into getsentry:master Oct 11, 2021
@klouskingsley
Copy link

hi guys, is there a plan to release this change?

@rhcarvalho
Copy link
Contributor

hi guys, is there a plan to release this change?

Yes, we're planning a release next week.

mcdurdin added a commit to keymanapp/keyman that referenced this pull request Jul 5, 2022
The back story:

Currently Keyman for Android reports errors sent to the console via
`console.error()` into Sentry but sentry-manager itself does not. This
means that Keyman for iPhone and iPad and other users of sentry-manager
do not report these errors. Many of these errors are important.

What's worse is that Keyman for Android's error reporting here (via the
`sendKMWError()` function in Keyman Engine for Android) does not capture
stack traces, and so many of the errors we get do not have enough
information to resolve them.

Furthermore, by having `sendKMWError()` in Keyman for Android, we
capture exceptions and other program errors twice -- once on the web
side, and once on the Java side -- this adds noise to our error
reporting. Sentry also tends to lump many unrelated `sendKMWError()`
events together, so tracking resolution to the errors is painful.

The fix:

This adds a patch to sentry-manager to capture `console.error()` and
`console.warning()` events and report them through Sentry's normal error
reporting, and disables the `sendKMWError()` report (although we leave
the breadcrumb in place for when there are later, related Java errors).
There is a Sentry integration called CaptureConsole, but it does not
support capturing stack traces until v6.14
(getsentry/sentry-javascript#4034). Updating
Sentry to 6.14 or newer is a bigger job (due to ES6 baseline req. etc.)

Note that Keyman for iOS currently has some other stubs in place
overriding the `console.*` functions. These should be removed for
release builds, so that we can use this pattern instead. I will try and
tackle this in a follow-up PR (I will build it on my mac so I can test
it).

A sample error report captured with this mechanism (no sourcemaps here
because this is a -local build):

https://sentry.io/organizations/keyman/issues/3401287467/events/c40fd2cebb7743cc8dfe72e0dd34bf65/?project=5983524

I am proposing we back-port this to 15.0-stable as we are missing a lot
of data in many of our error reports on Android.
mcdurdin added a commit to keymanapp/keyman that referenced this pull request Jul 6, 2022
The back story:

Currently Keyman for Android reports errors sent to the console via
`console.error()` into Sentry but sentry-manager itself does not. This
means that Keyman for iPhone and iPad and other users of sentry-manager
do not report these errors. Many of these errors are important.

What's worse is that Keyman for Android's error reporting here (via the
`sendKMWError()` function in Keyman Engine for Android) does not capture
stack traces, and so many of the errors we get do not have enough
information to resolve them.

Furthermore, by having `sendKMWError()` in Keyman for Android, we
capture exceptions and other program errors twice -- once on the web
side, and once on the Java side -- this adds noise to our error
reporting. Sentry also tends to lump many unrelated `sendKMWError()`
events together, so tracking resolution to the errors is painful.

The fix:

This adds a patch to sentry-manager to capture `console.error()` and
`console.warning()` events and report them through Sentry's normal error
reporting, and disables the `sendKMWError()` report (although we leave
the breadcrumb in place for when there are later, related Java errors).
There is a Sentry integration called CaptureConsole, but it does not
support capturing stack traces until v6.14
(getsentry/sentry-javascript#4034). Updating
Sentry to 6.14 or newer is a bigger job (due to ES6 baseline req. etc.)

Note that Keyman for iOS currently has some other stubs in place
overriding the `console.*` functions. These should be removed for
release builds, so that we can use this pattern instead. I will try and
tackle this in a follow-up PR (I will build it on my mac so I can test
it).

A sample error report captured with this mechanism (no sourcemaps here
because this is a -local build):

https://sentry.io/organizations/keyman/issues/3401287467/events/c40fd2cebb7743cc8dfe72e0dd34bf65/?project=5983524

I am proposing we back-port this to 15.0-stable as we are missing a lot
of data in many of our error reports on Android.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Capture console.error as exception
6 participants