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
How to log exceptions (captureException
) to console too
#1600
Comments
we wrapped function captureException(...args) {
if (typeof Sentry !== 'undefined') {
Sentry.captureException(...args);
}
else {
console.error(...args);
}
} |
I would say the best approach would the use Sentry.init({
dsn: "DSN",
beforeSend: event => {
if (IS_DEBUG) {
console.error(event);
return null; // this drops the event and nothing will be send to sentry
}
return event;
}
}); |
What I don't like about using |
@gaastonsr you do as the second argument :) https://docs.sentry.io/learn/filtering/?platform=browser#before-send Sentry.init({
dsn: "DSN",
beforeSend: (event, hint) => {
if (IS_DEBUG) {
console.error(hint.originalException || hint.syntheticException);
return null; // this drops the event and nothing will be sent to sentry
}
return event;
}
}); |
Omg, this changes everything! thanks, @kamilogorek. |
It took me 30 minutes to find why my console wasn't logging errors. This should be easier to do. |
The problem here is that if we'd log it by default, we'd also capture it as a breadcrumb by default. And we already do this for capture errors. Thus it'd create duplicate entries. |
It's really unexpected behavior that sentry catches errors and does not show them in console! I think you can filter out error from breadcrumb on server side. Sentry.init({
dsn: 'DSN',
beforeSend: (event, hint) => {
setTimeout(() => console.error(hint.originalException || hint.syntheticException), 0);
return event;
}
}); |
@vitalets it has been changed in |
@kamilogorek Sentry.init({ dsn: 'dsn' });
setTimeout(() => {throw new Error('abc')}, 3000); The console is empty. Network tab shows that error was sent to sentry. Without sentry error is shown: // Sentry.init({ dsn: 'dsn' });
setTimeout(() => {throw new Error('abc')}, 3000); |
it logs for captureException not for capture event :
|
@kamilogorek is it the default for the |
I also see no errors on console with 5.10.1. Logging would be enough if debug is set to true. |
This is what happens when you don't read specs to the very end... https://html.spec.whatwg.org/multipage/webappapis.html#the-event-handler-processing-algorithm
And then you scroll...
I'll update the code accordingly |
Nobody reads specs to the very end :) Thank you for the fix! |
If I am reading this thread correctly then the current release of sentry should show errors in the console while also sending them to the sentry dashboard. I am not experiencing this behavior. Here is how I am loading sentry into my page:
Here is my initialization call: Sentry.init({
dsn: 'https://_________.ingest.sentry.io/___________',
integrations: [new Sentry.Integrations.Vue({Vue, attachProps: true})],
}); I've added the following error producing line: window.undef.undef += 1; When I load the page and trigger the error line nothing shows up in the console, but I do see the error in the sentry dashboard. If I comment out the I expected based off my reading of this thread that I would see the error in the js console while also logging it to the sentry dashboard. Is that not correct? Do I still need to use the |
I realize now that I need to pass new Sentry.Integrations.Vue({Vue, attachProps: true, logErrors: true} Sorry, I should have read the docs more closely! |
Sorry, I know it's an old one, but I got a bit confused. Unhandled exceptions are printed correctly, but this code doesn't print the error: import * as Sentry from "@sentry/browser";
try {
throw new Error ("Catch this")
} catch (error) {
console.log ("Capturing exception. Will it be printed below?")
Sentry.captureException (error)
} The output is just:
After reading the discussion above I would expect the error to be printed in the console too. The error including the breadcrumb is in the Sentry app. I guess an easy workaround is to call |
|
Old issue here, but seems related. Since Sentry captures unhandled errors and also passes them to console.error, is there a simple route to avoid duplicates when also sending console.error (via CaptureConsole)? It seems the behavior (years ago) would have avoided this, but now that they are passed I'm curious if there is some config or hook I'm overlooking to negate that? :) |
@Codelica in @sentry/node? For exceptions, you can override |
@kamilogorek thanks for the info :) , but sorry to have mislead. :( I was hoping there'd be some crossover between Sentry's JS/Node options and those for React Native (which I'm using). Doesn't appear to have |
No worries. I can try to help if you explain your setup and which SDK is that exactly. Because I think i understood you want to achieve. |
Well we're using Expo / React Native so technically we include "sentry-expo" which is basically a wrapper around a couple Sentry SDK -- both |
How can you manage to log to both Sentry and console with the If I do this:
...it will create duplicate entries at Sentry's side 🤔 |
Hey @kamilogorek what about Also, seems like this PR #2475 moved it to tracing? how are the two related? |
When I'm developing locally I disable sending errors to Sentry but I still want those errors to show in my console so I can fix them.
Is there a way to disable sending exceptions/events to Sentry but still log them to the console?
The text was updated successfully, but these errors were encountered: