|
| 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 | +sentryTest('should create a new trace if `startNewTrace` is called', async ({ getLocalTestUrl, page }) => { |
| 11 | + if (shouldSkipTracingTest()) { |
| 12 | + sentryTest.skip(); |
| 13 | + } |
| 14 | + |
| 15 | + const url = await getLocalTestUrl({ testDir: __dirname }); |
| 16 | + |
| 17 | + await page.route('http://example.com/**', route => { |
| 18 | + return route.fulfill({ |
| 19 | + status: 200, |
| 20 | + contentType: 'application/json', |
| 21 | + body: JSON.stringify({}), |
| 22 | + }); |
| 23 | + }); |
| 24 | + |
| 25 | + const [pageloadEvent, pageloadTraceHeaders] = await getFirstSentryEnvelopeRequest<EventAndTraceHeader>( |
| 26 | + page, |
| 27 | + url, |
| 28 | + eventAndTraceHeaderRequestParser, |
| 29 | + ); |
| 30 | + |
| 31 | + const pageloadTraceContext = pageloadEvent.contexts?.trace; |
| 32 | + |
| 33 | + expect(pageloadEvent.type).toEqual('transaction'); |
| 34 | + |
| 35 | + expect(pageloadTraceContext).toMatchObject({ |
| 36 | + op: 'pageload', |
| 37 | + trace_id: expect.stringMatching(/^[0-9a-f]{32}$/), |
| 38 | + span_id: expect.stringMatching(/^[0-9a-f]{16}$/), |
| 39 | + }); |
| 40 | + expect(pageloadTraceContext).not.toHaveProperty('parent_span_id'); |
| 41 | + |
| 42 | + expect(pageloadTraceHeaders).toEqual({ |
| 43 | + environment: 'production', |
| 44 | + public_key: 'public', |
| 45 | + sample_rate: '1', |
| 46 | + sampled: 'true', |
| 47 | + trace_id: pageloadTraceContext?.trace_id, |
| 48 | + }); |
| 49 | + |
| 50 | + const customTransactionPromise = getFirstSentryEnvelopeRequest<EventAndTraceHeader>( |
| 51 | + page, |
| 52 | + undefined, |
| 53 | + eventAndTraceHeaderRequestParser, |
| 54 | + ); |
| 55 | + |
| 56 | + await page.locator('#fetchBtn').click(); |
| 57 | + |
| 58 | + const [customTransactionEvent, customTransactionTraceHeaders] = await customTransactionPromise; |
| 59 | + |
| 60 | + expect(customTransactionEvent.type).toEqual('transaction'); |
| 61 | + expect(customTransactionEvent.transaction).toEqual('fetch click'); |
| 62 | + |
| 63 | + const customTransactionTraceContext = customTransactionEvent.contexts?.trace; |
| 64 | + expect(customTransactionTraceContext).toMatchObject({ |
| 65 | + op: 'ui.interaction.click', |
| 66 | + trace_id: expect.stringMatching(/^[0-9a-f]{32}$/), |
| 67 | + span_id: expect.stringMatching(/^[0-9a-f]{16}$/), |
| 68 | + }); |
| 69 | + |
| 70 | + expect(customTransactionTraceHeaders).toEqual({ |
| 71 | + environment: 'production', |
| 72 | + public_key: 'public', |
| 73 | + sample_rate: '1', |
| 74 | + sampled: 'true', |
| 75 | + trace_id: customTransactionTraceContext?.trace_id, |
| 76 | + transaction: 'fetch click', |
| 77 | + }); |
| 78 | + |
| 79 | + expect(customTransactionTraceContext?.trace_id).not.toEqual(pageloadTraceContext?.trace_id); |
| 80 | +}); |
0 commit comments