Skip to content

feat(browser): Add fetchStreamPerformanceIntegration for streamed response tracking#20778

Open
nicohrubec wants to merge 20 commits into
developfrom
feat/migrate-fetch-timestamp-adjustment-to-process-span
Open

feat(browser): Add fetchStreamPerformanceIntegration for streamed response tracking#20778
nicohrubec wants to merge 20 commits into
developfrom
feat/migrate-fetch-timestamp-adjustment-to-process-span

Conversation

@nicohrubec
Copy link
Copy Markdown
Member

@nicohrubec nicohrubec commented May 9, 2026

Replaces the event processor approach for trackFetchStreamPerformance with a new fetchStreamPerformanceIntegration().

Instead of retroactively patching http.client span timestamps, the integration creates a sibling http.client.stream span that starts when response headers arrive and ends when the response body fully resolves. The existing trackFetchStreamPerformance flag on the browserTracingIntegration still works by auto-adding the integration under the hood (deprecated in favor of adding the integration directly). Currently this will extend the pageload span until the full body of the streamed request has resolved. An added benefit of this approach is that we now get data about how much this is actually used.

Screenshots from a local sample app

Feature disabled:
Screenshot 2026-05-13 at 13 12 58

Feature enabled:
Screenshot 2026-05-13 at 13 11 31

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
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 Outdated
Comment thread packages/browser/src/tracing/request.ts Outdated
Comment thread packages/browser/src/tracing/request.ts Outdated
@nicohrubec nicohrubec marked this pull request as draft May 12, 2026 14:59
@nicohrubec nicohrubec changed the title feat(browser): Defer fetch span end until stream body resolves feat(browser): Add fetchStreamPerformanceIntegration for streamed response tracking May 13, 2026
@nicohrubec nicohrubec changed the title feat(browser): Add fetchStreamPerformanceIntegration for streamed response tracking feat(browser): Add fetchStreamPerformanceIntegration for streamed response tracking May 13, 2026
Comment thread packages/browser/src/integrations/fetchStreamPerformance.ts Outdated
Comment thread packages/browser/src/integrations/fetchStreamPerformance.ts
Comment thread packages/browser/src/tracing/browserTracingIntegration.ts
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@nicohrubec nicohrubec marked this pull request as ready for review May 13, 2026 12:38
@nicohrubec nicohrubec marked this pull request as draft May 13, 2026 12:41
Comment thread packages/browser/src/integrations/fetchStreamPerformance.ts Outdated
nicohrubec and others added 2 commits May 13, 2026 14:45
The http.client and http.client.stream spans may arrive in different
envelopes. Wait for each independently instead of requiring both in
the same envelope.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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 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.

Reviewed by Cursor Bugbot for commit f596fcd. Configure here.

} from '@sentry-internal/browser-utils';
import { DEBUG_BUILD } from '../debug-build';
import { getHttpRequestData, WINDOW } from '../helpers';
import { fetchStreamPerformanceIntegration } from '../integrations/fetchStreamPerformance';
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Static import increases bundle size for all users

Medium Severity

The static import of fetchStreamPerformanceIntegration in browserTracingIntegration.ts pulls the entire module (including its dependency on addFetchEndInstrumentationHandler and the stream-reading code like resolveResponse/streamHandler) into every bundle containing browserTracingIntegration, even though trackFetchStreamPerformance defaults to false. This increases browser bundle size for all users regardless of whether they use this feature. Flagging per rule on bundle size increases in browser packages.

Additional Locations (1)
Fix in Cursor Fix in Web

Triggered by project rule: PR Review Guidelines for Cursor Bot

Reviewed by Cursor Bugbot for commit f596fcd. Configure here.

Copy link
Copy Markdown
Member Author

@nicohrubec nicohrubec May 13, 2026

Choose a reason for hiding this comment

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

looks manageable from the size report, we can completely remove the flag in v11 then this approach should be much better for bundle size

@getsentry getsentry deleted a comment from github-actions Bot May 13, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 13, 2026

size-limit report 📦

Path Size % Change Change
@sentry/browser 26.89 kB - -
@sentry/browser - with treeshaking flags 25.33 kB - -
@sentry/browser (incl. Tracing) 44.94 kB +0.32% +143 B 🔺
@sentry/browser (incl. Tracing + Span Streaming) 46.94 kB +0.31% +145 B 🔺
@sentry/browser (incl. Tracing, Profiling) 49.93 kB +0.3% +148 B 🔺
@sentry/browser (incl. Tracing, Replay) 84.57 kB +0.17% +143 B 🔺
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 73.99 kB +0.18% +130 B 🔺
@sentry/browser (incl. Tracing, Replay with Canvas) 89.27 kB +0.17% +143 B 🔺
@sentry/browser (incl. Tracing, Replay, Feedback) 101.92 kB +0.16% +157 B 🔺
@sentry/browser (incl. Feedback) 44.08 kB - -
@sentry/browser (incl. sendFeedback) 31.7 kB - -
@sentry/browser (incl. FeedbackAsync) 36.81 kB - -
@sentry/browser (incl. Metrics) 27.98 kB - -
@sentry/browser (incl. Logs) 28.13 kB - -
@sentry/browser (incl. Metrics & Logs) 28.8 kB - -
@sentry/react 28.64 kB - -
@sentry/react (incl. Tracing) 47.2 kB +0.3% +140 B 🔺
@sentry/vue 31.82 kB - -
@sentry/vue (incl. Tracing) 46.81 kB +0.3% +138 B 🔺
@sentry/svelte 26.91 kB - -
CDN Bundle 29.31 kB +0.12% +34 B 🔺
CDN Bundle (incl. Tracing) 47.24 kB +0.08% +35 B 🔺
CDN Bundle (incl. Logs, Metrics) 30.68 kB +0.11% +33 B 🔺
CDN Bundle (incl. Tracing, Logs, Metrics) 48.36 kB +0.05% +21 B 🔺
CDN Bundle (incl. Replay, Logs, Metrics) 70 kB +0.04% +25 B 🔺
CDN Bundle (incl. Tracing, Replay) 84.67 kB +0.09% +74 B 🔺
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) 85.72 kB +0.07% +58 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback) 90.52 kB +0.13% +113 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) 91.61 kB +0.12% +105 B 🔺
CDN Bundle - uncompressed 86.34 kB +0.24% +199 B 🔺
CDN Bundle (incl. Tracing) - uncompressed 142.15 kB +0.33% +457 B 🔺
CDN Bundle (incl. Logs, Metrics) - uncompressed 90.53 kB +0.23% +199 B 🔺
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed 145.62 kB +0.32% +457 B 🔺
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed 215.36 kB +0.1% +199 B 🔺
CDN Bundle (incl. Tracing, Replay) - uncompressed 260.86 kB +0.18% +457 B 🔺
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed 264.31 kB +0.18% +457 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 274.56 kB +0.17% +457 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed 278 kB +0.17% +457 B 🔺
@sentry/nextjs (client) 49.69 kB +0.25% +119 B 🔺
@sentry/sveltekit (client) 45.43 kB +0.32% +143 B 🔺
@sentry/node-core 60.89 kB +0.02% +8 B 🔺
@sentry/node 166.03 kB +0.01% +5 B 🔺
@sentry/node - without tracing 74.02 kB +0.02% +13 B 🔺
@sentry/aws-serverless 108.12 kB +0.01% +5 B 🔺
@sentry/cloudflare (withSentry) - minified 170.88 kB - -
@sentry/cloudflare (withSentry) 431.1 kB - -

View base workflow run

@nicohrubec nicohrubec marked this pull request as ready for review May 13, 2026 14:22
The http.client span now ends at header arrival. Streaming duration
is captured in the http.client.stream sibling span instead.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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)

3 participants