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
[2.0] new_scope
does not apply scope to unhandled exception
#2857
Comments
Hmm if I look at this the other way around. I just confirmed it works the same way in Java SDK with What are our options here?
Would this now apply both tags? When using isolation scope, tags should apply, as long as the exception is handled at some point during request handling. |
I can confirm that this is currently also the behaviour in the JS SDK (which is where we were notified about it in the first place, see getsentry/sentry-javascript#11133). Leaving aside that the behaviour can be argued in both ways (intended vs bug), I'd like to mention a solution proposed by @jeengbe: The To be clear: I think we have to continue popping/restoring the scope in the My 2 cents on @adinauer's questions:
I agree,
I think this goes into the direction of the solution outlined above for languages that can't just mess with the error object. Also the sub question about nested
Yes, I think in this scenario both tags would make sense from a user perspective. Reasoning: The exception was thrown within the scope of |
For unhandled errors this is expected. There is not much that can be done about that as the unhandled error is handled on a much higher scope. I would close this as non actionable. The solution going forward will be to manipulate the isolate scope. |
Unfortunately, setting values on the isolation scope won't solve the reported issue in a satisfying way. If users set data on the isolation scope within a closure that also throws an error, it will outlive the that closure and be applied to all future events within the lifetime of the isolation scope, not just to the error they're throwing. This means, they need to manually unset that data after they deem it no longer necessary (which could be in a lot of places potentially). Let's say I have something like this: Sentry.setTag('global', tag);
function getUsers() {
// assume there is an isolation scope set by the SDK
Sentry.getIsolationScope().setTag('local', 'tag');
throw new Error('This err has two 2 tags now ✅ ')
}
getUsers();
// this is intended behaviour for the isolation scope, no complaints here
// but it shows why mutating the isolation scope is not helpful for the
// described use case
throw new Error('This err now has 2 tags ⚠️'); In the reported issue in JS, we're not talking about setting a tag but setting a custom fingerprint which really shouldn't be applied to more events than intended by users 😅 To be clear: I'm fine if we all agree that the status quo is intended behaviour and cases where users want a different behaviour should live in user code. I just want to make sure we're aware that the current behaviour is potentially confusing (in fact I'm really surprised this didn't come up before) for users who work a lot with scopes. Mental train of thought: I specifically assigned x value to this scope and the error happened within the scope. Why is x not in my error event?. Do I really need to additionally call |
I think this is a key point. In TS, for instance, there is no practical equivalent to an option type (there are ways, but not very practical ones), so it is most common to throw exceptions instead of using option types and exiting early for unhappy paths. An option type provides no information about the error/why no value is returned, so it is natural that logging is done within the scope.
So in contexts where thrown error objects are commonly used to short-circuit any execution processes, you face the dilemma of either:
The solution to this would be to attach the scope to errors, and (opt-in?) consider that when processing the error at the root. By root, I mean e.g. http middlewares. |
Sure, but that's what it means. The error bubbles to the boundary (the edge of the isolation scope). The alternative would be to add a way to capture exceptions in a block. import sentry_sdk
sentry_sdk.init("<dsn>")
with sentry_sdk.new_scope(error_boundary=True) as scope:
scope.set_tag("custom tag 1", "value 1")
1 / 0 Where if |
TODO: We should also check whether
push_scope
in 1.x is affected!How do you use Sentry?
Sentry Saas (sentry.io)
Version
2.0.0rc2
Steps to Reproduce
Run the following script:
Expected Result
The zero division error gets sent to Sentry, and the error event has the tag "custom tag 1" with the value "value 1" set.
Actual Result
Although the zero division error gets reported to Sentry, the error event is missing the tag. This is because the
new_scope
method restores the original scope within afinally
block, which gets called before the scopes are merged and before the event is sent to Sentry. So, the scope that had the tag set is no longer active when the event is prepared for sending.The text was updated successfully, but these errors were encountered: