-
-
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
Instrument incorrectly wrapping error causing sentry functions to fail #5724
Comments
Hi, @Sammaye. Would you be able to provide a minimal repro of this issue (including all the parts needed to run the app)? It would help us a lot with debugging, since not everyone on the team is an angular expert. (At a quick glance, nothing in what you've done jumps out at me as obviously wrong.) Thanks! |
I'll try, though very busy |
Ok I have produced one and I was wrong, it does call my error handler, but it still says in Sentry that the instrument was the mechanism and it still will not attach the user to the error but will in the modal, code will follow |
Here is the code. Basically you will see in the global error handler I put a line like console.log('in error handler'); and this proves that it actually calls my global error handler and even calls the capture, but this is the result https://sentry.io/organizations/delenta/issues/3586573703/?query=is%3Aunresolved |
Something else I have noticed there as well the stack trace is messed up, take this error from my live app https://sentry.io/organizations/delenta/issues/3586583907/?query=is%3Aunresolved where it easily shows what module it crashed in and, if I upload my source maps, would instantly tell me the line it crashed on |
As a note: I did make the test in angular 14 and not 10, which while proves it isn't my angular version also mean the stack trace difference is likely from version but still quite valid since if I upgrade I might lose useful stack traces if that's true |
Ok further update, I thought I would test the scenario that does assign user for me in the new app and it doesn't: https://sentry.io/organizations/delenta/issues/3586723234/events/3eb54a8fbc26473f9e45326c22ba2212/?project=6736456&query=is%3Aunresolved and here is a screenshot of the process of using setUser, I commented out the if statement around it as well just in case |
And here is an error of the same kind form my live app, no nodejs server running, but it attaches the user correctly https://sentry.io/organizations/delenta/issues/3586740920/?query=is%3Aunresolved and the only real difference I can find it maybe angular or rxjs version, this is really quite inconsistent |
Any updates? |
Our angular expert is currently out with covid. |
Hi @Sammaye apologies for only getting back to you now. Thanks for providing a reproduction example and the links to your events! So just for me to confirm/summarize all of your observations (please feel free to correct and add whatever I forgot):
I'm still looking into what you could do to make this better. Just our of curiosity: Have you tried using Sentry's ErrorHandler that ships with the Angular SDK? If yes, does this improve the situation? I have a feeling that your problem might be related to what has been reported in #5417. Given this, my gut feeling currently is that this has something to do with scope bleed in async contexts which is a hard problem to solve (we've been working on this for a long time). Anyway, I'm still looking if there is something else we can do here, so I'll keep you posted. Let me know if you've found more clues or workarounds in the meantime :) |
Yes
Indeed
I think I tried it and it didn't, tbh my error handler is actually an extension of yours, just with a few custom little bit added on for me.
Thing is, other properties work, so if you were to make tags settable the same as other property that do work, like attachments, then this would solve it entirely Edit: Sorry I mean user, tags can be set like that |
Hi @Sammaye I think I found the problem for the missing user data: In your I think you have two options to work around this:
event.user = {
id: userId,
username: name,
email,
}; Please note the this second option does not set the user globally in the Sentry SDK, meaning that it only adds it to the event that's going through beforeSend. If you want to add user data to your transactions (as it currently works), you still have to call Sentry.setUser somewhere. In regards to incomplete stack traces: In the repro you provided, the exception I get in the console is a If I console log this error, I can see that This in turn means that a string is passed to Now, we could try to handle this I hope this helps a little (at least the user problem should be fixable). Let me know if you have further questions! |
Hmm, I didn't know there was a difference, is there any documentation related to this? One thing that would concern m,e about setting it globally is catching start up errors and stuff, so I would probably want to do it both, set it globally if it can and then set it each error as a backup for obscure errors.
This was actually comparing two dev instances: V10 V13 Re-reading my comments, I think this is since angular v13+ actually compiles my dev to 4 files, mian.js being the app itself, I guess this might be since the test app has no lazy loaded modules, maybe some change in Angular itself. I guess as long as I suddenly won't lose sight of errors by upgrading angular that's fine |
The only docs I can find on setting a user are setting them globally https://docs.sentry.io/platforms/javascript/enriching-events/identify-user/ so yeah, not sure what the difference is |
The main thing here is that Note that we definitely want to change this to give users a way of controlling sending of transaction events just like error events. We're currently evaluating how to do this best and we opened an RFC for it. In the meantime, to edit (or discard) transaction events, you could register an EventProcessor on the scope to make modifications to or manually drop transactions
I think that's a timing problem we can't do much about, if I understand you correctly, because surely, errors can occur before you even know the user data. But overall, setting user data globally and for each event shouldn't hurt. Just not sure if it improves this timing problem. |
If you set the user globally ( |
In this case no, since it happens within a page that can only be accessed by logged in users, so angular knows of the user, I am guessing you mean it is a timing issue between Sentry.setUser and dispatch of the event? |
Ahh alright.
Since your app already knows the user data, then yes, that's the only timing problem left. But I think if you call |
So the fact that it is could mean a deeper issue, ok I will try and few things a bit later and see if I can get any more insight |
I'll go ahead and close this issue since it seems like we found a solution. Feel free to comment if you still have questions. |
Yeah I just tested t, if I set it first thing in main.ts this error now works with full user info, so there is defo some kind of issue between Sentry.setUser and the beforeSend of an event, but it;s not vital, I will use globally since using it in beforeSend likely will mess up transactions as well like you said |
Is there an existing issue for this?
How do you use Sentry?
Sentry Saas (sentry.io)
Which package are you using?
@sentry/angular
SDK Version
7.12.1
Framework Version
Angular 10.2.5
Link to Sentry event
https://sentry.io/organizations/delenta/issues/3583358067/?query=is%3Aunresolved
Steps to Reproduce
Used this in my main.ts:
With a app module:
With a error handler like:
I used a function like:
Where by assignment of g would clearly raise an error.
Expected Result
Sentry would let the global error handler take this, as it works when I remove sentry
Actual Result
Sentry seems to throw this error somewhere else and avoid my global error handler altogether, I suspect the instrument.js and not only that but certain functions, while many others, do not work, like setUser(). In my main.ts everything there works but setUser when this happens, for every other error setUser works just fine.
This also worries me since I have a slightly custom error handler which checks for unrecoverable app state and does custom logic for that, I am concerned this could interfere with customer workflows if I release sentry to our live servers.
I suspect this to be a bug since it seems to break some of sentry's own functions when it happens, such as setUser(), as I said.
The text was updated successfully, but these errors were encountered: