|
| 1 | +import { createRunner } from '../../../utils/runner'; |
| 2 | +import { createTestServer } from '../../../utils/server'; |
| 3 | + |
| 4 | +test('adds current transaction name to baggage when the txn name is high-quality', done => { |
| 5 | + expect.assertions(5); |
| 6 | + |
| 7 | + let traceId: string | undefined; |
| 8 | + |
| 9 | + createTestServer(done) |
| 10 | + .get('/api/v0', headers => { |
| 11 | + const baggageItems = getBaggageHeaderItems(headers); |
| 12 | + traceId = baggageItems.find(item => item.startsWith('sentry-trace_id='))?.split('=')[1] as string; |
| 13 | + |
| 14 | + expect(traceId).toMatch(/^[0-9a-f]{32}$/); |
| 15 | + |
| 16 | + expect(baggageItems).toEqual([ |
| 17 | + 'sentry-environment=production', |
| 18 | + 'sentry-public_key=public', |
| 19 | + 'sentry-release=1.0', |
| 20 | + 'sentry-sample_rate=1', |
| 21 | + 'sentry-sampled=true', |
| 22 | + `sentry-trace_id=${traceId}`, |
| 23 | + ]); |
| 24 | + }) |
| 25 | + .get('/api/v1', headers => { |
| 26 | + expect(getBaggageHeaderItems(headers)).toEqual([ |
| 27 | + 'sentry-environment=production', |
| 28 | + 'sentry-public_key=public', |
| 29 | + 'sentry-release=1.0', |
| 30 | + 'sentry-sample_rate=1', |
| 31 | + 'sentry-sampled=true', |
| 32 | + `sentry-trace_id=${traceId}`, |
| 33 | + 'sentry-transaction=updated-name-1', |
| 34 | + ]); |
| 35 | + }) |
| 36 | + .get('/api/v2', headers => { |
| 37 | + expect(getBaggageHeaderItems(headers)).toEqual([ |
| 38 | + 'sentry-environment=production', |
| 39 | + 'sentry-public_key=public', |
| 40 | + 'sentry-release=1.0', |
| 41 | + 'sentry-sample_rate=1', |
| 42 | + 'sentry-sampled=true', |
| 43 | + `sentry-trace_id=${traceId}`, |
| 44 | + 'sentry-transaction=updated-name-2', |
| 45 | + ]); |
| 46 | + }) |
| 47 | + .start() |
| 48 | + .then(([SERVER_URL, closeTestServer]) => { |
| 49 | + createRunner(__dirname, 'scenario-headers.ts') |
| 50 | + .withEnv({ SERVER_URL }) |
| 51 | + .expect({ |
| 52 | + transaction: {}, |
| 53 | + }) |
| 54 | + .start(closeTestServer); |
| 55 | + }); |
| 56 | +}); |
| 57 | + |
| 58 | +test('adds current transaction name to trace envelope header when the txn name is high-quality', done => { |
| 59 | + expect.assertions(4); |
| 60 | + |
| 61 | + createRunner(__dirname, 'scenario-events.ts') |
| 62 | + .expectHeader({ |
| 63 | + event: { |
| 64 | + trace: { |
| 65 | + environment: 'production', |
| 66 | + public_key: 'public', |
| 67 | + release: '1.0', |
| 68 | + sample_rate: '1', |
| 69 | + sampled: 'true', |
| 70 | + trace_id: expect.any(String), |
| 71 | + }, |
| 72 | + }, |
| 73 | + }) |
| 74 | + .expectHeader({ |
| 75 | + event: { |
| 76 | + trace: { |
| 77 | + environment: 'production', |
| 78 | + public_key: 'public', |
| 79 | + release: '1.0', |
| 80 | + sample_rate: '1', |
| 81 | + sampled: 'true', |
| 82 | + trace_id: expect.any(String), |
| 83 | + transaction: 'updated-name-1', |
| 84 | + }, |
| 85 | + }, |
| 86 | + }) |
| 87 | + .expectHeader({ |
| 88 | + event: { |
| 89 | + trace: { |
| 90 | + environment: 'production', |
| 91 | + public_key: 'public', |
| 92 | + release: '1.0', |
| 93 | + sample_rate: '1', |
| 94 | + sampled: 'true', |
| 95 | + trace_id: expect.any(String), |
| 96 | + transaction: 'updated-name-2', |
| 97 | + }, |
| 98 | + }, |
| 99 | + }) |
| 100 | + .expectHeader({ |
| 101 | + transaction: { |
| 102 | + trace: { |
| 103 | + environment: 'production', |
| 104 | + public_key: 'public', |
| 105 | + release: '1.0', |
| 106 | + sample_rate: '1', |
| 107 | + sampled: 'true', |
| 108 | + trace_id: expect.any(String), |
| 109 | + transaction: 'updated-name-2', |
| 110 | + }, |
| 111 | + }, |
| 112 | + }) |
| 113 | + .start(done); |
| 114 | +}); |
| 115 | + |
| 116 | +function getBaggageHeaderItems(headers: Record<string, string | string[] | undefined>) { |
| 117 | + const baggage = headers['baggage'] as string; |
| 118 | + const baggageItems = baggage |
| 119 | + .split(',') |
| 120 | + .map(b => b.trim()) |
| 121 | + .sort(); |
| 122 | + return baggageItems; |
| 123 | +} |
0 commit comments