GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — fix(core): Sample errors after `beforeSend` while preserving session updates by s1gr1d · Pull Request #22671 · getsentry/sentry-javascript Conversation
|
size-limit report 📦
|
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
The sampling fix is correct. For beforeSend, we shouldn't increase error counts for filtered events (see comment).
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
| // Mechanism is passed via hint so it's available even when the event | ||
| // is dropped before event processors run (e.g. sampleRate sampling). | ||
| // We also add it via an event processor above. | ||
| captureException(ex, { |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
q: given the change in client.ts where we also merge the hint's mechanism: do we need this?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Yes, we need it here for when _prepareEvent is skipped.
eventFromException defaults every exception to handled: true, and e.g. handled: false (from the global error handler) is only merged onto the event inside _prepareEvent, which is skipped on the sampleRate drop path -> removing this also breaks this test "marks session as unhandled when unhandled error is sampled out by sampleRate"
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
ah thanks for explaining, makes sense!
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| // Reflects crashes inside release health sessions, regardless of beforeSend dropping the event. | ||
| const session = currentScope.getSession() || isolationScope.getSession(); | ||
| if (isError && session) { | ||
| this._updateSessionFromEvent(session, preparedEvent); | ||
| } |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
h: events dropped via beforeSend should not update a session. See Sessions spec and the internal slack convo we had about this topic a few weeks ago (will send you the link).
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
| const client = new TestClient(options); | ||
| setCurrentClient(client); | ||
| describe('edge case: sampled-out error that beforeSend would have filtered', () => { | ||
| test('updates session even though beforeSend would have dropped the error', () => { |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
tests the edge-case that was mentioned in a Slack convo (Sampled out + would have been filtered by beforeSend)
Sorry, something went wrong.
There was an error while loading. Please reload this page.
beforeSend returns nullsampleRate drops error event
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
thanks for making the changes!
Sorry, something went wrong.
There was an error while loading. Please reload this page.
sampleRate drops error eventbeforeSend while preserving session updates
| `Discarding event because it's not included in the random sample (sampling rate = ${sampleRate})`, | ||
| ); | ||
| } |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Bug: Sentry.lastEventId() is now set for events that are dropped by sampleRate, breaking user feedback integrations like showReportDialog() which rely on a sent event.
Severity: MEDIUM
Move the setLastEventId call to after the sampleRate check within the _prepareEvent function. This ensures Sentry.lastEventId() is only set for events that are actually sent, restoring the expected behavior for features that rely on it.
Review the code at the location below. A potential bug has been identified by an AI
agent. Verify if this is a real issue. If it is, propose a fix; if not, explain why it's
not valid.
Location: packages/core/src/client.ts#L1483-L1485
Potential issue: The `setLastEventId` call in `_prepareEvent` now executes before the
`sampleRate` check. Consequently, `Sentry.lastEventId()` stores the ID for all error
events, including those that are subsequently dropped due to sampling and never sent to
Sentry. This behavior breaks integrations like `showReportDialog()`, which depend on
`lastEventId()` to reference an event that was successfully transmitted in order to
associate user feedback with it.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
this is a known limitation. I made it more obvious: b653230
Sorry, something went wrong.
There was an error while loading. Please reload this page.
fc24c42 to
f711e80
Compare
| throw _makeDoNotSendEventError( | ||
| `Discarding event because it's not included in the random sample (sampling rate = ${sampleRate})`, | ||
| ); | ||
| } |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Bug: The sampleRate check is now performed after event processing, causing unnecessary work for events that are ultimately sampled out and discarded.
Severity: MEDIUM
This change was intentional to support session tracking. A potential improvement could be a two-phase processing system: handle session-relevant data, make the sampling decision, and only then execute the full, expensive processing pipeline for events that will be sent, if the spec allows.
Review the code at the location below. A potential bug has been identified by an AI
agent. Verify if this is a real issue. If it is, propose a fix; if not, explain why it's
not valid.
Location: packages/core/src/client.ts#L1487-L1490
Potential issue: The order of operations for event capturing has been changed to `event
processors → beforeSend → session update → sampleRate → send`. This means that for any
event that is ultimately dropped due to sampling, the SDK still performs all the
processing work upfront. This includes merging scope data, running integrations,
executing potentially expensive user-defined `event processors` and `beforeSend`
callbacks, and data normalization. This introduces a performance regression,
particularly impactful for applications with low `sampleRate` values, where the majority
of events are processed only to be discarded.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
…slot (#25751) Since #22671 sampled-out errors run the whole event pipeline while holding a client buffer slot, so error bursts on Node fill it up and real errors get dropped as queue_overflow, fixed by dropping sampled-out errors right away when there is no ok session for them to update. I added tests showing sampled-out errors no longer overflow the buffer without a session and still go through the pipeline when one exists.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
sampleRate for error events silently prevents crash-free session marking
There was an error while loading. Please reload this page.