GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix(core): Sample errors after `beforeSend` while preserving session updates by s1gr1d · Pull Request #22671 · getsentry/sentry-javascript

Conversation

@s1gr1d

@s1gr1d s1gr1d commented Jul 27, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

When sampleRate causes an error event to be dropped, the _processEvent method returned early before reaching _updateSessionFromEvent, so the session is never marked crashed/errored. This increased crash-free session rates.

This PR moves error event sampling after event processors and beforeSend, while keeping the session update before the sampling decision.

The updated pipeline is:
_prepareEvent (event processors) → beforeSend → session update → sampleRate → send

Before it was:
sampleRate → _prepareEvent (event processors) → beforeSend → session update → send

This follows the session update filtering spec.

Closes #22615

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
s1gr1d added 2 commits July 27, 2026 12:03
@s1gr1d
fix(core): Update session status before event is dropped or `beforeSe…
342bd89
…nd` returns `null`
@s1gr1d
fix(core): Update session status before event is dropped or `beforeSe…
b002e45
…nd` returns `null`
@s1gr1d
s1gr1d requested a review from a team as a code owner July 27, 2026 10:29
@s1gr1d
s1gr1d requested review from Lms24, logaretm and msonnb and removed request for a team, logaretm and msonnb July 27, 2026 10:29
@s1gr1d
s1gr1d force-pushed the sig/fix-session-error-rate branch from e0abd98 to b002e45 Compare July 27, 2026 10:40
@github-actions

github-actions Bot commented Jul 27, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

size-limit report 📦

Path Size % Change Change
@sentry/browser 29.82 kB -0.02% -4 B 🔽
@sentry/browser - with treeshaking flags 28.02 kB -0.03% -7 B 🔽
@sentry/browser (incl. Tracing) 47.1 kB -0.02% -6 B 🔽
@sentry/browser (incl. Tracing + Span Streaming) 47.1 kB -0.02% -5 B 🔽
@sentry/browser (incl. Tracing, Profiling) 51.81 kB -0.02% -6 B 🔽
@sentry/browser (incl. Tracing, Replay) 86.4 kB -0.02% -13 B 🔽
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 75.84 kB -0.01% -7 B 🔽
@sentry/browser (incl. Tracing, Replay with Canvas) 91.13 kB -0.02% -11 B 🔽
@sentry/browser (incl. Tracing, Replay, Feedback) 103.76 kB -0.02% -13 B 🔽
@sentry/browser (incl. Feedback) 47.13 kB -0.01% -4 B 🔽
@sentry/browser (incl. sendFeedback) 34.66 kB -0.02% -5 B 🔽
@sentry/browser (incl. FeedbackAsync) 39.76 kB -0.01% -2 B 🔽
@sentry/browser (incl. Metrics) 30.89 kB -0.01% -3 B 🔽
@sentry/browser (incl. Logs) 31.12 kB -0.02% -4 B 🔽
@sentry/browser (incl. Metrics & Logs) 31.8 kB -0.02% -5 B 🔽
@sentry/react 31.61 kB -0.02% -6 B 🔽
@sentry/react (incl. Tracing) 49.33 kB -0.02% -7 B 🔽
@sentry/vue 34.74 kB -0.03% -8 B 🔽
@sentry/vue (incl. Tracing) 49.05 kB -0.03% -10 B 🔽
@sentry/svelte 29.85 kB -0.02% -5 B 🔽
CDN Bundle 31.86 kB -0.04% -11 B 🔽
CDN Bundle (incl. Tracing) 47.45 kB +0.01% +1 B 🔺
CDN Bundle (incl. Logs, Metrics) 33.41 kB -0.03% -9 B 🔽
CDN Bundle (incl. Tracing, Logs, Metrics) 48.82 kB -0.01% -3 B 🔽
CDN Bundle (incl. Replay, Logs, Metrics) 72.78 kB -0.02% -8 B 🔽
CDN Bundle (incl. Tracing, Replay) 85.09 kB -0.01% -5 B 🔽
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) 86.38 kB -0.01% -3 B 🔽
CDN Bundle (incl. Tracing, Replay, Feedback) 90.85 kB -0.01% -4 B 🔽
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) 92.16 kB -0.01% -2 B 🔽
CDN Bundle - uncompressed 95.06 kB -0.02% -11 B 🔽
CDN Bundle (incl. Tracing) - uncompressed 142.28 kB -0.01% -11 B 🔽
CDN Bundle (incl. Logs, Metrics) - uncompressed 99.78 kB -0.02% -11 B 🔽
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed 146.26 kB -0.01% -11 B 🔽
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed 224.53 kB -0.01% -11 B 🔽
CDN Bundle (incl. Tracing, Replay) - uncompressed 261.54 kB -0.01% -11 B 🔽
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed 265.5 kB -0.01% -11 B 🔽
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 275.24 kB -0.01% -11 B 🔽
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed 279.2 kB -0.01% -11 B 🔽
@sentry/nextjs (client) 51.92 kB -0.02% -8 B 🔽
@sentry/sveltekit (client) 47.51 kB -0.03% -11 B 🔽
@sentry/core/server 79.59 kB +0.01% +3 B 🔺
@sentry/core/browser 51.6 kB +0.01% +4 B 🔺
@sentry/node 121.68 kB -0.01% -9 B 🔽
@sentry/node/import (ESM hook with diagnostics-channel injection) 166 B - -
@sentry/node - without tracing 85.26 kB -0.02% -9 B 🔽
@sentry/aws-serverless 93.48 kB -0.01% -9 B 🔽
@sentry/cloudflare (withSentry) - minified 197.59 kB -0.01% -9 B 🔽
@sentry/cloudflare (withSentry) 485.72 kB -0.01% -30 B 🔽

View base workflow run

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Lms24
Lms24 reviewed Jul 27, 2026
View reviewed changes

@Lms24 Lms24 left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for 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.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread dev-packages/browser-integration-tests/suites/sessions/sampled-session-update/test.ts Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread packages/browser/src/helpers.ts Outdated
// 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, {

@Lms24 Lms24 Jul 27, 2026

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for 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.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@s1gr1d s1gr1d Jul 27, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member Author

There was a problem hiding this comment.

Choose a reason for 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.

Uh oh!

There was an error while loading. Please reload this page.

Lms24 reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

@Lms24 Lms24 Jul 28, 2026

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for 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.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread packages/core/src/client.ts Outdated
Comment on lines +1497 to +1501
// 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);
}

@Lms24 Lms24 Jul 27, 2026

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for 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.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@s1gr1d
events dropped via beforeSend do not update a session
db044d0
sentry[bot]
sentry Bot reviewed Jul 27, 2026
View reviewed changes
Comment thread packages/core/src/client.ts Resolved

Uh oh!

There was an error while loading. Please reload this page.

s1gr1d
s1gr1d commented Jul 27, 2026
View reviewed changes
Comment thread packages/core/test/lib/client.test.ts Outdated
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', () => {

@s1gr1d s1gr1d Jul 27, 2026

Copy link
Copy Markdown
Member Author

There was a problem hiding this comment.

Choose a reason for 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.

Uh oh!

There was an error while loading. Please reload this page.

Lms24 reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
@s1gr1d
remove unused variable
a7cb866
@s1gr1d s1gr1d mentioned this pull request Jul 27, 2026
sampleRate for error events silently prevents crash-free session marking #22615
Closed
3 tasks done
@s1gr1d s1gr1d changed the title fix(core): Update session status before event is dropped or beforeSend returns null fix(core): Update session status before sampleRate drops error event Jul 27, 2026
@s1gr1d
s1gr1d requested a review from Lms24 July 27, 2026 12:24
Lms24
Lms24 approved these changes Jul 28, 2026
View reviewed changes

@Lms24 Lms24 left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for 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.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@s1gr1d s1gr1d changed the title fix(core): Update session status before sampleRate drops error event fix(core): Sample errors after beforeSend while preserving session updates Jul 28, 2026
sentry[bot]
sentry Bot reviewed Jul 28, 2026
View reviewed changes
Comment thread packages/core/src/client.ts
Comment on lines +1483 to +1485
`Discarding event because it's not included in the random sample (sampling rate = ${sampleRate})`,
);
}

@sentry sentry Bot Jul 28, 2026

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for 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

Suggested Fix

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.

Prompt for AI Agent
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.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@s1gr1d s1gr1d Jul 29, 2026

Copy link
Copy Markdown
Member Author

There was a problem hiding this comment.

Choose a reason for 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.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@s1gr1d
fix(core): Sample error events after beforeSend
f711e80
@s1gr1d
s1gr1d force-pushed the sig/fix-session-error-rate branch from fc24c42 to f711e80 Compare July 28, 2026 12:53
s1gr1d added 2 commits July 29, 2026 13:26
@s1gr1d
fix integration test
ae2228e
@s1gr1d
Merge branch 'develop' into sig/fix-session-error-rate
6cc6285
Lms24
Lms24 approved these changes Jul 29, 2026
View reviewed changes
@s1gr1d
add test
b653230
@s1gr1d
s1gr1d enabled auto-merge (squash) July 29, 2026 11:46
sentry[bot]
sentry Bot reviewed Jul 29, 2026
View reviewed changes
Comment thread packages/core/src/client.ts
Comment on lines +1487 to +1490
throw _makeDoNotSendEventError(
`Discarding event because it's not included in the random sample (sampling rate = ${sampleRate})`,
);
}

@sentry sentry Bot Jul 29, 2026

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for 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

Suggested Fix

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.

Prompt for AI Agent
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.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@s1gr1d
s1gr1d merged commit f6e91d8 into develop Jul 29, 2026
271 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@s1gr1d
s1gr1d deleted the sig/fix-session-error-rate branch July 29, 2026 12:02
@s1gr1d s1gr1d mentioned this pull request Jul 29, 2026
fix(v10/core): Sample errors after beforeSend while preserving session updates #22819
Merged
s1gr1d added a commit that referenced this pull request Jul 29, 2026
@s1gr1d
fix(v10/core): Sample errors after beforeSend while preserving sess…
045d07e
…ion updates (#22819)

backport of #22671

Closes #22615
@sentry-release-bot sentry-release-bot Bot mentioned this pull request Sep 16, 2026
publish: getsentry/[email protected] getsentry/publish#9545
Closed
47 tasks
@4ktLuffy 4ktLuffy mentioned this pull request Oct 21, 2026
Request sessions count errors dropped by ignoreErrors or beforeSend #25605
Open
3 tasks done
@s1gr1d s1gr1d mentioned this pull request Oct 21, 2026
fix(core): Do not count dropped errors in request sessions #25632
Closed
@logaretm logaretm mentioned this pull request Oct 27, 2026
fix(core): Drop sampled-out errors before they take a promise buffer slot #25751
Merged
logaretm added a commit that referenced this pull request Oct 27, 2026
@logaretm
fix(core): Drop sampled-out errors before they take a promise buffer …
fea30a2
…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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@sentry sentry[bot] sentry[bot] left review comments
@Lms24 Lms24 Lms24 approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

sampleRate for error events silently prevents crash-free session marking

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@s1gr1d @Lms24
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.