Skip to content

fix(node): Flush telemetry before Vercel functions are suspended - #24910

Open
sergical wants to merge 2 commits into
developfrom
fix/vercel-node-waituntil-span-flush
Open

sergical wants to merge 2 commits into
developfrom
fix/vercel-node-waituntil-span-flush

Conversation

@sergical

@sergical sergical commented Sep 30, 2026 •

Copy link
Copy Markdown
Member

On Vercel, a function can be suspended as soon as it sends the response. Telemetry that is still buffered (spans, logs, metrics, errors) then arrives late or never.

When a response finishes, @sentry/node now uses waitUntil to keep the function alive. It waits until the response closes and the request's root span ends (2 s max), then flushes. It works with or without tracing.

Some frameworks end the root span shortly after the response closes, so the flush waits for it.

Tested with unit tests and an integration test that fails without the change, and confirmed on a Vercel deployment.

Closes #24909. Refs #23087.

Created with Claude Code

@sergical sergical self-assigned this Sep 30, 2026
@github-actions

github-actions Bot commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

size-limit report 📦

Path Size % Change Change
@sentry/browser 29.51 kB - -
@sentry/browser - with treeshaking flags 27.68 kB - -
@sentry/browser - with treeshaking flags tracing without tracing 27.58 kB - -
@sentry/browser (incl. Tracing) 51.46 kB - -
@sentry/browser (incl. Tracing + Span Streaming) 51.47 kB - -
@sentry/browser (incl. Tracing, Profiling) 54.47 kB - -
@sentry/browser (incl. Tracing, Replay) 91.05 kB - -
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 80.03 kB - -
@sentry/browser (incl. Tracing, Replay with Canvas) 95.73 kB - -
@sentry/browser (incl. Tracing, Replay, Feedback) 108.72 kB - -
@sentry/browser (incl. Feedback) 47.04 kB - -
@sentry/browser (incl. sendFeedback) 34.57 kB - -
@sentry/browser (incl. FeedbackAsync) 39.69 kB - -
@sentry/browser (incl. Metrics) 30.53 kB - -
@sentry/browser (incl. Logs) 30.82 kB - -
@sentry/browser (incl. Metrics & Logs) 31.48 kB - -
@sentry/react 31.36 kB - -
@sentry/react (incl. Tracing) 53.82 kB - -
@sentry/vue 37.51 kB - -
@sentry/vue (incl. Tracing) 54.36 kB - -
@sentry/svelte 29.54 kB - -
@sentry/remix (Remix 3 client bundle) 55.75 kB - -
CDN Bundle 31.22 kB - -
CDN Bundle (incl. Tracing) 51.99 kB - -
CDN Bundle (incl. Logs, Metrics) 33.46 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) 53.94 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) 74.2 kB - -
CDN Bundle (incl. Tracing, Replay) 89.56 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) 91.54 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) 95.73 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) 97.73 kB - -
CDN Bundle - uncompressed 92.14 kB - -
CDN Bundle (incl. Tracing) - uncompressed 154.53 kB - -
CDN Bundle (incl. Logs, Metrics) - uncompressed 98.71 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed 160.48 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed 228.28 kB - -
CDN Bundle (incl. Tracing, Replay) - uncompressed 274.26 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed 280.2 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 287.96 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed 293.89 kB - -
@sentry/nextjs (client) 56.33 kB - -
@sentry/sveltekit (client) 51.88 kB - -
@sentry/core/server 39.99 kB - -
@sentry/core/browser 13.63 kB - -
@sentry/node 144.7 kB +0.16% +222 B 🔺
@sentry/node/import (ESM hook with diagnostics-channel injection) 83.08 kB - -
@sentry/node - without tracing 93.24 kB +0.24% +216 B 🔺
@sentry/node - without channel injection 122.96 kB +0.18% +209 B 🔺
@sentry/aws-serverless 101.53 kB +0.21% +208 B 🔺
@sentry/cloudflare (withSentry) - minified 207.1 kB - -
@sentry/cloudflare (withSentry) 515.31 kB - -

View base workflow run

@sergical
sergical marked this pull request as ready for review September 30, 2026 18:32
Comment thread packages/core/src/integrations/spanStreaming.ts
On Vercel, a function can be suspended as soon as it sends the response, so
buffered telemetry arrives late or never. When a response finishes, keep the
function alive with `waitUntil` until the response closes and the request's
root span ends (2 s max), then flush.

Closes #24909

Co-authored-by: Claude <claude@anthropic.com>
@sergical
sergical force-pushed the fix/vercel-node-waituntil-span-flush branch from 05da2d0 to 50ac024 Compare October 1, 2026 19:27
@sergical
sergical requested a review from a team as a code owner October 1, 2026 19:27
@sergical sergical changed the title fix(core): Keep Vercel Node.js instances alive until streamed spans are sent fix(node): Flush telemetry before Vercel functions are suspended Oct 1, 2026
@sergical
sergical requested review from isaacs and mydea and removed request for a team October 1, 2026 19:27
Comment thread packages/node/src/sdk/vercel.ts

@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 2 potential issues.

Fix All in Cursor

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

Want reviews to match your repository better? Bugbot Learning can learn team-specific rules from PR activity. A team admin can enable Learning in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 50ac024. Configure here.

Comment thread packages/node/src/sdk/vercel.ts Outdated
Comment thread packages/node/src/sdk/vercel.ts Outdated
- Wait at most 2 seconds for both the response to close and the root span to end, so a
  response that never emits `close` cannot hold the function open.
- Unref the timer and type the request-context global the same way `vercelWaitUntil` does.
- Bun does not publish `http.server.response.finish`, so the keep-alive suite is Node-only.

Co-authored-by: Claude <claude@anthropic.com>

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.

Telemetry is delayed or lost when Vercel suspends a Node.js function after the response

1 participant