-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(V7/browser-integration-tests): Check for
sentry-trace
header i…
…n TwP (#11555)
- Loading branch information
Showing
6 changed files
with
73 additions
and
3 deletions.
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
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 |
---|---|---|
|
@@ -5,6 +5,8 @@ window.Sentry = Sentry; | |
Sentry.init({ | ||
dsn: 'https://[email protected]/1337', | ||
// disable pageload transaction | ||
integrations: [Sentry.BrowserTracing({ tracingOrigins: ['http://example.com'], startTransactionOnPageLoad: false })], | ||
integrations: [ | ||
new Sentry.BrowserTracing({ tracingOrigins: ['http://example.com'], startTransactionOnPageLoad: false }), | ||
], | ||
tracesSampleRate: 1, | ||
}); |
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
9 changes: 9 additions & 0 deletions
9
...ckages/browser-integration-tests/suites/tracing/request/fetch-with-no-sample-rate/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,9 @@ | ||
import * as Sentry from '@sentry/browser'; | ||
|
||
window.Sentry = Sentry; | ||
|
||
Sentry.init({ | ||
dsn: 'https://[email protected]/1337', | ||
// disable pageload transaction | ||
integrations: [new Sentry.BrowserTracing({ tracePropagationTargets: ['http://example.com'] })], | ||
}); |
1 change: 1 addition & 0 deletions
1
...ges/browser-integration-tests/suites/tracing/request/fetch-with-no-sample-rate/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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
fetch('http://example.com/0').then(fetch('http://example.com/1').then(fetch('http://example.com/2'))); |
46 changes: 46 additions & 0 deletions
46
...ckages/browser-integration-tests/suites/tracing/request/fetch-with-no-sample-rate/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,46 @@ | ||
import { expect } from '@playwright/test'; | ||
|
||
import { sentryTest } from '../../../../utils/fixtures'; | ||
import { envelopeUrlRegex, shouldSkipTracingTest } from '../../../../utils/helpers'; | ||
|
||
sentryTest( | ||
'should not create span for fetch requests with no active span but should attach sentry-trace header if no sample rate is set', | ||
async ({ getLocalTestPath, page }) => { | ||
if (shouldSkipTracingTest()) { | ||
sentryTest.skip(); | ||
} | ||
|
||
const url = await getLocalTestPath({ testDir: __dirname }); | ||
|
||
let requestCount = 0; | ||
const sentryTraceHeaders: string[] = []; | ||
page.on('request', request => { | ||
const sentryTraceHeader = request.headers()['sentry-trace']; | ||
if (sentryTraceHeader) { | ||
sentryTraceHeaders.push(sentryTraceHeader); | ||
} | ||
expect(envelopeUrlRegex.test(request.url())).toBe(false); | ||
requestCount++; | ||
}); | ||
|
||
await page.goto(url); | ||
|
||
// Here are the requests that should exist: | ||
// 1. HTML page | ||
// 2. Init JS bundle | ||
// 3. Subject JS bundle | ||
// 4 [OPTIONAl] CDN JS bundle | ||
// and then 3 fetch requests | ||
if (process.env.PW_BUNDLE && process.env.PW_BUNDLE.startsWith('bundle_')) { | ||
expect(requestCount).toBe(7); | ||
} else { | ||
expect(requestCount).toBe(6); | ||
} | ||
|
||
// TODO: This is incorrect behavior. Even if `tracesSampleRate` is not set (which in browser | ||
// realistically is the only way to truly get "Tracing without performance"), we should still | ||
// attach the `sentry-trace` header to the fetch requests. | ||
// Right now, we don't do this, as this test demonstrates. | ||
expect(sentryTraceHeaders).toHaveLength(0); | ||
}, | ||
); |