|
| 1 | +import { describe, expect } from 'vitest'; |
| 2 | +import { createEsmAndCjsTests } from '../../../../utils/runner'; |
| 3 | +import { createTestServer } from '../../../../utils/server'; |
| 4 | + |
| 5 | +describe('outgoing traceparent', () => { |
| 6 | + createEsmAndCjsTests(__dirname, 'scenario-fetch.mjs', 'instrument.mjs', (createRunner, test) => { |
| 7 | + test('outgoing fetch requests should get traceparent headers', async () => { |
| 8 | + expect.assertions(5); |
| 9 | + |
| 10 | + const [SERVER_URL, closeTestServer] = await createTestServer() |
| 11 | + .get('/api/v1', headers => { |
| 12 | + expect(headers['baggage']).toEqual(expect.any(String)); |
| 13 | + expect(headers['sentry-trace']).toEqual(expect.stringMatching(/^([a-f\d]{32})-([a-f\d]{16})-1$/)); |
| 14 | + expect(headers['sentry-trace']).not.toEqual('00000000000000000000000000000000-0000000000000000-0'); |
| 15 | + expect(headers['traceparent']).toEqual(expect.stringMatching(/^00-([a-f\d]{32})-([a-f\d]{16})-01$/)); |
| 16 | + }) |
| 17 | + .start(); |
| 18 | + |
| 19 | + await createRunner() |
| 20 | + .withEnv({ SERVER_URL }) |
| 21 | + .expect({ |
| 22 | + transaction: { |
| 23 | + // we're not too concerned with the actual transaction here since this is tested elsewhere |
| 24 | + }, |
| 25 | + }) |
| 26 | + .start() |
| 27 | + .completed(); |
| 28 | + closeTestServer(); |
| 29 | + }); |
| 30 | + }); |
| 31 | + |
| 32 | + createEsmAndCjsTests(__dirname, 'scenario-http.mjs', 'instrument.mjs', (createRunner, test) => { |
| 33 | + test('outgoing http requests should get traceparent headers', async () => { |
| 34 | + expect.assertions(5); |
| 35 | + |
| 36 | + const [SERVER_URL, closeTestServer] = await createTestServer() |
| 37 | + .get('/api/v1', headers => { |
| 38 | + expect(headers['baggage']).toEqual(expect.any(String)); |
| 39 | + expect(headers['sentry-trace']).toEqual(expect.stringMatching(/^([a-f\d]{32})-([a-f\d]{16})-1$/)); |
| 40 | + expect(headers['sentry-trace']).not.toEqual('00000000000000000000000000000000-0000000000000000-0'); |
| 41 | + expect(headers['traceparent']).toEqual(expect.stringMatching(/^00-([a-f\d]{32})-([a-f\d]{16})-01$/)); |
| 42 | + }) |
| 43 | + .start(); |
| 44 | + |
| 45 | + await createRunner() |
| 46 | + .withEnv({ SERVER_URL }) |
| 47 | + .expect({ |
| 48 | + transaction: { |
| 49 | + // we're not too concerned with the actual transaction here since this is tested elsewhere |
| 50 | + }, |
| 51 | + }) |
| 52 | + .start() |
| 53 | + .completed(); |
| 54 | + closeTestServer(); |
| 55 | + }); |
| 56 | + }); |
| 57 | +}); |
0 commit comments