-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
feat(browser): Defer fetch span end until stream body resolves #20778
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
nicohrubec
wants to merge
7
commits into
develop
Choose a base branch
from
feat/migrate-fetch-timestamp-adjustment-to-process-span
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
e479578
feat(browser): Add processSpan hook for fetch timestamp adjustment
nicohrubec 745a2f3
feat(browser): Defer fetch span end for streamed responses
nicohrubec 0d88922
refactor(browser): Replay deferred spans through instrumentFetchRequest
nicohrubec 2ba4397
test(browser): Add integration test for trackFetchStreamPerformance
nicohrubec 24e97f6
refactor(browser): Clean up deferred span data structures
nicohrubec 78dc307
yarn fix
nicohrubec dfaaf26
update
nicohrubec File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
14 changes: 14 additions & 0 deletions
14
...-integration-tests/suites/tracing/request/fetch-streamed-track-stream-performance/init.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| import * as Sentry from '@sentry/browser'; | ||
|
|
||
| window.Sentry = Sentry; | ||
|
|
||
| Sentry.init({ | ||
| dsn: 'https://public@dsn.ingest.sentry.io/1337', | ||
| integrations: [ | ||
| Sentry.browserTracingIntegration({ trackFetchStreamPerformance: true }), | ||
| Sentry.spanStreamingIntegration(), | ||
| ], | ||
| tracePropagationTargets: ['http://sentry-test-site.example'], | ||
| tracesSampleRate: 1, | ||
| autoSessionTracking: false, | ||
| }); |
1 change: 1 addition & 0 deletions
1
...tegration-tests/suites/tracing/request/fetch-streamed-track-stream-performance/subject.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| fetch('http://sentry-test-site.example/delayed').then(res => res.text()); |
43 changes: 43 additions & 0 deletions
43
...-integration-tests/suites/tracing/request/fetch-streamed-track-stream-performance/test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| import { expect } from '@playwright/test'; | ||
| import { sentryTest } from '../../../../utils/fixtures'; | ||
| import { shouldSkipTracingTest } from '../../../../utils/helpers'; | ||
| import { getSpanOp, waitForStreamedSpans } from '../../../../utils/spanUtils'; | ||
|
|
||
| sentryTest( | ||
| 'span has correct attributes when trackFetchStreamPerformance is enabled', | ||
| async ({ getLocalTestUrl, page }) => { | ||
| sentryTest.skip(shouldSkipTracingTest()); | ||
|
|
||
| await page.route('http://sentry-test-site.example/*', route => route.fulfill({ body: 'ok', status: 200 })); | ||
|
|
||
| const url = await getLocalTestUrl({ testDir: __dirname }); | ||
|
|
||
| const spansPromise = waitForStreamedSpans(page, spans => spans.some(s => getSpanOp(s) === 'http.client')); | ||
|
|
||
| await page.goto(url); | ||
|
|
||
| const allSpans = await spansPromise; | ||
| const pageloadSpan = allSpans.find(s => getSpanOp(s) === 'pageload'); | ||
| const requestSpan = allSpans.find(s => getSpanOp(s) === 'http.client'); | ||
|
|
||
| expect(requestSpan).toBeDefined(); | ||
| expect(requestSpan!.end_timestamp).toBeGreaterThan(requestSpan!.start_timestamp); | ||
| expect(requestSpan).toMatchObject({ | ||
| name: 'GET http://sentry-test-site.example/delayed', | ||
| parent_span_id: pageloadSpan?.span_id, | ||
| span_id: expect.stringMatching(/[a-f\d]{16}/), | ||
| start_timestamp: expect.any(Number), | ||
| end_timestamp: expect.any(Number), | ||
| trace_id: pageloadSpan?.trace_id, | ||
| status: 'ok', | ||
| attributes: expect.objectContaining({ | ||
| 'http.method': { type: 'string', value: 'GET' }, | ||
| 'http.url': { type: 'string', value: 'http://sentry-test-site.example/delayed' }, | ||
| url: { type: 'string', value: 'http://sentry-test-site.example/delayed' }, | ||
| 'server.address': { type: 'string', value: 'sentry-test-site.example' }, | ||
| type: { type: 'string', value: 'fetch' }, | ||
| 'http.response.status_code': { type: 'integer', value: 200 }, | ||
| }), | ||
| }); | ||
| }, | ||
| ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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
trackFetchStreamPerformanceis enabled withoutspanStreamingIntegration, 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, thehttp.clientspan 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)
packages/browser/src/tracing/request.ts#L166-L191Reviewed by Cursor Bugbot for commit dfaaf26. Configure here.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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...
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was going to say what happens if the root span becomes inactive, then we would lose this span. It would've been great if we knew how many people are using it but I don't see any marking attributes we can use here.
Do we think deprecating this integration for span v2 is an option?