Skip to content

fix(core): Do not count dropped errors in request sessions - #26819

Draft
s1gr1d wants to merge 8 commits into
ref/request-session-wait-for-pending-errorsfrom
fix/request-session-dropped-errors
Draft

s1gr1d wants to merge 8 commits into
ref/request-session-wait-for-pending-errorsfrom
fix/request-session-dropped-errors

Conversation

@s1gr1d

@s1gr1d s1gr1d commented Nov 24, 2026 •

Copy link
Copy Markdown
Member

Supersedes #25632

What

Errors that ignoreErrors, an event processor or beforeSend drop no longer count in request sessions. Sampled-out and deduplicated errors still count if the filters keep them.

Part 3 of 3 for #25605. Stacked on #27138 (Dedupe ignores errors that are never sent) and #27139 (request sessions wait for their errors).

Why

The client spec puts the session update after beforeSend and before sampling. Request sessions counted errors at capture time, so dropped errors lowered the crash-free rate.

  • Dedupe drops to save quota, like sampling. So a duplicate from another request still counts, after it runs the filters. If 1000 requests fail with the same error, all 1000 still count, and a beforeSend that drops health checks still works for duplicates.
  • Overflow: on the server, errors that are never sent run the filters outside of the promise buffer, with their own limit. So they never push a real error out with queue_overflow. An error that is itself dropped with queue_overflow still counts, without the filters, because they could not run.

The never-sent path is in ServerRuntimeClient only. In the browser, sampled-out errors still run the filters inside the promise buffer, as before. A burst of errors with an async beforeSend or event processor can still overflow it there. But one user rarely fills the buffer, while a server gets the errors of all its requests. Moving the browser to the side lane too would cost about +220 B gzip, so the browser keeps the current behavior.

The cost: beforeSend now also runs for errors that are not sent, once per request for a duplicate. With 1000 failing requests, it runs 1000 times instead of 3. The Python SDK does the same. More details are in this comment.

Before (develop) After (server)
flowchart TD
  CAP["captureException"] --> RS["Mark request session errored<br/>(before any filter: bug #25605)"]
  RS --> SMP{"Sampled out?"}
  SMP -- "yes, scope session cannot change" --> D1["Drop: sample_rate"]
  SMP -- "no, or scope session can change" --> P

  subgraph DB["Delivery buffer (64 slots)"]
    P["Event processors<br/>EventFilters, Dedupe, ContextLines, ..."] --> BS{"beforeSend"}
    BS -- "keeps" --> US["Update scope session"]
    US --> SMP2{"Sampled out?"}
    SMP2 -- "no" --> SEND["Send"]
  end

  P -- "a filter or Dedupe drops" --> D2["Drop: event_processor"]
  BS -- "drops" --> D3["Drop: before_send"]
  SMP2 -- "yes" --> D4["Drop: sample_rate"]

  classDef counts fill:#d4f4dd,stroke:#2e7d32
  classDef nocount fill:#eeeeee,stroke:#757575
  class RS,US counts
  class D1,D2,D3 nocount
Loading
flowchart TD
  CAP["captureException"] --> SMP{"rollSampleRate:<br/>sampled out?"}
  SMP -- "yes" --> CS{"_countSampledOutError:<br/>can a session change?"}
  CS -- "no" --> D1["Drop: sample_rate"]
  CS -- "yes" --> F2
  SMP -- "no" --> F1

  subgraph DB["Delivery buffer (64 slots): errors that can be sent"]
    F1["_applyFilters<br/>event processors (Dedupe compares), beforeSend"] --> U1["_updateSessions<br/>scope + request"]
    U1 --> SEND["sendEvent"]
  end

  F1 -- "a filter drops" --> D2["Drop: event_processor / before_send"]
  F1 -- "duplicate, same request and handled" --> D3["Drop: event_processor<br/>(as before)"]
  F1 -- "duplicate, other request or unhandled,<br/>a session can change" --> F2

  subgraph SB["_countWithoutSlot (own limit of 64)"]
    F2["_applyFilters<br/>(Dedupe ignores sampled-out errors)"] --> U2["_updateSessions"]
  end

  U2 --> D4["Drop: sample_rate / event_processor"]
  F2 -- "a filter drops" --> D2

  classDef counts fill:#d4f4dd,stroke:#2e7d32
  classDef nocount fill:#eeeeee,stroke:#757575
  class U1,U2 counts
  class D1,D2,D3 nocount
Loading

Fixes #25605

@github-actions

github-actions Bot commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

size-limit report 📦

Compared: d3d2c2d (PR test merge using develop at 2007cec)

Against: 2007cec (develop) · base run #68738

✅ Baseline matches: this diff contains only this PR's changes.

Path Size % Change Change
@sentry/browser 30.88 kB +0.52% +158 B 🔺
@sentry/browser - with treeshaking flags 29 kB +0.52% +148 B 🔺
@sentry/browser - with treeshaking flags tracing without tracing 28.88 kB +0.64% +183 B 🔺
@sentry/browser (incl. Tracing) 54.24 kB +0.32% +168 B 🔺
@sentry/browser (incl. Tracing Core) 41.07 kB +0.45% +183 B 🔺
@sentry/browser (incl. Tracing + Span Streaming) 54.24 kB +0.32% +168 B 🔺
@sentry/browser (incl. Tracing, Profiling) 57.13 kB +0.29% +162 B 🔺
@sentry/browser (incl. Tracing, Replay) 94.22 kB +0.18% +161 B 🔺
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 82.77 kB +0.23% +185 B 🔺
@sentry/browser (incl. Tracing, Replay with Canvas) 99.06 kB +0.17% +166 B 🔺
@sentry/browser (incl. Tracing, Replay, Feedback) 112.01 kB +0.15% +159 B 🔺
@sentry/browser (incl. Feedback) 48.74 kB +0.31% +149 B 🔺
@sentry/browser (incl. sendFeedback) 31.45 kB +0.51% +157 B 🔺
@sentry/browser (incl. FeedbackAsync) 36.5 kB +0.45% +160 B 🔺
@sentry/browser (incl. Metrics) 32.22 kB +0.58% +184 B 🔺
@sentry/browser (incl. Logs) 32.51 kB +0.57% +184 B 🔺
@sentry/browser (incl. Metrics & Logs) 33.18 kB +0.55% +180 B 🔺
@sentry/react 32.78 kB +0.52% +167 B 🔺
@sentry/react (incl. Tracing) 56.75 kB +0.32% +178 B 🔺
@sentry/vue 39.24 kB +0.43% +166 B 🔺
@sentry/vue (incl. Tracing) 57.32 kB +0.24% +136 B 🔺
@sentry/svelte 30.94 kB +0.55% +167 B 🔺
@sentry/effect (client) 42.46 kB +0.4% +168 B 🔺
@sentry/effect (client, incl. Tracing) 55.28 kB +0.33% +177 B 🔺
@sentry/effect (client, incl. Tracing, Logs, Metrics) 66.75 kB +0.25% +161 B 🔺
@sentry/remix (Remix 3 client bundle) 59.7 kB +0.26% +152 B 🔺
CDN Bundle 32.68 kB +0.46% +147 B 🔺
CDN Bundle (incl. Tracing) 54.33 kB +0.29% +157 B 🔺
CDN Bundle (incl. Logs, Metrics) 35.4 kB +0.43% +150 B 🔺
CDN Bundle (incl. Tracing, Logs, Metrics) 56.77 kB +0.25% +139 B 🔺
CDN Bundle (incl. Replay, Logs, Metrics) 76.35 kB +0.21% +156 B 🔺
CDN Bundle (incl. Tracing, Replay) 92.15 kB +0.18% +165 B 🔺
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) 94.63 kB +0.15% +136 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback) 97.6 kB +0.17% +158 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) 100.05 kB +0.16% +154 B 🔺
CDN Bundle - uncompressed 95.41 kB +0.5% +469 B 🔺
CDN Bundle (incl. Tracing) - uncompressed 160.76 kB +0.3% +469 B 🔺
CDN Bundle (incl. Logs, Metrics) - uncompressed 103.75 kB +0.46% +469 B 🔺
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed 168.38 kB +0.28% +469 B 🔺
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed 234.14 kB +0.21% +469 B 🔺
CDN Bundle (incl. Tracing, Replay) - uncompressed 281.19 kB +0.17% +469 B 🔺
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed 288.82 kB +0.17% +469 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 293.12 kB +0.17% +469 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed 300.74 kB +0.16% +469 B 🔺
@sentry/nextjs (client) 60.08 kB +0.26% +150 B 🔺
@sentry/sveltekit (client) 55.08 kB +0.35% +191 B 🔺
@sentry/astro (client) - rolldown, without tracing 36.04 kB +0.59% +210 B 🔺
@sentry/core/server 46.69 kB +1.6% +731 B 🔺
@sentry/core/browser 14.55 kB - -
@sentry/node 158.69 kB +0.6% +936 B 🔺
@sentry/node/import (ESM hook with diagnostics-channel injection) 83.63 kB - -
@sentry/node - without tracing 90.66 kB +1.02% +915 B 🔺
@sentry/node - without channel injection 148.07 kB +0.66% +961 B 🔺
@sentry/aws-serverless 101.62 kB +0.98% +977 B 🔺
@sentry/cloudflare (withSentry) - minified 216.49 kB +1.49% +3.17 kB 🔺
@sentry/cloudflare (withSentry) 503.32 kB +1.65% +8.14 kB 🔺
@sentry/cloudflare (withSentry, instrumented CommonJS package) - minified 219.43 kB +1.47% +3.17 kB 🔺
@sentry/nextjs/cloudflare (withSentry) - minified 244.7 kB +1.32% +3.17 kB 🔺

View base workflow run

@github-actions

Copy link
Copy Markdown
Contributor

One or more gzipped bundles increased by more than 500 bytes. If this increase is intentional, add the Accept Bundlesize Increase label to this PR to rerun and accept the check.

@github-actions

github-actions Bot commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Optional E2E tests

Some optional checks were not successful. They do not block the merge. 1 not successful, 64 successful. See the run.

Check Status
❌ CI: Optional E2E Tests / E2E node-express-mcp-v2 (MCP SDK OpenTelemetry) Test (optional) Failing after 57s Details
Successful checks
Check Status
✅ CI: Optional E2E Tests / E2E cloudflare-workers-send-to-sentry Test (optional) Successful in 4m Details
✅ CI: Optional E2E Tests / E2E node-pi-durable (latest) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E hono-5 Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E nuxt-5-sourcemaps Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E nuxt-5 (development) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E cloudflare-agent Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E hapi-21 (bun) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E hono-5 (cloudflare) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E nuxt-5-sourcemaps (no upload) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E astro-7 Test (optional) Successful in 2m Details
✅ CI: Optional E2E Tests / E2E nuxt-5 (kv-cache) Test (optional) Successful in 2m Details
✅ CI: Optional E2E Tests / E2E nuxt-5 (deno) Test (optional) Successful in 2m Details
✅ CI: Optional E2E Tests / E2E debug-id-sourcemaps Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E node-fastify-6 Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E solidstart-2-tunnel Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E cloudflare-think (ai v6) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E react-send-to-sentry Test (optional) Successful in 3m Details
✅ CI: Optional E2E Tests / E2E node-express-send-to-sentry (static trace lifecycle) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E nuxt-5 Test (optional) Successful in 3m Details
✅ CI: Optional E2E Tests / E2E cloudflare-pi-durable (latest) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E astro-7 (static trace lifecycle) Test (optional) Successful in 2m Details
✅ CI: Optional E2E Tests / E2E nuxt-5 (cloudflare) Test (optional) Successful in 2m Details
✅ CI: Optional E2E Tests / E2E nuxt-5-sourcemaps (client source maps kept) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E nuxt-5 (bun) Test (optional) Successful in 2m Details
✅ CI: Optional E2E Tests / E2E cloudflare-flue-send-to-sentry Test (optional) Successful in 3m Details
✅ CI: Optional E2E Tests / E2E hapi-21 (deno) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E node-flue (latest) Test (optional) Successful in 2m Details
✅ CI: Optional E2E Tests / E2E gen-ai-libraries (latest) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E nextjs-16 (vinext) Test (optional) Successful in 2m Details
✅ CI: Optional E2E Tests / E2E cloudflare-workers-without-tracing-send-to-sentry Test (optional) Successful in 2m Details
✅ CI: Optional E2E Tests / E2E hono-5 (bun) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E node-openai-decisions (latest) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E deno (latest) Test (optional) Successful in 2m Details
✅ CI: Optional E2E Tests / E2E tanstackstart-react-sourcemaps (delete all) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E nextjs-15 (latest) Test (optional) Successful in 3m Details
✅ CI: Optional E2E Tests / E2E react-router-7-framework-instrumentation Test (optional) Successful in 2m Details
✅ CI: Optional E2E Tests / E2E node-eve (content off) Test (optional) Successful in 4m Details
✅ CI: Optional E2E Tests / E2E tanstackstart-react-sourcemaps (manual upload) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E tanstackstart-react (latest) Test (optional) Successful in 2m Details
✅ CI: Optional E2E Tests / E2E nuxt-4-sourcemaps (Vite server) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E hono-5 (deno) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E node-eve (0.x) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E nuxt-5-sourcemaps (client source maps enabled by Sentry) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E node-eve (orchestrion) Test (optional) Successful in 4m Details
✅ CI: Optional E2E Tests / E2E solidstart-2 (delete all) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E solidstart-2 (no upload) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E node-express-mcp-v2 Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E nuxt-5-tunnel (cloudflare) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E nuxt-5-tunnel Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E solidstart-2 (manual upload) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E nextjs-16-tunnel (cloudflare) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E solidstart-2 Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E tanstackstart-react-sourcemaps (no upload) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E nuxt-5-sourcemaps (static / nuxt generate) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E tanstackstart-react-cloudflare Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E nextjs-15 (turbo) Test (optional) Successful in 2m Details
✅ CI: Optional E2E Tests / E2E tanstackstart-react-sourcemaps Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E vinext-cf-workers (workers cache) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E node-express-send-to-sentry Test (optional) Successful in 3m Details
✅ CI: Optional E2E Tests / E2E nextjs-16 (vinext, bun) Test (optional) Successful in 2m Details
✅ CI: Optional E2E Tests / E2E node-express-mcp-v1 Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E nextjs-14-supabase Test (optional) Successful in 3m Details
✅ CI: Optional E2E Tests / E2E node-mastra (latest) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E vue-3 (no Options API) Test (optional) Successful in 1m Details

@s1gr1d

This comment was marked as resolved.

cursor[bot]

This comment was marked as low quality.

Split _processEvent into steps in the order of the client spec: roll the
sample rate, run the filters (_applyFilters: event processors and the
beforeSend callbacks), update the sessions (_updateSessions), and send. A
sampled-out error goes through _countSampledOutError, which counts it in
sessions if the filters keep it.

No behavior change. The next change to which errors count in sessions can
then override these steps instead of copying them.

Refs #25605
Request sessions counted an error at capture time, before ignoreErrors, event
processors and beforeSend ran. So errors that the user chose to drop still
lowered the crash-free rate. Errors now count after beforeSend, as the client
spec requires.

Sampling and Dedupe only save quota, so an error that they drop still counts
if the filters keep it. On the server, such an error runs the filters outside
of the promise buffer, with its own limit, so it never pushes a real error
out. Dedupe ignores sampled-out errors, so a repeated error is no longer
dropped every time with a low sampleRate.

Fixes #25605
@s1gr1d
s1gr1d force-pushed the fix/request-session-dropped-errors branch from 82e3cd4 to ab88166 Compare November 24, 2026 15:29
@s1gr1d

This comment was marked as duplicate.

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Want higher recall? High effort reviews run extra passes and find more bugs. A team admin can switch effort levels in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit ab88166. Configure here.

Only ServerRuntimeClient moves never-sent errors out of the promise buffer. In the browser a
burst with async event processors can still overflow it, but one user rarely fills it, so the
browser keeps the develop behavior to save bundle size.
Say why the browser keeps sampled-out errors in the promise buffer, why only exception events
get the overflow hint, what the side lane limit trades off, why a marked duplicate rejects at
once, and why the side lane increments _numProcessing.
Base automatically changed from ref/core-error-pipeline-steps to develop December 3, 2026 08:51
s1gr1d added a commit that referenced this pull request Dec 3, 2026
## What

`_processEvent` now reads in the order of the [client spec event
pipeline](https://develop.sentry.dev/sdk/foundations/client/#event-pipeline).
Each step is a function: `_applyFilters` (event processors and
`beforeSend*`), `_updateSessions`, and `_countSampledOutError` for
errors that sampling drops. No test changed.

<table><tr><th>Before</th><th>After</th></tr><tr><td height=500
width=500>

```mermaid
flowchart TD
  P["_processEvent<br/>(one long promise chain:<br/>sampling, _prepareEvent, beforeSend,<br/>session update, sampling drop, send)"]
```

</td><td height=500 width=500>

```mermaid
flowchart TD
  S0{"rollSampleRate:<br/>sampled out?"} -- "no" --> S1["_applyFilters<br/>event processors + beforeSend*"]
  S1 --> S2["_updateSessions"]
  S2 --> S3["sendEvent"]
  S0 -- "yes" --> C["_countSampledOutError"]
  C -- "session can change" --> C1["_applyFilters"] --> C2["_updateSessions"] --> D["drop: sample_rate"]
  C -- "no session can change" --> D
```

</td></tr></table>

## Why

The next PR (#26819) changes which errors count in sessions (#25605).
With one function for each step, the server client can override a step
there, and the fix does not copy the `beforeSend` and outcome logic.

One small difference: `_updateSessions` reads the session when
processing ends, not when the error is captured. It only matters if a
new session starts while an event is processed, and it was the behavior
before #25751.

Refs #25605
…n-dropped-errors

# Conflicts:
#	packages/core/src/client.ts
#	packages/core/src/server-runtime-client.ts
#	packages/core/test/lib/server-runtime-client.test.ts
@s1gr1d

s1gr1d commented Dec 3, 2026

Copy link
Copy Markdown
Member Author

@sentry-junior review

@sentry-junior sentry-junior Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the human reviewer

  • Is it OK that beforeSend and event processors now run for errors that are never sent (sampled out, or a duplicate once per request)? User callbacks with side effects or cost get more calls.
  • On the server, an error that overflows the promise buffer now counts in the request session without filters, so ignoreErrors matches still count in that case. Is that the trade-off you want?

With attachStacktrace, eventFromMessage adds exception values to a message event, so the
request session counted it as an error. The sessions spec says that captureMessage events
must not count. eventFromMessage now flags these events, and ServerRuntimeClient skips them.
Replace a fixed 20 ms sleep with fake timers that advance exactly the delay of the async
beforeSend. Use denoHttpIntegration in the sampled-errors session suite when httpIntegration
does not exist, as the shared sessions suite does.
@s1gr1d

s1gr1d commented Dec 3, 2026

Copy link
Copy Markdown
Member Author

@sentry-junior review

@sentry-junior sentry-junior Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No findings.

@s1gr1d
s1gr1d removed this pull request from stack #26820 December 3, 2026 16:55
@s1gr1d
s1gr1d changed the base branch from develop to ref/request-session-wait-for-pending-errors December 3, 2026 16:55
@s1gr1d
s1gr1d added this pull request to stack #27141 December 3, 2026 16:55

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Request sessions count errors dropped by ignoreErrors or beforeSend

1 participant