-
-
Notifications
You must be signed in to change notification settings - Fork 239
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
(PR created) Allow attachments to be bound to exception more easily #682
Comments
SentryOptions
that *can* touch scope
(and thus touch attachments)
Hi @marandaneto @ueman could you please suggest whether this is acceptable? If so I will make a PR. This is a blocking issue on our app... |
If I'm not mistaken you can already do something like this: Sentry.captureException(exception: ex, withScope:(scope) {
scope.addAttachment(attachment);
}); I'm not sure if that already works, but you might try that. If not @marandaneto probably appreciates a PR which enable scoped attachments. I'm not a maintainer of this SDK anymore. Currently is also Christmas season, so most people are probably out of office. |
@ueman No I cannot do that...Notice that I
Ah I did not realized that (I have been doing my project for 2 years without using holidays ;) ). Sorry for disturbing. |
Oh I see. In that case the solution would probably be similar to .NETs |
@ueman Well that is a bit the inverse. In my case I want to bind attachment in inner function and capture exception in outer. With the proposed modification, that can be implemented trivially. |
Yeah, with mine, too. The code would be something like this: void main_function() {
Sentry.withScope((scope) {
// within this scope, the attachment is added to the capture exception
try {
inner_function(); // indeed, functions calling functions calling functions... so the calling stack is deep
} catch (e,s) {
Sentry.captureException(e, s);
}
}
// here the attachment isn't added to the exception anymore
Sentry.captureException(ex); // this exception has no attachment
}
void inner_function() {
var my_data = ...;
try {
do_some_work_that_can_throw_exception(my_data);
} catch (e,s) {
Sentry.addAttachment(my_data);
rethrow;
}
} |
Agree. Since that is a bit complex (read: can introduce bugs), I will firstly implement a simpler solution |
PR made: #683 |
I'm on vacay, maybe @bruno-garcia can help |
@marandaneto No problem, I can wait for it |
I'll discuss that internally and get back to you, but I agree with @ueman , the solution could be using local scopes, it'd be confusing to have a |
@marandaneto Sure. I have used it in my app in production and my implementation seems quite good. |
You could solve this today by throwing a new exception that holds the reference to your attachment and the inner exception. pseudocode:
|
@bruno-garcia Sounds interesting, thanks |
Hi, is there any updates? |
Yes, but we're going to experiment on sentry-java first, which is using You could e.g. |
Thanks for the update! As long as the goal mentioned in the first post of the issue is solved it, any method is great |
@marandaneto Hi is there any updates? |
Btw this has a big drawback: the exception type is changed. e.g. if outer function only knows to catch MyException, it will not look at AttachmentException at all. |
@fzyzcjy yes, we are experimenting with a new API for |
Looking forward to it! |
@marandaneto Hi is there any updates? Thanks |
Yeah the approach taken on sentry-java worked well, now it's a matter of doing it on Dart/Flutter, not planning on this Quarter tho. |
#1136 is going to unblock this via |
It's now possible via hints. |
Why I need this (very much!)
My code is like:
Notice the
Sentry.pleaseBindAttachmentToException
, where I want to bind attachment to exception.However, as we know, we cannot do it. I can create some code to bind
extra
to exception, becauseextra
can be modified in EventProcessors (so I can manually create a static map holding some extras and bind to exception in my own EventProcessor). However, EventProcessors cannot modify or add attachments. So I have no way to do it :(Proposed solution
Say, add a field to
SentryOptions
, e.g.void Function(Scope)? withScopeWhenCapture
. Then, inHub.captureException
and similar places, call that callback. This is very simple and I will implement it if you like.related: #646
Hi @marandaneto could you please have a look (since this thread is strongly related to #646)? Thanks! And @ueman could you please also have a look? Thanks!
The text was updated successfully, but these errors were encountered: