|
| 1 | +import { expect } from '@playwright/test'; |
| 2 | +import type { ClientReport } from '@sentry/core'; |
| 3 | +import { sentryTest } from '../../../../utils/fixtures'; |
| 4 | +import { |
| 5 | + envelopeRequestParser, |
| 6 | + hidePage, |
| 7 | + shouldSkipTracingTest, |
| 8 | + waitForClientReportRequest, |
| 9 | + waitForTracingHeadersOnUrl, |
| 10 | +} from '../../../../utils/helpers'; |
| 11 | +import { getSpanOp, waitForStreamedSpans } from '../../../../utils/spanUtils'; |
| 12 | + |
| 13 | +sentryTest( |
| 14 | + 'ignoring a child span preserves the positive sampling decision of a continued trace when propagating it', |
| 15 | + async ({ getLocalTestUrl, page }) => { |
| 16 | + sentryTest.skip(shouldSkipTracingTest()); |
| 17 | + |
| 18 | + const url = await getLocalTestUrl({ testDir: __dirname }); |
| 19 | + |
| 20 | + const clientReportPromise = waitForClientReportRequest(page); |
| 21 | + const tracingHeadersPromise = waitForTracingHeadersOnUrl(page, 'http://sentry-test-external.io'); |
| 22 | + const spansPromise = waitForStreamedSpans( |
| 23 | + page, |
| 24 | + spans => |
| 25 | + spans.some(span => getSpanOp(span) === 'pageload') && spans.some(span => getSpanOp(span) === 'http.client'), |
| 26 | + ); |
| 27 | + |
| 28 | + await page.goto(url); |
| 29 | + |
| 30 | + const [{ baggage, sentryTrace }, spans] = await Promise.all([tracingHeadersPromise, spansPromise]); |
| 31 | + const pageloadSpan = spans.find(span => getSpanOp(span) === 'pageload'); |
| 32 | + const httpClientSpan = spans.find(span => getSpanOp(span) === 'http.client'); |
| 33 | + |
| 34 | + expect(pageloadSpan?.is_segment).toBe(true); |
| 35 | + expect(pageloadSpan?.trace_id).toBe('12345678901234567890123456789012'); |
| 36 | + expect(httpClientSpan?.parent_span_id).toBe(pageloadSpan?.span_id); |
| 37 | + expect(sentryTrace).toBe(`${pageloadSpan?.trace_id}-${httpClientSpan?.span_id}-1`); |
| 38 | + expect(baggage).toEqual( |
| 39 | + 'sentry-trace_id=12345678901234567890123456789012,sentry-sample_rate=1,sentry-sampled=true,sentry-public_key=public,sentry-sample_rand=0.5', |
| 40 | + ); |
| 41 | + |
| 42 | + await hidePage(page); |
| 43 | + const clientReport = envelopeRequestParser<ClientReport>(await clientReportPromise); |
| 44 | + expect(clientReport.discarded_events).toEqual([{ category: 'span', quantity: 1, reason: 'ignored' }]); |
| 45 | + }, |
| 46 | +); |
0 commit comments