|
| 1 | +import { expect } from '@playwright/test'; |
| 2 | +import { sentryTest } from '../../../../utils/fixtures'; |
| 3 | +import type { EventAndTraceHeader } from '../../../../utils/helpers'; |
| 4 | +import { |
| 5 | + eventAndTraceHeaderRequestParser, |
| 6 | + getFirstSentryEnvelopeRequest, |
| 7 | + shouldSkipTracingTest, |
| 8 | +} from '../../../../utils/helpers'; |
| 9 | + |
| 10 | +const META_TAG_TRACE_ID = '12345678901234567890123456789012'; |
| 11 | +const META_TAG_PARENT_SPAN_ID = '1234567890123456'; |
| 12 | +const META_TAG_BAGGAGE = |
| 13 | + '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'; |
| 14 | + |
| 15 | +sentryTest( |
| 16 | + 'create a new trace for a navigation after the server timing headers', |
| 17 | + async ({ getLocalTestUrl, page, enableConsole }) => { |
| 18 | + if (shouldSkipTracingTest()) { |
| 19 | + sentryTest.skip(); |
| 20 | + } |
| 21 | + |
| 22 | + enableConsole(); |
| 23 | + |
| 24 | + const url = await getLocalTestUrl({ |
| 25 | + testDir: __dirname, |
| 26 | + responseHeaders: { |
| 27 | + 'Server-Timing': `sentry-trace;desc=${META_TAG_TRACE_ID}-${META_TAG_PARENT_SPAN_ID}, baggage;desc="${META_TAG_BAGGAGE}"`, |
| 28 | + }, |
| 29 | + }); |
| 30 | + |
| 31 | + const [pageloadEvent, pageloadTraceHeader] = await getFirstSentryEnvelopeRequest<EventAndTraceHeader>( |
| 32 | + page, |
| 33 | + url, |
| 34 | + eventAndTraceHeaderRequestParser, |
| 35 | + ); |
| 36 | + const [navigationEvent, navigationTraceHeader] = await getFirstSentryEnvelopeRequest<EventAndTraceHeader>( |
| 37 | + page, |
| 38 | + `${url}#foo`, |
| 39 | + eventAndTraceHeaderRequestParser, |
| 40 | + ); |
| 41 | + |
| 42 | + const pageloadTraceContext = pageloadEvent.contexts?.trace; |
| 43 | + const navigationTraceContext = navigationEvent.contexts?.trace; |
| 44 | + |
| 45 | + expect(pageloadEvent.type).toEqual('transaction'); |
| 46 | + expect(pageloadTraceContext).toMatchObject({ |
| 47 | + op: 'pageload', |
| 48 | + trace_id: META_TAG_TRACE_ID, |
| 49 | + parent_span_id: META_TAG_PARENT_SPAN_ID, |
| 50 | + span_id: expect.stringMatching(/^[\da-f]{16}$/), |
| 51 | + }); |
| 52 | + |
| 53 | + expect(pageloadTraceHeader).toEqual({ |
| 54 | + environment: 'prod', |
| 55 | + release: '1.0.0', |
| 56 | + sample_rate: '0.2', |
| 57 | + sampled: 'true', |
| 58 | + transaction: 'my-transaction', |
| 59 | + public_key: 'public', |
| 60 | + trace_id: META_TAG_TRACE_ID, |
| 61 | + sample_rand: '0.42', |
| 62 | + }); |
| 63 | + |
| 64 | + expect(navigationEvent.type).toEqual('transaction'); |
| 65 | + expect(navigationTraceContext).toMatchObject({ |
| 66 | + op: 'navigation', |
| 67 | + trace_id: expect.stringMatching(/^[\da-f]{32}$/), |
| 68 | + span_id: expect.stringMatching(/^[\da-f]{16}$/), |
| 69 | + }); |
| 70 | + // navigation span is head of trace, so there's no parent span: |
| 71 | + expect(navigationTraceContext?.trace_id).not.toHaveProperty('parent_span_id'); |
| 72 | + |
| 73 | + expect(navigationTraceHeader).toEqual({ |
| 74 | + environment: 'production', |
| 75 | + public_key: 'public', |
| 76 | + sample_rate: '1', |
| 77 | + sampled: 'true', |
| 78 | + trace_id: navigationTraceContext?.trace_id, |
| 79 | + sample_rand: expect.any(String), |
| 80 | + }); |
| 81 | + |
| 82 | + expect(pageloadTraceContext?.trace_id).not.toEqual(navigationTraceContext?.trace_id); |
| 83 | + expect(pageloadTraceHeader?.sample_rand).not.toEqual(navigationTraceHeader?.sample_rand); |
| 84 | + }, |
| 85 | +); |
0 commit comments