|
| 1 | +import { expect } from '@playwright/test'; |
| 2 | + |
| 3 | +import { sentryTest } from '../../../../utils/fixtures'; |
| 4 | +import { envelopeUrlRegex, shouldSkipTracingTest } from '../../../../utils/helpers'; |
| 5 | + |
| 6 | +sentryTest( |
| 7 | + 'should not create span for fetch requests with no active span but should attach sentry-trace header if no sample rate is set', |
| 8 | + async ({ getLocalTestPath, page }) => { |
| 9 | + if (shouldSkipTracingTest()) { |
| 10 | + sentryTest.skip(); |
| 11 | + } |
| 12 | + |
| 13 | + const url = await getLocalTestPath({ testDir: __dirname }); |
| 14 | + |
| 15 | + let requestCount = 0; |
| 16 | + const sentryTraceHeaders: string[] = []; |
| 17 | + page.on('request', request => { |
| 18 | + const sentryTraceHeader = request.headers()['sentry-trace']; |
| 19 | + if (sentryTraceHeader) { |
| 20 | + sentryTraceHeaders.push(sentryTraceHeader); |
| 21 | + } |
| 22 | + expect(envelopeUrlRegex.test(request.url())).toBe(false); |
| 23 | + requestCount++; |
| 24 | + }); |
| 25 | + |
| 26 | + await page.goto(url); |
| 27 | + |
| 28 | + // Here are the requests that should exist: |
| 29 | + // 1. HTML page |
| 30 | + // 2. Init JS bundle |
| 31 | + // 3. Subject JS bundle |
| 32 | + // 4 [OPTIONAl] CDN JS bundle |
| 33 | + // and then 3 fetch requests |
| 34 | + if (process.env.PW_BUNDLE && process.env.PW_BUNDLE.startsWith('bundle_')) { |
| 35 | + expect(requestCount).toBe(7); |
| 36 | + } else { |
| 37 | + expect(requestCount).toBe(6); |
| 38 | + } |
| 39 | + |
| 40 | + // TODO: This is incorrect behavior. Even if `tracesSampleRate` is not set (which in browser |
| 41 | + // realistically is the only way to truly get "Tracing without performance"), we should still |
| 42 | + // attach the `sentry-trace` header to the fetch requests. |
| 43 | + // Right now, we don't do this, as this test demonstrates. |
| 44 | + expect(sentryTraceHeaders).toHaveLength(0); |
| 45 | + }, |
| 46 | +); |
0 commit comments