-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(browser-integration-tests): Add trace lifetime tests in TwP scen…
…ario (#11636) Adds a couple of tests to cover the "Tracing Without Performance" use case where no spans will be created but we nevertheless attach tracing headers to outgoing requests and attach a trace id to errors. Also, we expect these traceIds to be different/new for each subsequent navigation ref #11599
- Loading branch information
Showing
5 changed files
with
131 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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
2 changes: 1 addition & 1 deletion
2
dev-packages/browser-integration-tests/suites/tracing/trace-lifetime/subject.js
This file contains 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
...owser-integration-tests/suites/tracing/trace-lifetime/tracing-without-performance/init.js
This file contains 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://public@dsn.ingest.sentry.io/1337', | ||
integrations: [Sentry.browserTracingIntegration()], | ||
tracePropagationTargets: ['http://example.com'], | ||
}); |
15 changes: 15 additions & 0 deletions
15
...integration-tests/suites/tracing/trace-lifetime/tracing-without-performance/template.html
This file contains 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,15 @@ | ||
<!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"/> | ||
</head> | ||
<body> | ||
<button id="errorBtn">Throw Error</button> | ||
<button id="fetchBtn">Fetch Request</button> | ||
<button id="xhrBtn">XHR Request</button> | ||
</body> | ||
</html> |
104 changes: 104 additions & 0 deletions
104
...owser-integration-tests/suites/tracing/trace-lifetime/tracing-without-performance/test.ts
This file contains 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,104 @@ | ||
import { expect } from '@playwright/test'; | ||
import type { Event } from '@sentry/types'; | ||
import { sentryTest } from '../../../../utils/fixtures'; | ||
import { 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'; | ||
|
||
sentryTest('error has new traceId after navigation', async ({ getLocalTestPath, page }) => { | ||
if (shouldSkipTracingTest()) { | ||
sentryTest.skip(); | ||
} | ||
|
||
const url = await getLocalTestPath({ testDir: __dirname }); | ||
await page.goto(url); | ||
|
||
const errorEventPromise = getFirstSentryEnvelopeRequest<Event>(page); | ||
await page.locator('#errorBtn').click(); | ||
const errorEvent = await errorEventPromise; | ||
|
||
expect(errorEvent.contexts?.trace).toEqual({ | ||
trace_id: META_TAG_TRACE_ID, | ||
parent_span_id: META_TAG_PARENT_SPAN_ID, | ||
span_id: expect.stringMatching(/^[0-9a-f]{16}$/), | ||
}); | ||
|
||
const errorEventPromise2 = getFirstSentryEnvelopeRequest<Event>(page, `${url}#navigation`); | ||
await page.locator('#errorBtn').click(); | ||
const errorEvent2 = await errorEventPromise2; | ||
|
||
expect(errorEvent2.contexts?.trace).toEqual({ | ||
trace_id: expect.stringMatching(/^[0-9a-f]{32}$/), | ||
span_id: expect.stringMatching(/^[0-9a-f]{16}$/), | ||
}); | ||
expect(errorEvent2.contexts?.trace?.trace_id).not.toBe(META_TAG_TRACE_ID); | ||
}); | ||
|
||
sentryTest('outgoing fetch requests have new traceId after navigation', async ({ getLocalTestPath, page }) => { | ||
if (shouldSkipTracingTest()) { | ||
sentryTest.skip(); | ||
} | ||
|
||
const url = await getLocalTestPath({ testDir: __dirname }); | ||
await page.goto(url); | ||
|
||
const requestPromise = page.waitForRequest('http://example.com/*'); | ||
await page.locator('#fetchBtn').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://example.com/*'); | ||
await page.locator('#fetchBtn').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}`); | ||
}); | ||
|
||
sentryTest('outgoing XHR requests have new traceId after navigation', async ({ getLocalTestPath, page }) => { | ||
if (shouldSkipTracingTest()) { | ||
sentryTest.skip(); | ||
} | ||
|
||
const url = await getLocalTestPath({ testDir: __dirname }); | ||
await page.goto(url); | ||
|
||
const requestPromise = page.waitForRequest('http://example.com/*'); | ||
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://example.com/*'); | ||
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}`); | ||
}); |