fix(nextjs): Return correct lastEventId for SSR pages#19240
fix(nextjs): Return correct lastEventId for SSR pages#19240
Conversation
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 2 potential issues.
Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.
dev-packages/e2e-tests/test-applications/nextjs-pages-dir/tests/error-page-lasteventid.test.ts
Outdated
Show resolved
Hide resolved
| // return the existing event ID instead of capturing it again (needed for lastEventId() to work) | ||
| if (err && checkOrSetAlreadyCaught(err)) { | ||
| waitUntil(flushSafelyWithTimeout()); | ||
| return getIsolationScope().lastEventId(); |
There was a problem hiding this comment.
I feel like this has a high chance of not being the event id we are looking for... we really should think about storing lastEventId with more info of what the actual event was that this belongs to.
I don't really think there's much we can do here, just wanted to mention this tho and this is probably better than straight up return an event id of an event that gets deduped.
There was a problem hiding this comment.
I think this can work but doesn't feel bullet proof to me.
Could we perhaps associate error objects with their event IDs? Like add a __sentry_evt_id__ to each error instance so that we can refer to that purely from the error object regardless of where we catch it?
There was a problem hiding this comment.
@logaretm that sounds also like a nice approach. But do you mean that independently from lastEventId()? Because I am not sure how those two things would connect. lastEventId() is still separate from an error.
There was a problem hiding this comment.
What I was thinking here is "how do we know for sure that the very last event is the same one that caught the same error?" I can't say I'm familiar with how this all works yet, so I was wondering if this is an edge case to consider, is it possible for events to slip in between? are they guaranteed to be sequential?
What I was suggesting is if the error was caught, we stick an event ID on it if possible, that way if it comes up again then we can use the last event assigned to that error instance. Does that track or is it maybe naive?
|
|
||
| // If the error was already captured (e.g., by wrapped functions in data fetchers), | ||
| // return the existing event ID instead of capturing it again (needed for lastEventId() to work) | ||
| if (err && checkOrSetAlreadyCaught(err)) { |
There was a problem hiding this comment.
This modifies the error object already before sending it, which we do not want bc this prevents it from capturing it?
There was a problem hiding this comment.
probably worth exposing isAlreadyCaptured from core since we want this to be read only.
Codecov Results 📊Generated by Codecov Action |
node-overhead report 🧳Note: This is a synthetic benchmark with a minimal express app and does not necessarily reflect the real-world performance impact in an application.
|
When using
captureUnderscoreErrorExceptionon an_errorpage, the events were mostly dropped because it already existed from a Sentry-wrapped data fetcher (likegetServerProps). This resulted in not sending the error to Sentry but still generating a new event ID which was used aslastEventId(and thus was wrong).Closes #19217
Also, check out this specific comment within the issue as it gives more context: #19217 (comment)