Skip to content

feat(browser): Defer fetch span end until stream body resolves#20778

Open
nicohrubec wants to merge 7 commits intodevelopfrom
feat/migrate-fetch-timestamp-adjustment-to-process-span
Open

feat(browser): Defer fetch span end until stream body resolves#20778
nicohrubec wants to merge 7 commits intodevelopfrom
feat/migrate-fetch-timestamp-adjustment-to-process-span

Conversation

@nicohrubec
Copy link
Copy Markdown
Member

@nicohrubec nicohrubec commented May 9, 2026

If trackFetchStreamPerformance was enabled, the SDK ended http.client spans immediately when response headers arrived, then retroactively patching the end timestamp via an event processor when the transaction is flushed. Now, instead of patching after the fact, the span end is deferred entirely until the response body stream resolves. This removes the need for the event processor and works for both transaction and span streaming paths.

Screenshots from a local sample app

Feature disabled:
Screenshot 2026-05-11 at 12 51 23

Feature enabled:
Screenshot 2026-05-11 at 12 56 15

Closes #20376

nicohrubec and others added 2 commits May 9, 2026 10:25
Add a `processSpan` hook alongside the existing event processor to
support the span streaming path for fetch stream timestamp corrections.

Ref: #20376

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Instead of ending the span at header arrival and patching timestamps
later via event processor, defer the span end until the response body
fully resolves. Removes the event processor entirely.

Closes #20376

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@nicohrubec nicohrubec changed the title feat(browser): Add processSpan hook for fetch timestamp adjustment feat(browser): Migrate fetch stream timestamp adjustment away from event processor May 9, 2026
@nicohrubec nicohrubec changed the title feat(browser): Migrate fetch stream timestamp adjustment away from event processor feat(browser): Defer fetch span end until stream body resolves May 9, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 9, 2026

size-limit report 📦

Path Size % Change Change
@sentry/browser 26.37 kB - -
@sentry/browser - with treeshaking flags 24.82 kB - -
@sentry/browser (incl. Tracing) 44.28 kB +0.1% +43 B 🔺
@sentry/browser (incl. Tracing + Span Streaming) 46.5 kB +0.08% +35 B 🔺
@sentry/browser (incl. Tracing, Profiling) 49.25 kB +0.06% +29 B 🔺
@sentry/browser (incl. Tracing, Replay) 83.89 kB +0.04% +31 B 🔺
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 73.36 kB +0.07% +46 B 🔺
@sentry/browser (incl. Tracing, Replay with Canvas) 88.57 kB +0.03% +26 B 🔺
@sentry/browser (incl. Tracing, Replay, Feedback) 101.22 kB +0.04% +34 B 🔺
@sentry/browser (incl. Feedback) 43.53 kB - -
@sentry/browser (incl. sendFeedback) 31.19 kB - -
@sentry/browser (incl. FeedbackAsync) 36.27 kB - -
@sentry/browser (incl. Metrics) 27.65 kB - -
@sentry/browser (incl. Logs) 27.78 kB - -
@sentry/browser (incl. Metrics & Logs) 28.47 kB - -
@sentry/react 28.11 kB - -
@sentry/react (incl. Tracing) 46.53 kB +0.08% +34 B 🔺
@sentry/vue 31.24 kB - -
@sentry/vue (incl. Tracing) 46.13 kB +0.09% +40 B 🔺
@sentry/svelte 26.39 kB - -
CDN Bundle 28.95 kB - -
CDN Bundle (incl. Tracing) 46.96 kB -0.03% -10 B 🔽
CDN Bundle (incl. Logs, Metrics) 30.36 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) 48.06 kB -0.06% -28 B 🔽
CDN Bundle (incl. Replay, Logs, Metrics) 69.68 kB - -
CDN Bundle (incl. Tracing, Replay) 84.43 kB +0.08% +62 B 🔺
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) 85.5 kB +0.09% +76 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback) 90.22 kB +0.08% +65 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) 91.33 kB +0.09% +78 B 🔺
CDN Bundle - uncompressed 84.98 kB - -
CDN Bundle (incl. Tracing) - uncompressed 140.76 kB +0.16% +223 B 🔺
CDN Bundle (incl. Logs, Metrics) - uncompressed 89.17 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed 144.22 kB +0.16% +223 B 🔺
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed 214 kB - -
CDN Bundle (incl. Tracing, Replay) - uncompressed 259.47 kB +0.09% +223 B 🔺
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed 262.91 kB +0.09% +223 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 273.17 kB +0.09% +223 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed 276.6 kB +0.09% +223 B 🔺
@sentry/nextjs (client) 49.03 kB +0.05% +24 B 🔺
@sentry/sveltekit (client) 44.75 kB +0.07% +31 B 🔺
@sentry/node-core 60.56 kB +0.02% +7 B 🔺
@sentry/node 165.63 kB +0.01% +8 B 🔺
@sentry/node - without tracing 73.59 kB +0.02% +12 B 🔺
@sentry/aws-serverless 107.74 kB +0.01% +7 B 🔺
@sentry/cloudflare (withSentry) - minified 169.66 kB - -
@sentry/cloudflare (withSentry) 428.38 kB - -

View base workflow run

nicohrubec and others added 4 commits May 9, 2026 11:15
Instead of reimplementing endSpan logic (HTTP status, content-length,
onRequestSpanEnd), stash the original handlerData, put the span back
in the spans record, and let instrumentFetchRequest handle everything.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Add a Playwright test verifying that spans produced via the deferred
span end path have correct attributes, status, and trace context.
Also remove unnecessary dynamic delete from spans record.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Remove unused span field from deferred data map and rename for clarity.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@nicohrubec nicohrubec marked this pull request as ready for review May 11, 2026 10:56
@nicohrubec nicohrubec requested a review from a team as a code owner May 11, 2026 10:56
@nicohrubec nicohrubec requested a review from chargome May 11, 2026 10:57
Comment thread packages/browser/src/tracing/request.ts
Comment thread packages/browser/src/tracing/request.ts
Copy link
Copy Markdown

@cursor cursor Bot left a comment

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 dfaaf26. Configure here.

}, STREAM_RESOLVE_FALLBACK_MS);

spanIdToFallbackTimeout.set(spanId, fallbackTimeout);
return;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Deferred spans lost in non-streaming transaction path

High Severity

When trackFetchStreamPerformance is enabled without spanStreamingIntegration, the fetch span end is now fully deferred until the body stream resolves. The removed event processor previously ensured the span was always included in the transaction (with the header-arrival timestamp), patching it retroactively if the body resolved in time. Now, if the idle span (pageload/navigation) ends and the transaction is sent before the body resolves, the http.client span will be entirely absent from the transaction — a silent data loss regression compared to the old behavior, which always included the span.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit dfaaf26. Configure here.

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.

jep right I also ran into this locally. not sure if there is a better way to do this migration though, so we'll likely have to live with this limitation or we'll skip the whole migration altogether so this feature just won't work on the streaming path

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 this is exactly why this is implemented this way 😅 likely we'll need both ways implemented somehow...

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.

Event processor migration: Browser fetch timestamp adjustments (TBD)

2 participants