|
| 1 | +import { expect } from '@playwright/test'; |
| 2 | +import type { SpanEnvelope } from '@sentry/core'; |
| 3 | +import { sentryTest } from '../../../../utils/fixtures'; |
| 4 | +import { |
| 5 | + getMultipleSentryEnvelopeRequests, |
| 6 | + properFullEnvelopeRequestParser, |
| 7 | + shouldSkipTracingTest, |
| 8 | +} from '../../../../utils/helpers'; |
| 9 | + |
| 10 | +const TRACE_ID = '12345678901234567890123456789012'; |
| 11 | +const OUTGOING_REQUEST_URL = 'http://sentry-test-external.io'; |
| 12 | + |
| 13 | +sentryTest( |
| 14 | + 'omits the trace envelope header when a standalone span continues a trace without baggage', |
| 15 | + async ({ getLocalTestUrl, page }) => { |
| 16 | + sentryTest.skip(shouldSkipTracingTest()); |
| 17 | + |
| 18 | + const url = await getLocalTestUrl({ testDir: __dirname }); |
| 19 | + await page.route(OUTGOING_REQUEST_URL, route => route.fulfill({ status: 200, body: 'ok' })); |
| 20 | + const outgoingRequestPromise = page.waitForRequest(OUTGOING_REQUEST_URL); |
| 21 | + |
| 22 | + const [spanEnvelope] = await getMultipleSentryEnvelopeRequests<SpanEnvelope>( |
| 23 | + page, |
| 24 | + 1, |
| 25 | + { url, envelopeType: 'span' }, |
| 26 | + properFullEnvelopeRequestParser, |
| 27 | + ); |
| 28 | + const outgoingRequest = await outgoingRequestPromise; |
| 29 | + |
| 30 | + expect(spanEnvelope[0]).toEqual({ |
| 31 | + sent_at: expect.any(String), |
| 32 | + }); |
| 33 | + |
| 34 | + // To be clear: This is _expected_ behavior, not a bug. |
| 35 | + // SDKs must assume that an incoming `sentry-trace` but no `baggage` meta tag means that the |
| 36 | + // trace was started from an SDK that's not yet compatible with the DSC or baggage propagation. |
| 37 | + // The test demonstrates that the SDK as expected continues the trace but does not send a `trace` |
| 38 | + // header, nor a baggage header. |
| 39 | + expect(spanEnvelope[0].trace).toBeUndefined(); |
| 40 | + |
| 41 | + expect(spanEnvelope[1]).toHaveLength(1); |
| 42 | + expect(spanEnvelope[1][0][1].trace_id).toBe(TRACE_ID); |
| 43 | + |
| 44 | + const outgoingRequestHeaders = outgoingRequest.headers(); |
| 45 | + expect(outgoingRequestHeaders['sentry-trace']).toMatch(new RegExp(`^${TRACE_ID}-[\\da-f]{16}-1$`)); |
| 46 | + expect(outgoingRequestHeaders['baggage']).toBeUndefined(); |
| 47 | + }, |
| 48 | +); |
0 commit comments