Repository navigation
fix(core): Freeze streamed segment DSC on first flush or segment end #26653
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
Merged
+131
−2
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
30 changes: 30 additions & 0 deletions
30
...s/suites/tracing/browserTracingIntegration/navigation-after-pageload-trace-header/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,30 @@ | ||
| import * as Sentry from '@sentry/browser'; | ||
|
|
||
| window.Sentry = Sentry; | ||
|
|
||
| Sentry.init({ | ||
| dsn: 'https://public@dsn.ingest.sentry.io/1337', | ||
| integrations: [ | ||
| Sentry.browserTracingIntegration({ | ||
| enableReportPageLoaded: true, | ||
| // Otherwise, the navigation right after the pageload start counts as a redirect | ||
| detectRedirects: false, | ||
| }), | ||
| ], | ||
| tracesSampleRate: 1, | ||
| }); | ||
|
|
||
| const pageloadPropagationContext = Sentry.getCurrentScope().getPropagationContext(); | ||
| window._pageloadSampleRand = pageloadPropagationContext.sampleRand; | ||
|
|
||
| // Record which trace the scope holds when the pageload span envelope is sent | ||
| Sentry.getClient().on('beforeEnvelope', envelope => { | ||
| const isSpanEnvelope = envelope[1].some(([itemHeader]) => itemHeader.type === 'span'); | ||
| if (isSpanEnvelope && envelope[0].trace?.trace_id === pageloadPropagationContext.traceId) { | ||
| window._scopeTraceIdOnPageloadFlush = Sentry.getCurrentScope().getPropagationContext().traceId; | ||
| } | ||
| }); | ||
|
|
||
| // End the pageload span and start a new trace in the same tick, so both happen before the pageload span is flushed | ||
| Sentry.reportPageLoaded(); | ||
| window.history.pushState({}, '', '/sub-page'); |
54 changes: 54 additions & 0 deletions
54
...s/suites/tracing/browserTracingIntegration/navigation-after-pageload-trace-header/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,54 @@ | ||
| import { NAVIGATION, PAGELOAD } from '@sentry/conventions/op'; | ||
| import { SENTRY_IDLE_SPAN_FINISH_REASON } from '@sentry/conventions/attributes'; | ||
| import { expect } from '@playwright/test'; | ||
| import { sentryTest } from '../../../../utils/fixtures'; | ||
| import { shouldSkipTracingTest } from '../../../../utils/helpers'; | ||
| import { getSpanOp, waitForStreamedSpanAndTraceHeader } from '../../../../utils/spanUtils'; | ||
|
|
||
| sentryTest( | ||
| "keeps the pageload's trace values in its trace envelope header when a new navigation trace starts before the pageload spans are flushed", | ||
| async ({ getLocalTestUrl, page }) => { | ||
| if (shouldSkipTracingTest()) { | ||
| sentryTest.skip(); | ||
| } | ||
|
|
||
| const url = await getLocalTestUrl({ testDir: __dirname }); | ||
|
|
||
| const pageloadPromise = waitForStreamedSpanAndTraceHeader(page, span => getSpanOp(span) === PAGELOAD); | ||
| const navigationPromise = waitForStreamedSpanAndTraceHeader(page, span => getSpanOp(span) === NAVIGATION); | ||
|
|
||
| await page.goto(url); | ||
|
|
||
| const [pageloadSpan, pageloadTraceHeader] = await pageloadPromise; | ||
| const [navigationSpan, navigationTraceHeader] = await navigationPromise; | ||
|
|
||
| const { pageloadSampleRand, scopeTraceIdOnPageloadFlush } = await page.evaluate(() => ({ | ||
| pageloadSampleRand: (window as any)._pageloadSampleRand, | ||
| scopeTraceIdOnPageloadFlush: (window as any)._scopeTraceIdOnPageloadFlush, | ||
| })); | ||
|
|
||
| expect(pageloadSpan.trace_id).not.toEqual(navigationSpan.trace_id); | ||
| expect(pageloadSpan.attributes[SENTRY_IDLE_SPAN_FINISH_REASON]?.value).toBe('reportPageLoaded'); | ||
|
|
||
| // The pageload span envelope was only sent after the navigation started its new trace on the scope | ||
| expect(scopeTraceIdOnPageloadFlush).toBe(navigationSpan.trace_id); | ||
|
|
||
| // The navigation resets the propagation context on the scope the pageload span captured. | ||
| // The pageload envelope is flushed after that, but must still carry the pageload's values. | ||
| expect(pageloadTraceHeader).toEqual({ | ||
| environment: 'production', | ||
| public_key: 'public', | ||
| trace_id: pageloadSpan.trace_id, | ||
| sample_rate: '1', | ||
| sampled: 'true', | ||
| sample_rand: String(pageloadSampleRand), | ||
| }); | ||
|
|
||
| expect(navigationTraceHeader).toMatchObject({ | ||
| trace_id: navigationSpan.trace_id, | ||
| sampled: 'true', | ||
| }); | ||
|
|
||
| expect(navigationTraceHeader?.sample_rand).not.toEqual(pageloadTraceHeader?.sample_rand); | ||
| }, | ||
| ); |
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
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.
Freezing here also freezes the transaction name. If the first flush happens before the name is parameterized, the DSC never gets the final name, where before the last envelope did. Is that an issue?
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.
Not sure if that would surface in e2e
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.
that's intentional. I think diverging between trace boundaries (i.e. when we propagate via baggage) is one thing but diverging within the same service (for two or more envelopes) is something we should avoid.