|
| 1 | +import { createTestServer } from '@sentry-internal/test-utils'; |
| 2 | +import { afterAll, describe, expect } from 'vitest'; |
| 3 | +import { cleanupChildProcesses, createEsmAndCjsTests } from '../../../../utils/runner'; |
| 4 | +import { SENTRY_OP } from '@sentry/conventions/attributes'; |
| 5 | + |
| 6 | +describe('ignoring an HTTP client child of a continued server segment (streaming)', () => { |
| 7 | + afterAll(() => { |
| 8 | + cleanupChildProcesses(); |
| 9 | + }); |
| 10 | + |
| 11 | + createEsmAndCjsTests(__dirname, 'server.mjs', 'instrument.mjs', (createRunner, test) => { |
| 12 | + const testPropagation = async (path: string): Promise<void> => { |
| 13 | + const [SERVER_URL, closeTestServer] = await createTestServer() |
| 14 | + .get('/outgoing', headers => { |
| 15 | + expect |
| 16 | + .soft(headers['sentry-trace']) |
| 17 | + .toEqual(expect.stringMatching(/^12345678901234567890123456789012-[\da-f]{16}-1$/)); |
| 18 | + |
| 19 | + expect(headers['baggage']).toBe( |
| 20 | + 'sentry-trace_id=12345678901234567890123456789012,sentry-sample_rate=1,sentry-sampled=true,sentry-public_key=public,sentry-sample_rand=0.5', |
| 21 | + ); |
| 22 | + }) |
| 23 | + .start(); |
| 24 | + |
| 25 | + const runner = createRunner() |
| 26 | + .withEnv({ SERVER_URL }) |
| 27 | + .unignore('client_report') |
| 28 | + .expect({ |
| 29 | + client_report: { |
| 30 | + discarded_events: [{ category: 'span', quantity: 1, reason: 'ignored' }], |
| 31 | + }, |
| 32 | + }) |
| 33 | + .expect({ |
| 34 | + span: container => { |
| 35 | + const httpServerSpan = container.items.find(item => item.attributes[SENTRY_OP]?.value === 'http.server'); |
| 36 | + |
| 37 | + expect(httpServerSpan?.is_segment).toBe(true); |
| 38 | + expect(httpServerSpan?.trace_id).toBe('12345678901234567890123456789012'); |
| 39 | + |
| 40 | + expect(container.items.some(item => item.attributes[SENTRY_OP]?.value === 'http.client')).toBe(false); |
| 41 | + }, |
| 42 | + }) |
| 43 | + .start(); |
| 44 | + |
| 45 | + try { |
| 46 | + const response = await runner.makeRequest<{ status: string }>('get', path, { |
| 47 | + headers: { |
| 48 | + 'sentry-trace': '12345678901234567890123456789012-1234567890123456-1', |
| 49 | + baggage: |
| 50 | + 'sentry-trace_id=12345678901234567890123456789012,sentry-sample_rate=1,sentry-sampled=true,sentry-public_key=public,sentry-sample_rand=0.5', |
| 51 | + }, |
| 52 | + }); |
| 53 | + |
| 54 | + expect(response?.status).toBe('ok'); |
| 55 | + await runner.completed(); |
| 56 | + } finally { |
| 57 | + closeTestServer(); |
| 58 | + } |
| 59 | + }; |
| 60 | + |
| 61 | + test('preserves the positive sampling decision on the outgoing fetch request', () => |
| 62 | + testPropagation('/ignored-http-client')); |
| 63 | + |
| 64 | + test('preserves the positive sampling decision on the outgoing node:http request', () => |
| 65 | + testPropagation('/ignored-node-http-client')); |
| 66 | + }); |
| 67 | +}); |
0 commit comments