Skip to content

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

Open
s1gr1d wants to merge 5 commits into
developfrom
sig/request-session-filtered-errors
Open

s1gr1d wants to merge 5 commits into
developfrom
sig/request-session-filtered-errors

Conversation

@s1gr1d

@s1gr1d s1gr1d commented Oct 21, 2026 •

Copy link
Copy Markdown
Member

Errors that ignoreErrors, beforeSend or an event processor drops no longer mark the request session as errored or crashed. Errors that sampleRate drops still count. This is the same rule that already applies to client sessions since #22671.

Before, ServerRuntimeClient set the request session status in captureException/captureEvent, before the event pipeline ran. Now the status is set at the same point in the pipeline as the client session update.

Event processing can finish after the response ends (e.g. async ContextLines reads). Because of this, the request session now waits for its pending error events before it is recorded. If client.flush() runs during that wait, the session is sent immediately. This is necessary because the flush sends the aggregate before it waits for event processing.

Reference PR: #25751

Fixes #25605

@s1gr1d
s1gr1d requested a review from a team as a code owner October 21, 2026 16:07
@s1gr1d

s1gr1d commented Oct 21, 2026

Copy link
Copy Markdown
Member Author

bugbot run

@github-actions

github-actions Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

size-limit report 📦

Compared: c2007eb (PR test merge using develop at e1026aa)

Against: e1026aa (develop) · base run #63365

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

Path Size % Change Change
@sentry/browser 30.01 kB +0.09% +24 B 🔺
@sentry/browser - with treeshaking flags 28.15 kB +0.09% +24 B 🔺
@sentry/browser - with treeshaking flags tracing without tracing 28.05 kB +0.09% +24 B 🔺
@sentry/browser (incl. Tracing) 52.2 kB +0.06% +27 B 🔺
@sentry/browser (incl. Tracing + Span Streaming) 52.2 kB +0.06% +27 B 🔺
@sentry/browser (incl. Tracing, Profiling) 55.15 kB +0.05% +27 B 🔺
@sentry/browser (incl. Tracing, Replay) 91.98 kB +0.03% +20 B 🔺
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 80.88 kB +0.03% +24 B 🔺
@sentry/browser (incl. Tracing, Replay with Canvas) 96.71 kB +0.03% +20 B 🔺
@sentry/browser (incl. Tracing, Replay, Feedback) 109.65 kB +0.02% +21 B 🔺
@sentry/browser (incl. Feedback) 47.53 kB +0.06% +25 B 🔺
@sentry/browser (incl. sendFeedback) 35.08 kB +0.07% +24 B 🔺
@sentry/browser (incl. FeedbackAsync) 40.18 kB +0.06% +24 B 🔺
@sentry/browser (incl. Metrics) 31.03 kB +0.08% +22 B 🔺
@sentry/browser (incl. Logs) 31.3 kB +0.07% +21 B 🔺
@sentry/browser (incl. Metrics & Logs) 31.97 kB +0.08% +24 B 🔺
@sentry/react 31.84 kB +0.07% +22 B 🔺
@sentry/react (incl. Tracing) 54.53 kB +0.06% +32 B 🔺
@sentry/vue 38.17 kB +0.08% +27 B 🔺
@sentry/vue (incl. Tracing) 55.13 kB +0.05% +23 B 🔺
@sentry/svelte 30.03 kB +0.08% +24 B 🔺
@sentry/remix (Remix 3 client bundle) 57.22 kB +0.04% +21 B 🔺
CDN Bundle 31.77 kB +0.06% +16 B 🔺
CDN Bundle (incl. Tracing) 52.73 kB +0.04% +18 B 🔺
CDN Bundle (incl. Logs, Metrics) 33.97 kB +0.06% +19 B 🔺
CDN Bundle (incl. Tracing, Logs, Metrics) 54.68 kB +0.05% +24 B 🔺
CDN Bundle (incl. Replay, Logs, Metrics) 74.94 kB +0.02% +14 B 🔺
CDN Bundle (incl. Tracing, Replay) 90.43 kB +0.03% +22 B 🔺
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) 92.36 kB +0.03% +24 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback) 96.57 kB +0.03% +25 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) 98.52 kB +0.03% +23 B 🔺
CDN Bundle - uncompressed 93.58 kB +0.07% +65 B 🔺
CDN Bundle (incl. Tracing) - uncompressed 156.43 kB +0.05% +65 B 🔺
CDN Bundle (incl. Logs, Metrics) - uncompressed 100.13 kB +0.07% +65 B 🔺
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed 162.4 kB +0.05% +65 B 🔺
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed 230.34 kB +0.03% +65 B 🔺
CDN Bundle (incl. Tracing, Replay) - uncompressed 276.77 kB +0.03% +65 B 🔺
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed 282.73 kB +0.03% +65 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 290.47 kB +0.03% +65 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed 296.42 kB +0.03% +65 B 🔺
@sentry/nextjs (client) 57.41 kB +0.05% +26 B 🔺
@sentry/sveltekit (client) 52.57 kB +0.04% +20 B 🔺
@sentry/core/server 42.02 kB +0.33% +136 B 🔺
@sentry/core/browser 13.81 kB - -
@sentry/node 153.34 kB +0.1% +142 B 🔺
@sentry/node/import (ESM hook with diagnostics-channel injection) 81.58 kB - -
@sentry/node - without tracing 94.85 kB +0.15% +138 B 🔺
@sentry/node - without channel injection 133.93 kB +0.11% +134 B 🔺
@sentry/aws-serverless 103.01 kB +0.14% +137 B 🔺
@sentry/cloudflare (withSentry) - minified 194.02 kB +0.15% +284 B 🔺
@sentry/cloudflare (withSentry) 482.85 kB +0.2% +936 B 🔺
@sentry/nextjs/cloudflare (withSentry) - minified 214.67 kB +0.13% +272 B 🔺

View base workflow run

@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 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.

Reviewed by Cursor Bugbot for commit e4c2c57. Configure here.


if (flushNow) {
flushPendingClientAggregates();
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Flush-now skips existing aggregates

Medium Severity

When a request session settles after client.flush(), flushNow only sends if this call created the aggregate. Another request that records during that wait can already have opened a bucket, so this session is added and not sent. The in-flight flush then drains the transport without it, and a shutdown flush can drop the session.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit e4c2c57. Configure here.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think one way we could solve this is by adding something like an afterFlushProcessing client hook that the client emits in its flush method after determining clientFinished. This should allow us to get rid of the flushNow flag that only worked locally for this request

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

sounds good!

@github-actions

github-actions Bot commented Oct 21, 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-anthropic-send-to-sentry (latest) Test (optional) Failing after 24s Details
Successful checks
Check Status
✅ CI: Optional E2E Tests / E2E astro-7-static Test (optional) Successful in 48s Details
✅ CI: Optional E2E Tests / E2E nextjs-16-tunnel (cloudflare) Test (optional) Successful in 53s Details
✅ CI: Optional E2E Tests / E2E nextjs-16 (vinext) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E nextjs-16 (vinext, bun) Test (optional) Successful in 2m Details
✅ CI: Optional E2E Tests / E2E cloudflare-think Test (optional) Successful in 49s Details
✅ CI: Optional E2E Tests / E2E angular (canary) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E nextjs-14 (canary) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E gen-ai-libraries Test (optional) Successful in 44s Details
✅ CI: Optional E2E Tests / E2E cloudflare-pi-durable Test (optional) Successful in 33s Details
✅ CI: Optional E2E Tests / E2E cloudflare-mastra Test (optional) Successful in 48s Details
✅ CI: Optional E2E Tests / E2E cloudflare-pi-durable (latest) Test (optional) Successful in 31s Details
✅ CI: Optional E2E Tests / E2E astro-7 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 cloudflare-flue-send-to-sentry Test (optional) Successful in 2m Details
✅ CI: Optional E2E Tests / E2E cloudflare-agent Test (optional) Successful in 24s Details
✅ CI: Optional E2E Tests / E2E nextjs-16 (cloudflare, latest) Test (optional) Successful in 2m Details
✅ CI: Optional E2E Tests / E2E node-openai-send-to-sentry Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E node-express-send-to-sentry Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E nextjs-14 (latest) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E nextjs-16 (deno) Test (optional) Successful in 2m Details
✅ CI: Optional E2E Tests / E2E cloudflare-workers-send-to-sentry Test (optional) Successful in 2m Details
✅ CI: Optional E2E Tests / E2E deno (latest) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E nextjs-16 (canary, turbopack) Test (optional) Successful in 3m Details
✅ CI: Optional E2E Tests / E2E nextjs-15 (latest) Test (optional) Successful in 4m Details
✅ CI: Optional E2E Tests / E2E node-express-mcp-v1 Test (optional) Successful in 26s Details
✅ CI: Optional E2E Tests / E2E node-openai-decisions-send-to-sentry (latest) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E node-express-mcp-v2 Test (optional) Successful in 20s Details
✅ CI: Optional E2E Tests / E2E nextjs-orpc Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E node-mastra (latest) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E vue-3 (canary) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E node-flue Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E node-express-send-to-sentry-static Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E solidstart-2 Test (optional) Successful in 43s Details
✅ CI: Optional E2E Tests / E2E cloudflare-think (ai v6) Test (optional) Successful in 59s Details
✅ CI: Optional E2E Tests / E2E node-mastra Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E nuxt-3 (canary) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E node-fastify-6 Test (optional) Successful in 25s Details
✅ CI: Optional E2E Tests / E2E nextjs-16-standalone (canary, turbopack) Test (optional) Successful in 30s Details
✅ CI: Optional E2E Tests / E2E node-anthropic-send-to-sentry Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E node-fastify-6 (tracer provider) Test (optional) Successful in 24s Details
✅ CI: Optional E2E Tests / E2E gen-ai-libraries (cloudflare) Test (optional) Successful in 34s Details
✅ CI: Optional E2E Tests / E2E node-openai-send-to-sentry (latest) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E node-pi-durable Test (optional) Successful in 34s Details
✅ CI: Optional E2E Tests / E2E nuxt-5-sourcemaps Test (optional) Successful in 37s Details
✅ CI: Optional E2E Tests / E2E nextjs-16 (canary, webpack) Test (optional) Successful in 5m Details
✅ CI: Optional E2E Tests / E2E node-eve Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E nuxt-5-sourcemaps (client source maps kept) Test (optional) Successful in 36s Details
✅ CI: Optional E2E Tests / E2E react-router-7-framework-instrumentation Test (optional) Successful in 2m Details
✅ CI: Optional E2E Tests / E2E react-send-to-sentry Test (optional) Successful in 2m Details
✅ CI: Optional E2E Tests / E2E nuxt-4 (canary) Test (optional) Successful in 3m Details
✅ CI: Optional E2E Tests / E2E angular (canary) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E nuxt-5 Test (optional) Successful in 2m Details
✅ CI: Optional E2E Tests / E2E supabase-nextjs Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E debug-id-sourcemaps Test (optional) Successful in 32s Details
✅ CI: Optional E2E Tests / E2E node-openai-decisions-send-to-sentry Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E node-flue (latest) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E tanstackstart-react-sourcemaps Test (optional) Successful in 27s Details
✅ CI: Optional E2E Tests / E2E nuxt-5-sourcemaps (static / nuxt generate) Test (optional) Successful in 26s Details
✅ CI: Optional E2E Tests / E2E nuxt-4-static (canary) Test (optional) Successful in 2m Details
✅ CI: Optional E2E Tests / E2E node-eve (orchestrion) Test (optional) Successful in 56s Details
✅ CI: Optional E2E Tests / E2E node-pi-durable (latest) Test (optional) Successful in 31s Details
✅ CI: Optional E2E Tests / E2E node-eve (latest) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E tanstackstart-react-cloudflare Test (optional) Successful in 26s Details
✅ CI: Optional E2E Tests / E2E vue-3 (no Options API) Test (optional) Successful in 1m Details

@Lms24 Lms24 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for fixing this, I admittedly forgot about the server side part when we made the change in browser.

Took me a bit to understand the pendingRequests logic but I think it's fine and shouldn't hurt us or leak memory (that is assuming the isolationScope cleans up at which point the references to the pending errors should be gc'd).

I think we still should address the bugbot comment but otherwise, looks great!

The scenario sets `sessionFlushingDelayMS` on `httpIntegration`, which has no effect with `@sentry/bun`, so the session aggregate arrives after the test timeout.
A session that settled while `client.flush()` waited for event processing was only sent when it opened a new aggregate. If another request opened an aggregate during that wait, the session joined it and that flush did not send it.

Add an `afterFlushProcessing` client hook, which `flush()` emits after event processing and before the transport flush. Request session aggregates now also send on this hook.
@s1gr1d
s1gr1d requested review from Lms24 and isaacs October 23, 2026 14:28
@linear-code

linear-code Bot commented Oct 26, 2026

Copy link
Copy Markdown

JS-3979

@Lms24 Lms24 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nice!

@s1gr1d

s1gr1d commented Nov 23, 2026

Copy link
Copy Markdown
Member Author

A short update on this PR as I did not merge it yet. The other PR (#25751) working on sampled-out errors was not yet merged and I wanted to get this in as well. And the changes in this PR here (25632) do not fix the problem.

The Problem

A request session records an error whether one server request had an error (for the "crash-free" rate). The server SDK marks the request session as errored at the point the error is captured (no filter ran at this point). So errors dropped in ignoreErrors or beforeSend count as errored. The request shows as errored and lower the "crash-free" rate, even though Sentry does not have an issue for them.

The spec

https://develop.sentry.dev/sdk/telemetry/sessions/#session-update-filtering

This should be the order: event processors (incl. ignoreErrors) > before_send > session update > sampling > transport

  • Events dropped due to sampling or rate limiting SHOULD still update the session — the event was dropped to save quota but represents something the developer cares about.
  • Events dropped for other reasons (beforeSend, event processors, ignored types) SHOULD NOT update the session — the developer chose to ignore them.

If the event has been dropped but the session was updated, the session update SHOULD be sent to the server without the event in case the session changed from healthy to errored or from any state to crashed (for user-attended sessions).

For the exact position of the session update relative to these filters, see the event pipeline in the Client spec, which is the authoritative ordering. In short: the session update sits after beforeSend and before sampling, so developer-controlled filters run first and quota-saving drops run after.

Why the current state of this PR does not work

This PR moves the session update after beforeSend, as the spec requires. So now every drop also decides whether an error counts.

Dedupe

Dedupe drops an error if it is equal to the previous error. It stores one previous error for the whole client, and all requests share it.

  • Before, this didn't matter: the request session was already marked when the error was captured.
  • With this PR (current changes), a duplicate looks like a filter drop and does not count. If 1000 requests fail with the same error, only 1 request counts as errored. The crash-free rate goes up, and that's wrong.
  • We can't count duplicates without running the filters. Example: a beforeSend that drops health checks by URL. If a health check fails with the same error as a real request, its duplicate must not count.
  • In the same request, a duplicate adds nothing. The first error already decided that request's status. So only the first duplicate per request needs the filters (or an unhandled one, which can change errored to crashed).
  • The spec does not mention Dedupe. We treat it as a quota drop, like sampling.

Sampling

As (per spec) sampled-out errors must still update the session. So a sampled-out error that can update/change a session runs through the full pipeline, only to update the session. Develop already does this for the scope session. This PR also does it for request sessions, and on a server almost every error can change its request session.

But this has two problems:

  • Overflow: they use the same 64 slots as errors that are sent. In an error burst, they are dropped with queue_overflow.
  • Never sent: sampled-out errors reach Dedupe and become its previous error. The next sampled-in copy of that error is then a duplicate, and Dedupe drops it. With a sampleRate below 1, an error that repeats can be dropped every time and never reach Sentry. This already happens in 11.11.0.

What this PR will do

So we still need to make sure we keep sampled-out errors in mind for the crash-free rate, but we cannot go through the whole pipeline as this would lead to an overflow. So we make two buffers:

  • Delivery Buffer that will hold the errors that will actually be sent (so we avoid a queue_overflow)
  • Session Buffer holds errors that the SDK never sends but that can still change a session. They run through the event processors and beforeSend, and they count if both keep them.

The cost: beforeSend now also runs for errors that are not sent. With 1000 failing requests, it runs 1000 times instead of 3. Each request is its own session, so each request needs its own beforeSend result. This is also how this works in the Python SDK.

Spec Update?

Open question: the Client spec says event processor drops MUST NOT update the session. We count Dedupe drops anyway, because Dedupe drops to save quota, not because the developer chose to ignore the error. We should probably mention this explicitly in the spec.

Flow before/after

Before (develop) After (this PR soon)
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{"Sampled out?"}
  SMP -- "yes, no session can change" --> D1["Drop: sample_rate"]
  SMP -- "yes, a session can change" --> SP
  SMP -- "no" --> P

  subgraph DB["Delivery buffer (64 slots): only errors that can be sent"]
    P["Event processors<br/>(Dedupe compares with the previous error)"] --> BS{"beforeSend"}
    BS -- "keeps" --> US["Update sessions<br/>scope + request"]
    US --> SEND["Send"]
  end

  P -- "a filter drops" --> D2["Drop: event_processor"]
  BS -- "drops" --> D3["Drop: before_send"]
  P -- "duplicate" --> SR{"<b>Same request as the<br/>previous error, and handled?</b>"}
  SR -- "yes: the first error decides" --> D4["Drop: event_processor<br/>(as in 11.11.0)"]
  SR -- "no, and a session can change" --> SP
  SR -- "no, and no session can change" --> D4

  subgraph SB["Session buffer (own slots): errors that are never sent"]
    SP["Rest of the event processors<br/>(Dedupe ignores sampled-out errors)"] --> SBS{"beforeSend"}
    SBS -- "keeps" --> SU["Update sessions<br/>scope + request"]
  end

  SU --> D5["Drop: sample_rate or event_processor"]
  SBS -- "drops" --> D5

  classDef counts fill:#d4f4dd,stroke:#2e7d32
  classDef nocount fill:#eeeeee,stroke:#757575
  classDef newrule fill:#fff3cd,stroke:#b8860b
  class US,SU counts
  class D1,D2,D3,D4 nocount
  class SR newrule

Loading

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Request sessions count errors dropped by ignoreErrors or beforeSend

2 participants