-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
Copy pathtest.ts
106 lines (87 loc) · 3.68 KB
/
test.ts
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
import * as path from 'path';
import { getAPIResponse, runServer } from '../../../../utils/index';
import { TestAPIResponse } from '../server';
test('Should not overwrite baggage if the incoming request already has Sentry baggage data.', async () => {
const url = await runServer(__dirname, `${path.resolve(__dirname, '..')}/server.ts`);
const response = (await getAPIResponse(new URL(`${url}/express`), {
baggage: 'sentry-release=2.0.0,sentry-environment=myEnv',
})) as TestAPIResponse;
expect(response).toBeDefined();
expect(response).toMatchObject({
test_data: {
host: 'somewhere.not.sentry',
baggage: 'sentry-release=2.0.0,sentry-environment=myEnv',
},
});
});
test('Should propagate sentry trace baggage data from an incoming to an outgoing request.', async () => {
const url = await runServer(__dirname, `${path.resolve(__dirname, '..')}/server.ts`);
const response = (await getAPIResponse(new URL(`${url}/express`), {
'sentry-trace': '',
baggage: 'sentry-release=2.0.0,sentry-environment=myEnv,dogs=great',
})) as TestAPIResponse;
expect(response).toBeDefined();
expect(response).toMatchObject({
test_data: {
host: 'somewhere.not.sentry',
baggage: 'sentry-release=2.0.0,sentry-environment=myEnv',
},
});
});
test('Should propagate empty baggage if sentry-trace header is present in incoming request but no baggage header', async () => {
const url = await runServer(__dirname, `${path.resolve(__dirname, '..')}/server.ts`);
const response = (await getAPIResponse(new URL(`${url}/express`), {
'sentry-trace': '',
})) as TestAPIResponse;
expect(response).toBeDefined();
expect(response).toMatchObject({
test_data: {
host: 'somewhere.not.sentry',
baggage: '',
},
});
});
test('Should propagate empty sentry and ignore original 3rd party baggage entries if sentry-trace header is present', async () => {
const url = await runServer(__dirname, `${path.resolve(__dirname, '..')}/server.ts`);
const response = (await getAPIResponse(new URL(`${url}/express`), {
'sentry-trace': '',
baggage: 'foo=bar',
})) as TestAPIResponse;
expect(response).toBeDefined();
expect(response).toMatchObject({
test_data: {
host: 'somewhere.not.sentry',
baggage: '',
},
});
});
test('Should populate and propagate sentry baggage if sentry-trace header does not exist', async () => {
const url = await runServer(__dirname, `${path.resolve(__dirname, '..')}/server.ts`);
const response = (await getAPIResponse(new URL(`${url}/express`), {})) as TestAPIResponse;
expect(response).toBeDefined();
expect(response).toMatchObject({
test_data: {
host: 'somewhere.not.sentry',
// TraceId changes, hence we only expect that the string contains the traceid key
baggage: expect.stringContaining(
'sentry-environment=prod,sentry-release=1.0,sentry-transaction=GET%20%2Ftest%2Fexpress,sentry-public_key=public,sentry-trace_id=',
),
},
});
});
test('Should populate Sentry and ignore 3rd party content if sentry-trace header does not exist', async () => {
const url = await runServer(__dirname, `${path.resolve(__dirname, '..')}/server.ts`);
const response = (await getAPIResponse(new URL(`${url}/express`), {
baggage: 'foo=bar,bar=baz',
})) as TestAPIResponse;
expect(response).toBeDefined();
expect(response).toMatchObject({
test_data: {
host: 'somewhere.not.sentry',
// TraceId changes, hence we only expect that the string contains the traceid key
baggage: expect.stringContaining(
'sentry-environment=prod,sentry-release=1.0,sentry-transaction=GET%20%2Ftest%2Fexpress,sentry-public_key=public,sentry-trace_id=',
),
},
});
});