-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Sentry Node: do not exit process if the app added its own 'uncaughtException' or 'unhandledRejection' listener #5176
Conversation
…ception' or 'unhandledRejection' listener - Fixes getsentry#1661
b8308de
to
27b77a4
Compare
Hi, I took the liberty of rebasing this PR and cleaning it up a bit. Thanks for your contribution! We'll make sure to mention you in the changelog. I fixed a small bug where domains would interfere with the listener count. Additionally, we decided it would be best to put this behaviour behind an option. We can reevaluate at a later point in time (ie, when we do a major bump) if we want to alter the default behaviour. Currently this seems to risky because people might depend on this behaviour in their applications. The This decision might be a bit unsatisfying at the moment. And trust me, I agree with you that the SDK should never alter behaviour like this - bugs me a lot. For the moment however, we need to consider downstream users that already depend on this behaviour. I'll make sure to revisit this when we have another major bump. |
Thanks for your feedback. Regarding "users may already depend on current behavior" I fail to understand it. For me it's the opposite: our app relies on Node's behavior (if you set an "uncaughtException" listener, Node guarantees that it won't exit the process when an uncaught exception happens). Then we integrated Sentry and such a behavior changed dramatically. IMHO it makes more sense that users rely on Node's official documentation than in a wrong behavior of a 3rd party library (do not take me wrong). |
Yeah I see your point. However, changing the default might break current users, which is a valid concern for us. As I said - we might revisit the default behaviour for the next major version. |
@AbhiPrasad can I get another pair of 👀 on this since I added a bunch of logic? |
Did a little bit more thinking on this change in general. I will close this PR. Currently it doesn't add any particular value to have an option for this behaviour. Users can just provide their own handler in the |
@lforst, can you please provide an example of how to do this:
This part of the documentation specifically states that:
Hence, there is no way, from what I can see, for me to resolve my issue which relates to #1661. |
@dzlandis We will currently not reopen this PR since changing the default behaviour is a breaking change and we're not planning on doing a major update right now. Additionally, providing options to mimic node's native behaviour is also not really adding much since users have already all the tools they need to mimic the behaviour themselves via the
import * as Sentry from "@sentry/node";
Sentry.init({
// Other options ...
integrations: (defaultIntegrations) => {
return defaultIntegrations.map((integration) => {
if (integration.name === "OnUncaughtException") {
return new Sentry.Integrations.OnUncaughtException({
onFatalError: (error, errorPotentiallyThrownInOnFatalError) => {
// Do whatever you like here. Quit the app, keep it alive, log the Error...
// If this option is provided, the SDK will not quit the application.
// Keep in mind however, that if you want all the error events that have built up to be sent to Sentry,
// you need to await:
// await Sentry.getCurrentHub().getClient()?.close()
},
});
} else if (integration.name === "OnUnhandledRejection") {
return new Sentry.Integrations.OnUnhandledRejection({ mode: "none" }); // chose between "none", "warn" and "strict"
} else {
return integration;
}
});
},
}); |
@lforst The sample you provide does not work on Sentry 7.13.3 – I appreciate that you don't want to make a breaking change here 👍 I wish that same standard was applied to #5627 which was a breaking change and caused production issues for a ton of people, including myself. |
@i-tu I think you're right. Thanks for letting me know. I also updated my comment. As for the breaking change: I see that this issue and #5627 are somewhat similar. With #5627 we didn't immediately see the impact it would have (everybody makes mistakes) but we decided not to roll back. Here it is quite clear to us and we make the conscious decision to go through with it until we do a major bump. Hope that sounds reasonable - thank you for the feedback! :) |
Before submitting a pull request, please take a look at our
Contributing guidelines and verify:
yarn lint
) & (yarn test
).Ref: https://getsentry.atlassian.net/browse/WEB-939