-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
feat(browser): Trace continuation from server-timing headers #18673
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
timfish
wants to merge
1
commit into
develop
Choose a base branch
from
timfish/feat/browser-server-timing
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
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
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
16 changes: 16 additions & 0 deletions
16
...kages/browser-integration-tests/suites/tracing/trace-lifetime/pageload-headers/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,16 @@ | ||
| const errorBtn = document.getElementById('errorBtn'); | ||
| errorBtn.addEventListener('click', () => { | ||
| throw new Error(`Sentry Test Error ${Math.random()}`); | ||
| }); | ||
|
|
||
| const fetchBtn = document.getElementById('fetchBtn'); | ||
| fetchBtn.addEventListener('click', async () => { | ||
| await fetch('http://sentry-test-site.example'); | ||
| }); | ||
|
|
||
| const xhrBtn = document.getElementById('xhrBtn'); | ||
| xhrBtn.addEventListener('click', () => { | ||
| const xhr = new XMLHttpRequest(); | ||
| xhr.open('GET', 'http://sentry-test-site.example'); | ||
| xhr.send(); | ||
| }); |
11 changes: 11 additions & 0 deletions
11
...es/browser-integration-tests/suites/tracing/trace-lifetime/pageload-headers/template.html
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,11 @@ | ||
| <!DOCTYPE html> | ||
| <html> | ||
| <head> | ||
| <meta charset="utf-8" /> | ||
| </head> | ||
| <body> | ||
| <button id="errorBtn">Throw Error</button> | ||
| <button id="fetchBtn">Fetch Request</button> | ||
| <button id="xhrBtn">XHR Request</button> | ||
| </body> | ||
| </html> |
85 changes: 85 additions & 0 deletions
85
...packages/browser-integration-tests/suites/tracing/trace-lifetime/pageload-headers/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,85 @@ | ||
| import { expect } from '@playwright/test'; | ||
| import { sentryTest } from '../../../../utils/fixtures'; | ||
| import type { EventAndTraceHeader } from '../../../../utils/helpers'; | ||
| import { | ||
| eventAndTraceHeaderRequestParser, | ||
| getFirstSentryEnvelopeRequest, | ||
| shouldSkipTracingTest, | ||
| } from '../../../../utils/helpers'; | ||
|
|
||
| const META_TAG_TRACE_ID = '12345678901234567890123456789012'; | ||
| const META_TAG_PARENT_SPAN_ID = '1234567890123456'; | ||
| const META_TAG_BAGGAGE = | ||
| 'sentry-trace_id=12345678901234567890123456789012,sentry-sample_rate=0.2,sentry-sampled=true,sentry-transaction=my-transaction,sentry-public_key=public,sentry-release=1.0.0,sentry-environment=prod,sentry-sample_rand=0.42'; | ||
|
|
||
| sentryTest( | ||
| 'create a new trace for a navigation after the server timing headers', | ||
| async ({ getLocalTestUrl, page, enableConsole }) => { | ||
| if (shouldSkipTracingTest()) { | ||
| sentryTest.skip(); | ||
| } | ||
|
|
||
| enableConsole(); | ||
|
|
||
| const url = await getLocalTestUrl({ | ||
| testDir: __dirname, | ||
| responseHeaders: { | ||
| 'Server-Timing': `sentry-trace;desc=${META_TAG_TRACE_ID}-${META_TAG_PARENT_SPAN_ID}-1, baggage;desc="${META_TAG_BAGGAGE}"`, | ||
| }, | ||
| }); | ||
|
|
||
| const [pageloadEvent, pageloadTraceHeader] = await getFirstSentryEnvelopeRequest<EventAndTraceHeader>( | ||
| page, | ||
| url, | ||
| eventAndTraceHeaderRequestParser, | ||
| ); | ||
| const [navigationEvent, navigationTraceHeader] = await getFirstSentryEnvelopeRequest<EventAndTraceHeader>( | ||
| page, | ||
| `${url}#foo`, | ||
| eventAndTraceHeaderRequestParser, | ||
| ); | ||
|
|
||
| const pageloadTraceContext = pageloadEvent.contexts?.trace; | ||
| const navigationTraceContext = navigationEvent.contexts?.trace; | ||
|
|
||
| expect(pageloadEvent.type).toEqual('transaction'); | ||
| expect(pageloadTraceContext).toMatchObject({ | ||
| op: 'pageload', | ||
| trace_id: META_TAG_TRACE_ID, | ||
| parent_span_id: META_TAG_PARENT_SPAN_ID, | ||
| span_id: expect.stringMatching(/^[\da-f]{16}$/), | ||
| }); | ||
|
|
||
| expect(pageloadTraceHeader).toEqual({ | ||
| environment: 'prod', | ||
| release: '1.0.0', | ||
| sample_rate: '0.2', | ||
| sampled: 'true', | ||
| transaction: 'my-transaction', | ||
| public_key: 'public', | ||
| trace_id: META_TAG_TRACE_ID, | ||
| sample_rand: '0.42', | ||
| }); | ||
|
|
||
| expect(navigationEvent.type).toEqual('transaction'); | ||
| expect(navigationTraceContext).toMatchObject({ | ||
| op: 'navigation', | ||
| trace_id: expect.stringMatching(/^[\da-f]{32}$/), | ||
| span_id: expect.stringMatching(/^[\da-f]{16}$/), | ||
| }); | ||
| // navigation span is head of trace, so there's no parent span: | ||
| expect(navigationTraceContext).not.toHaveProperty('parent_span_id'); | ||
|
|
||
| expect(navigationTraceHeader).toEqual({ | ||
| environment: 'production', | ||
| public_key: 'public', | ||
| sample_rate: '1', | ||
| sampled: 'true', | ||
| trace_id: navigationTraceContext?.trace_id, | ||
| sample_rand: expect.any(String), | ||
| }); | ||
|
|
||
| expect(pageloadTraceContext?.trace_id).not.toEqual(navigationTraceContext?.trace_id); | ||
| expect(pageloadTraceHeader?.sample_rand).not.toEqual(navigationTraceHeader?.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
10 changes: 10 additions & 0 deletions
10
...tegration-tests/suites/tracing/trace-lifetime/tracing-without-performance-headers/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,10 @@ | ||
| import * as Sentry from '@sentry/browser'; | ||
|
|
||
| window.Sentry = Sentry; | ||
|
|
||
| Sentry.init({ | ||
| // in browser TwP means not setting tracesSampleRate but adding browserTracingIntegration, | ||
| dsn: 'https://[email protected]/1337', | ||
| integrations: [Sentry.browserTracingIntegration()], | ||
| tracePropagationTargets: ['http://sentry-test-site.example'], | ||
| }); |
9 changes: 9 additions & 0 deletions
9
...ion-tests/suites/tracing/trace-lifetime/tracing-without-performance-headers/template.html
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,9 @@ | ||
| <!DOCTYPE html> | ||
| <html> | ||
| <head> | ||
| <meta charset="utf-8" /> | ||
| </head> | ||
| <body> | ||
| <button id="errorBtn">Throw Error</button> | ||
| </body> | ||
| </html> | ||
timfish marked this conversation as resolved.
Show resolved
Hide resolved
|
||
51 changes: 51 additions & 0 deletions
51
...tegration-tests/suites/tracing/trace-lifetime/tracing-without-performance-headers/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,51 @@ | ||
| import { expect } from '@playwright/test'; | ||
| import { sentryTest } from '../../../../utils/fixtures'; | ||
| import type { EventAndTraceHeader } from '../../../../utils/helpers'; | ||
| import { | ||
| eventAndTraceHeaderRequestParser, | ||
| getFirstSentryEnvelopeRequest, | ||
| shouldSkipTracingTest, | ||
| } from '../../../../utils/helpers'; | ||
|
|
||
| const META_TAG_TRACE_ID = '12345678901234567890123456789012'; | ||
| const META_TAG_PARENT_SPAN_ID = '1234567890123456'; | ||
| const META_TAG_BAGGAGE = | ||
| 'sentry-trace_id=12345678901234567890123456789012,sentry-public_key=public,sentry-release=1.0.0,sentry-environment=prod,sentry-sample_rand=0.42'; | ||
|
|
||
| sentryTest('error on initial page has traceId from server timing headers', async ({ getLocalTestUrl, page }) => { | ||
| if (shouldSkipTracingTest()) { | ||
| sentryTest.skip(); | ||
| } | ||
|
|
||
| const url = await getLocalTestUrl({ | ||
| testDir: __dirname, | ||
| responseHeaders: { | ||
| 'Server-Timing': `sentry-trace;desc=${META_TAG_TRACE_ID}-${META_TAG_PARENT_SPAN_ID}, baggage;desc="${META_TAG_BAGGAGE}"`, | ||
| }, | ||
| }); | ||
| await page.goto(url); | ||
|
|
||
| const errorEventPromise = getFirstSentryEnvelopeRequest<EventAndTraceHeader>( | ||
| page, | ||
| undefined, | ||
| eventAndTraceHeaderRequestParser, | ||
| ); | ||
|
|
||
| await page.locator('#errorBtn').click(); | ||
| const [errorEvent, errorTraceHeader] = await errorEventPromise; | ||
|
|
||
| expect(errorEvent.type).toEqual(undefined); | ||
| expect(errorEvent.contexts?.trace).toEqual({ | ||
| trace_id: META_TAG_TRACE_ID, | ||
| parent_span_id: META_TAG_PARENT_SPAN_ID, | ||
| span_id: expect.stringMatching(/^[\da-f]{16}$/), | ||
| }); | ||
|
|
||
| expect(errorTraceHeader).toEqual({ | ||
| environment: 'prod', | ||
| public_key: 'public', | ||
| release: '1.0.0', | ||
| trace_id: META_TAG_TRACE_ID, | ||
| sample_rand: '0.42', | ||
| }); | ||
| }); |
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.
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.
Cursor pointed out that the type/logic was wrong in this expection...