feat(browser): Add fetchStreamPerformanceIntegration for streamed response tracking#20778
feat(browser): Add fetchStreamPerformanceIntegration for streamed response tracking#20778nicohrubec wants to merge 20 commits into
fetchStreamPerformanceIntegration for streamed response tracking#20778Conversation
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>
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>
fetchStreamPerformanceIntegration for streamed response tracking
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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>
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 2 potential issues.
❌ 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'; |
There was a problem hiding this comment.
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)
Triggered by project rule: PR Review Guidelines for Cursor Bot
Reviewed by Cursor Bugbot for commit f596fcd. Configure here.
There was a problem hiding this comment.
looks manageable from the size report, we can completely remove the flag in v11 then this approach should be much better for bundle size
size-limit report 📦
|
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>


Replaces the event processor approach for trackFetchStreamPerformance with a new
fetchStreamPerformanceIntegration().Instead of retroactively patching
http.clientspan timestamps, the integration creates a siblinghttp.client.streamspan that starts when response headers arrive and ends when the response body fully resolves. The existingtrackFetchStreamPerformanceflag on thebrowserTracingIntegrationstill 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:

Feature enabled:

Closes #20376