-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
fix(browser): Ensure propagated parentSpanId
stays consistent during trace in TwP mode
#17526
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
Merged
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
3 changes: 2 additions & 1 deletion
3
.../suites/tracing/request/fetch-tracing-without-performance-propagateTraceparent/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 |
---|---|---|
@@ -1 +1,2 @@ | ||
fetch('http://sentry-test-site.example/0').then(); | ||
fetch('http://sentry-test-site.example/0'); | ||
fetch('http://sentry-test-site.example/1'); |
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
11 changes: 11 additions & 0 deletions
11
...ts/suites/tracing/trace-lifetime/tracing-without-performance-propagateTraceparent/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,11 @@ | ||
import * as Sentry from '@sentry/browser'; | ||
|
||
window.Sentry = Sentry; | ||
|
||
Sentry.init({ | ||
// in browser TwP means not setting tracesSampleRate but adding browserTracingIntegration, | ||
dsn: 'https://public@dsn.ingest.sentry.io/1337', | ||
integrations: [Sentry.browserTracingIntegration()], | ||
tracePropagationTargets: ['http://sentry-test-site.example'], | ||
propagateTraceparent: true, | ||
}); |
17 changes: 17 additions & 0 deletions
17
...tes/tracing/trace-lifetime/tracing-without-performance-propagateTraceparent/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,17 @@ | ||
<!doctype html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8" /> | ||
<!-- Purposefully emitting the `sampled` flag in the sentry-trace tag --> | ||
<meta name="sentry-trace" content="12345678901234567890123456789012-1234567890123456" /> | ||
<meta | ||
name="baggage" | ||
content="sentry-trace_id=12345678901234567890123456789012,sentry-public_key=public,sentry-release=1.0.0,sentry-environment=prod,sentry-sample_rand=0.42" | ||
/> | ||
</head> | ||
<body> | ||
<button id="errorBtn">Throw Error</button> | ||
<button id="fetchBtn">Fetch Request</button> | ||
<button id="xhrBtn">XHR Request</button> | ||
</body> | ||
</html> |
130 changes: 130 additions & 0 deletions
130
...ts/suites/tracing/trace-lifetime/tracing-without-performance-propagateTraceparent/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,130 @@ | ||
import { expect } from '@playwright/test'; | ||
import { extractTraceparentData } from '@sentry/core'; | ||
import { sentryTest } from '../../../../utils/fixtures'; | ||
import { 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( | ||
'outgoing fetch requests have new traceId after navigation (with propagateTraceparent)', | ||
async ({ getLocalTestUrl, page }) => { | ||
if (shouldSkipTracingTest()) { | ||
sentryTest.skip(); | ||
} | ||
|
||
const url = await getLocalTestUrl({ testDir: __dirname }); | ||
|
||
await page.route('http://sentry-test-site.example/**', route => { | ||
return route.fulfill({ | ||
status: 200, | ||
contentType: 'application/json', | ||
body: JSON.stringify({}), | ||
}); | ||
}); | ||
|
||
await page.goto(url); | ||
|
||
const requestPromise = page.waitForRequest('http://sentry-test-site.example/*'); | ||
await page.locator('#fetchBtn').click(); | ||
const request = await requestPromise; | ||
const headers = request.headers(); | ||
|
||
const sentryTraceParentData = extractTraceparentData(headers['sentry-trace']); | ||
// sampling decision is deferred because TwP means we didn't sample any span | ||
expect(sentryTraceParentData).toEqual({ | ||
traceId: META_TAG_TRACE_ID, | ||
parentSpanId: expect.stringMatching(/^[0-9a-f]{16}$/), | ||
parentSampled: undefined, | ||
}); | ||
expect(headers['baggage']).toBe(META_TAG_BAGGAGE); | ||
// but traceparent propagates a negative sampling decision because it has no concept of deferred sampling | ||
expect(headers['traceparent']).toBe( | ||
`00-${sentryTraceParentData?.traceId}-${sentryTraceParentData?.parentSpanId}-00`, | ||
); | ||
|
||
const requestPromise2 = page.waitForRequest('http://sentry-test-site.example/*'); | ||
await page.locator('#fetchBtn').click(); | ||
const request2 = await requestPromise2; | ||
const headers2 = request2.headers(); | ||
|
||
const sentryTraceParentData2 = extractTraceparentData(headers2['sentry-trace']); | ||
expect(sentryTraceParentData2).toEqual(sentryTraceParentData); | ||
|
||
await page.goto(`${url}#navigation`); | ||
|
||
const requestPromise3 = page.waitForRequest('http://sentry-test-site.example/*'); | ||
await page.locator('#fetchBtn').click(); | ||
const request3 = await requestPromise3; | ||
const headers3 = request3.headers(); | ||
|
||
const sentryTraceParentData3 = extractTraceparentData(headers3['sentry-trace']); | ||
// sampling decision is deferred because TwP means we didn't sample any span | ||
expect(sentryTraceParentData3).toEqual({ | ||
traceId: expect.not.stringContaining(sentryTraceParentData!.traceId!), | ||
parentSpanId: expect.not.stringContaining(sentryTraceParentData!.parentSpanId!), | ||
parentSampled: undefined, | ||
}); | ||
|
||
expect(headers3['baggage']).toMatch( | ||
/sentry-environment=production,sentry-public_key=public,sentry-trace_id=[0-9a-f]{32}/, | ||
); | ||
expect(headers3['baggage']).not.toContain(`sentry-trace_id=${META_TAG_TRACE_ID}`); | ||
// but traceparent propagates a negative sampling decision because it has no concept of deferred sampling | ||
expect(headers3['traceparent']).toBe( | ||
`00-${sentryTraceParentData3!.traceId}-${sentryTraceParentData3!.parentSpanId}-00`, | ||
); | ||
|
||
const requestPromise4 = page.waitForRequest('http://sentry-test-site.example/*'); | ||
await page.locator('#fetchBtn').click(); | ||
const request4 = await requestPromise4; | ||
const headers4 = request4.headers(); | ||
|
||
const sentryTraceParentData4 = extractTraceparentData(headers4['sentry-trace']); | ||
expect(sentryTraceParentData4).toEqual(sentryTraceParentData3); | ||
}, | ||
); | ||
|
||
sentryTest('outgoing XHR requests have new traceId after navigation', async ({ getLocalTestUrl, page }) => { | ||
if (shouldSkipTracingTest()) { | ||
sentryTest.skip(); | ||
} | ||
|
||
const url = await getLocalTestUrl({ testDir: __dirname }); | ||
|
||
await page.route('http://sentry-test-site.example/**', route => { | ||
return route.fulfill({ | ||
status: 200, | ||
contentType: 'application/json', | ||
body: JSON.stringify({}), | ||
}); | ||
}); | ||
|
||
await page.goto(url); | ||
|
||
const requestPromise = page.waitForRequest('http://sentry-test-site.example/*'); | ||
await page.locator('#xhrBtn').click(); | ||
const request = await requestPromise; | ||
const headers = request.headers(); | ||
|
||
// sampling decision is deferred because TwP means we didn't sample any span | ||
expect(headers['sentry-trace']).toMatch(new RegExp(`^${META_TAG_TRACE_ID}-[0-9a-f]{16}$`)); | ||
expect(headers['baggage']).toBe(META_TAG_BAGGAGE); | ||
|
||
await page.goto(`${url}#navigation`); | ||
|
||
const requestPromise2 = page.waitForRequest('http://sentry-test-site.example/*'); | ||
await page.locator('#xhrBtn').click(); | ||
const request2 = await requestPromise2; | ||
const headers2 = request2.headers(); | ||
|
||
// sampling decision is deferred because TwP means we didn't sample any span | ||
expect(headers2['sentry-trace']).toMatch(/^[0-9a-f]{32}-[0-9a-f]{16}$/); | ||
expect(headers2['baggage']).not.toBe(`${META_TAG_TRACE_ID}-${META_TAG_PARENT_SPAN_ID}`); | ||
expect(headers2['baggage']).toMatch( | ||
/sentry-environment=production,sentry-public_key=public,sentry-trace_id=[0-9a-f]{32}/, | ||
); | ||
expect(headers2['baggage']).not.toContain(`sentry-trace_id=${META_TAG_TRACE_ID}`); | ||
}); |
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.
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.
This test confused me a bit, so I just added some comments. No change for consistent trace sampling!