Skip to content

ref(core): Record request sessions after their errors are processed - #27139

Draft
s1gr1d wants to merge 1 commit into
fix/dedupe-ignore-never-sent-errorsfrom
ref/request-session-wait-for-pending-errors
Draft

s1gr1d wants to merge 1 commit into
fix/dedupe-ignore-never-sent-errorsfrom
ref/request-session-wait-for-pending-errors

Conversation

@s1gr1d

@s1gr1d s1gr1d commented Dec 3, 2026

Copy link
Copy Markdown
Member

What

A request session is now recorded when the errors of the request have left the event pipeline, not when the response ends. A session that settles during a flush() is sent with that flush.

The counts do not change. The status is still set when an error is captured.

Part 2 of 3 for #25605. Stacked on #27138. #26819 is stacked on this PR.

Why

#26819 decides the session status in the event pipeline, after beforeSend. With an async event processor or an async beforeSend, that result can come after the response ended, so the session must wait for it.

This PR adds only the wait, so that the flush handling can be reviewed without the counting rules.

Refs #25605

A request session is now recorded when the errors of the request have left the event
pipeline, not when the response ends. A session that settles during a flush is sent with that
flush. The status is still set when an error is captured, so the counts do not change.

This prepares the fix for #25605, which decides the status in the event pipeline.

Refs #25605
@github-actions

github-actions Bot commented Dec 3, 2026

Copy link
Copy Markdown
Contributor

size-limit report 📦

Compared: f04e713 (PR test merge using base PR #27138 at f8f90a3)

Against: 89bc3c1 (base PR #27138) · base run #68760

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

Path Size % Change Change
@sentry/browser 30.77 kB - -
@sentry/browser - with treeshaking flags 28.88 kB - -
@sentry/browser - with treeshaking flags tracing without tracing 28.76 kB - -
@sentry/browser (incl. Tracing) 54.12 kB - -
@sentry/browser (incl. Tracing Core) 40.94 kB - -
@sentry/browser (incl. Tracing + Span Streaming) 54.12 kB - -
@sentry/browser (incl. Tracing, Profiling) 57.01 kB - -
@sentry/browser (incl. Tracing, Replay) 94.09 kB - -
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 82.65 kB - -
@sentry/browser (incl. Tracing, Replay with Canvas) 98.94 kB - -
@sentry/browser (incl. Tracing, Replay, Feedback) 111.89 kB - -
@sentry/browser (incl. Feedback) 48.63 kB - -
@sentry/browser (incl. sendFeedback) 31.33 kB - -
@sentry/browser (incl. FeedbackAsync) 36.38 kB - -
@sentry/browser (incl. Metrics) 32.09 kB - -
@sentry/browser (incl. Logs) 32.37 kB - -
@sentry/browser (incl. Metrics & Logs) 33.05 kB - -
@sentry/react 32.65 kB - -
@sentry/react (incl. Tracing) 56.62 kB - -
@sentry/vue 39.12 kB - -
@sentry/vue (incl. Tracing) 57.2 kB - -
@sentry/svelte 30.81 kB - -
@sentry/effect (client) 42.32 kB - -
@sentry/effect (client, incl. Tracing) 55.15 kB - -
@sentry/effect (client, incl. Tracing, Logs, Metrics) 66.63 kB - -
@sentry/remix (Remix 3 client bundle) 59.59 kB - -
CDN Bundle 32.58 kB - -
CDN Bundle (incl. Tracing) 54.22 kB - -
CDN Bundle (incl. Logs, Metrics) 35.3 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) 56.65 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) 76.25 kB - -
CDN Bundle (incl. Tracing, Replay) 92.03 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) 94.52 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) 97.48 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) 99.94 kB - -
CDN Bundle - uncompressed 95.06 kB - -
CDN Bundle (incl. Tracing) - uncompressed 160.41 kB - -
CDN Bundle (incl. Logs, Metrics) - uncompressed 103.4 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed 168.04 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed 233.79 kB - -
CDN Bundle (incl. Tracing, Replay) - uncompressed 280.84 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed 288.47 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 292.77 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed 300.39 kB - -
@sentry/nextjs (client) 59.97 kB - -
@sentry/sveltekit (client) 54.95 kB - -
@sentry/astro (client) - rolldown, without tracing 35.88 kB - -
@sentry/core/server 46.2 kB +0.46% +208 B 🔺
@sentry/core/browser 14.55 kB - -
@sentry/node 158.03 kB +0.14% +211 B 🔺
@sentry/node/import (ESM hook with diagnostics-channel injection) 83.63 kB - -
@sentry/node - without tracing 90.03 kB +0.26% +228 B 🔺
@sentry/node - without channel injection 147.43 kB +0.15% +220 B 🔺
@sentry/aws-serverless 100.92 kB +0.21% +209 B 🔺
@sentry/cloudflare (withSentry) - minified 214.37 kB +0.41% +857 B 🔺
@sentry/cloudflare (withSentry) 497.79 kB +0.43% +2.13 kB 🔺
@sentry/cloudflare (withSentry, instrumented CommonJS package) - minified 217.31 kB +0.4% +857 B 🔺
@sentry/nextjs/cloudflare (withSentry) - minified 242.57 kB +0.36% +857 B 🔺

View base workflow run

@github-actions

github-actions Bot commented Dec 3, 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 1m Details
Successful checks
Check Status
✅ CI: Optional E2E Tests / E2E cloudflare-flue-send-to-sentry Test (optional) Successful in 2m Details
✅ CI: Optional E2E Tests / E2E nuxt-5 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 cloudflare-workers-without-tracing-send-to-sentry Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E gen-ai-libraries (latest) 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-agent Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E astro-7 Test (optional) Successful in 2m Details
✅ CI: Optional E2E Tests / E2E hapi-21 (bun) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E deno (latest) Test (optional) Successful in 2m Details
✅ CI: Optional E2E Tests / E2E cloudflare-workers-send-to-sentry Test (optional) Successful in 3m Details
✅ CI: Optional E2E Tests / E2E astro-7 (static trace lifecycle) 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 nextjs-15 (latest) Test (optional) Successful in 2m Details
✅ CI: Optional E2E Tests / E2E cloudflare-pi-durable (latest) 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 hono-5 (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 node-express-send-to-sentry (static trace lifecycle) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E debug-id-sourcemaps Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E node-eve (orchestrion) Test (optional) Successful in 3m Details
✅ CI: Optional E2E Tests / E2E nextjs-15 (turbo) Test (optional) Successful in 2m Details
✅ CI: Optional E2E Tests / E2E tanstackstart-react-sourcemaps (no upload) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E hono-5 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 nextjs-14-supabase Test (optional) Successful in 3m Details
✅ CI: Optional E2E Tests / E2E node-eve (content off) Test (optional) Successful in 3m Details
✅ CI: Optional E2E Tests / E2E nextjs-16 (vinext) 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 nextjs-16-tunnel (cloudflare) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E node-express-send-to-sentry 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 hapi-21 (deno) 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 node-flue (latest) 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 (deno) Test (optional) Successful in 3m Details
✅ CI: Optional E2E Tests / E2E nuxt-5 (development) Test (optional) Successful in 2m Details
✅ CI: Optional E2E Tests / E2E nuxt-5 (bun) Test (optional) Successful in 2m Details
✅ CI: Optional E2E Tests / E2E nuxt-5-sourcemaps (static / nuxt generate) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E node-pi-durable (latest) 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 tanstackstart-react-sourcemaps Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E nuxt-5-sourcemaps (client source maps kept) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E node-mastra (latest) Test (optional) Successful in 2m Details
✅ CI: Optional E2E Tests / E2E node-fastify-6 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-4-sourcemaps (Vite server) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E tanstackstart-react-sourcemaps (manual upload) 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-openai-decisions (latest) 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 solidstart-2 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 react-router-7-framework-instrumentation Test (optional) Successful in 3m Details
✅ CI: Optional E2E Tests / E2E tanstackstart-react-cloudflare 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 solidstart-2 (manual upload) 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 vinext-cf-workers (workers cache) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E solidstart-2 (delete all) 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 vue-3 (no Options API) Test (optional) Successful in 1m Details

@s1gr1d

s1gr1d commented Dec 3, 2026

Copy link
Copy Markdown
Member Author

@sentry-junior review

client.captureException(new Error('foo'));
endErroredRequestSession();

const flushed = client.flush();

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.

[m] packages/core/test/lib/server-runtime-client.test.ts:209: Both new tests pass without the change

The new path in startRequestSession isn't proven by a test. That path waits on pendingErrors, then sends at once if a flush ran in the meantime. captureException still sets the status synchronously. So on the base, the session goes into the aggregate at endErroredRequestSession() and the flush hook sends it, which gives the same sendSession calls in both tests. I reverted the four src files to the base (f8f90a3), and both tests in request sessions still pass.

This assertion checks that nothing is sent while beforeSend is still pending. With it, the first test fails on the base and passes on this head:

Suggested change
const flushed = client.flush();
const flushed = client.flush();
expect(sendSessionSpy).not.toHaveBeenCalled();

The second test (aggregates a session that settles after the request ended when no flush runs) has the same gap.

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.

1 participant