-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
Copy pathtest.ts
172 lines (156 loc) · 5.49 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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
import { cleanupChildProcesses, createRunner } from '../../../utils/runner';
describe('httpIntegration', () => {
afterAll(() => {
cleanupChildProcesses();
});
test('allows to pass instrumentation options to integration', done => {
// response shape seems different on Node 14, so we skip this there
const nodeMajorVersion = Number(process.versions.node.split('.')[0]);
if (nodeMajorVersion <= 14) {
done();
return;
}
createRunner(__dirname, 'server.js')
.expect({
transaction: {
contexts: {
trace: {
span_id: expect.any(String),
trace_id: expect.any(String),
data: {
url: expect.stringMatching(/\/test$/),
'http.response.status_code': 200,
attr1: 'yes',
attr2: 'yes',
attr3: 'yes',
},
op: 'http.server',
status: 'ok',
},
},
extra: {
requestHookCalled: {
url: expect.stringMatching(/\/test$/),
method: 'GET',
},
responseHookCalled: {
url: expect.stringMatching(/\/test$/),
method: 'GET',
},
applyCustomAttributesOnSpanCalled: {
reqUrl: expect.stringMatching(/\/test$/),
reqMethod: 'GET',
resUrl: expect.stringMatching(/\/test$/),
resMethod: 'GET',
},
},
},
})
.start(done)
.makeRequest('get', '/test');
});
test('allows to pass experimental config through to integration', done => {
createRunner(__dirname, 'server-experimental.js')
.expect({
transaction: {
contexts: {
trace: {
span_id: expect.any(String),
trace_id: expect.any(String),
data: {
url: expect.stringMatching(/\/test$/),
'http.response.status_code': 200,
'http.server_name': 'sentry-test-server-name',
},
op: 'http.server',
status: 'ok',
},
},
},
})
.start(done)
.makeRequest('get', '/test');
});
describe("doesn't create a root span for incoming requests ignored via `ignoreIncomingRequests`", () => {
test('via the url param', done => {
const runner = createRunner(__dirname, 'server-ignoreIncomingRequests.js')
.expect({
transaction: {
contexts: {
trace: {
span_id: expect.any(String),
trace_id: expect.any(String),
data: {
url: expect.stringMatching(/\/test$/),
'http.response.status_code': 200,
},
op: 'http.server',
status: 'ok',
},
},
transaction: 'GET /test',
},
})
.start(done);
runner.makeRequest('get', '/liveness'); // should be ignored
runner.makeRequest('get', '/test');
});
test('via the request param', done => {
const runner = createRunner(__dirname, 'server-ignoreIncomingRequests.js')
.expect({
transaction: {
contexts: {
trace: {
span_id: expect.any(String),
trace_id: expect.any(String),
data: {
url: expect.stringMatching(/\/test$/),
'http.response.status_code': 200,
},
op: 'http.server',
status: 'ok',
},
},
transaction: 'GET /test',
},
})
.start(done);
runner.makeRequest('post', '/readiness'); // should be ignored
runner.makeRequest('get', '/test');
});
});
describe("doesn't create child spans or breadcrumbs for outgoing requests ignored via `ignoreOutgoingRequests`", () => {
test('via the url param', done => {
const runner = createRunner(__dirname, 'server-ignoreOutgoingRequests.js')
.expect({
transaction: event => {
expect(event.transaction).toBe('GET /testUrl');
const requestSpans = event.spans?.filter(span => span.op === 'http.client');
expect(requestSpans).toHaveLength(1);
expect(requestSpans![0]?.description).toBe('GET http://example.com/pass');
const breadcrumbs = event.breadcrumbs?.filter(b => b.category === 'http');
expect(breadcrumbs).toHaveLength(1);
expect(breadcrumbs![0]?.data?.url).toEqual('http://example.com/pass');
},
})
.start(done);
runner.makeRequest('get', '/testUrl');
});
test('via the request param', done => {
const runner = createRunner(__dirname, 'server-ignoreOutgoingRequests.js')
.expect({
transaction: event => {
expect(event.transaction).toBe('GET /testRequest');
const requestSpans = event.spans?.filter(span => span.op === 'http.client');
expect(requestSpans).toHaveLength(1);
expect(requestSpans![0]?.description).toBe('GET http://example.com/pass');
const breadcrumbs = event.breadcrumbs?.filter(b => b.category === 'http');
expect(breadcrumbs).toHaveLength(1);
expect(breadcrumbs![0]?.data?.url).toEqual('http://example.com/pass');
},
})
.start(done);
runner.makeRequest('get', '/testRequest');
});
});
});