-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Expand file tree
/
Copy pathtest.ts
More file actions
75 lines (60 loc) · 2.18 KB
/
test.ts
File metadata and controls
75 lines (60 loc) · 2.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import { afterAll, expect, test } from 'vitest';
import { cleanupChildProcesses, createRunner } from '../../../../utils/runner';
import type { TestAPIResponse } from '../server';
import { extractTraceparentData } from '@sentry/core';
afterAll(() => {
cleanupChildProcesses();
});
test('should ignore sentry-values in `baggage` header of a third party vendor and overwrite them with incoming DSC', async () => {
const runner = createRunner(__dirname, 'server.ts').start();
const response = await runner.makeRequest<TestAPIResponse>('get', '/test/express', {
headers: {
'sentry-trace': '12312012123120121231201212312012-1121201211212012-1',
baggage: 'sentry-release=2.1.0,sentry-environment=myEnv',
},
});
expect(response).toBeDefined();
const baggage = response?.test_data.baggage?.split(',').sort();
expect(response).toMatchObject({
test_data: {
host: 'somewhere.not.sentry',
},
});
expect(baggage).toEqual([
'foo=bar',
'last=item',
'other=vendor',
'sentry-environment=myEnv',
'sentry-release=2.1.0',
expect.stringMatching(/sentry-sample_rand=\d+/),
'third=party',
]);
});
test('should ignore sentry-values in `baggage` header of a third party vendor and overwrite them with new DSC', async () => {
const runner = createRunner(__dirname, 'server.ts').start();
const response = await runner.makeRequest<TestAPIResponse>('get', '/test/express');
expect(response).toBeDefined();
const baggage = response?.test_data.baggage?.split(',').sort();
const sentryTraceHeader = response?.test_data['sentry-trace'];
const sentryTrace = extractTraceparentData(sentryTraceHeader);
expect(sentryTrace?.traceId).toMatch(/^[0-9a-f]{32}$/);
expect(response).toMatchObject({
test_data: {
host: 'somewhere.not.sentry',
},
});
expect(baggage).toEqual([
'foo=bar',
'last=item',
'other=vendor',
'sentry-environment=prod',
'sentry-public_key=public',
'sentry-release=1.0',
expect.stringMatching(/sentry-sample_rand=\d+/),
'sentry-sample_rate=1',
'sentry-sampled=true',
`sentry-trace_id=${sentryTrace?.traceId}`,
'sentry-transaction=GET%20%2Ftest%2Fexpress',
'third=party',
]);
});