-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Expand file tree
/
Copy pathserver.test.ts
More file actions
168 lines (150 loc) · 5.65 KB
/
server.test.ts
File metadata and controls
168 lines (150 loc) · 5.65 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
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
import { expect, test } from '@playwright/test';
import { waitForError, waitForTransaction } from '@sentry-internal/test-utils';
test('Should record exceptions captured inside handlers', async ({ request }) => {
const errorEventPromise = waitForError('node-express-esm-preload', errorEvent => {
return !!errorEvent?.exception?.values?.[0]?.value?.includes('This is an error');
});
await request.get('/test-error');
await expect(errorEventPromise).resolves.toBeDefined();
});
test('Should record a transaction for a parameterless route', async ({ request }) => {
const transactionEventPromise = waitForTransaction('node-express-esm-preload', transactionEvent => {
return transactionEvent?.transaction === 'GET /test-success';
});
await request.get('/test-success');
await expect(transactionEventPromise).resolves.toBeDefined();
});
test('Should record a transaction for route with parameters', async ({ request }) => {
const transactionEventPromise = waitForTransaction('node-express-esm-preload', transactionEvent => {
return transactionEvent.contexts?.trace?.data?.['http.target'] === '/test-transaction/1';
});
await request.get('/test-transaction/1');
const transactionEvent = await transactionEventPromise;
expect(transactionEvent).toBeDefined();
expect(transactionEvent.transaction).toEqual('GET /test-transaction/:param');
expect(transactionEvent.contexts?.trace?.data).toEqual(
expect.objectContaining({
'http.flavor': '1.1',
'http.host': 'localhost:3030',
'http.method': 'GET',
'http.response.status_code': 200,
'http.route': '/test-transaction/:param',
'http.scheme': 'http',
'http.status_code': 200,
'http.status_text': 'OK',
'http.target': '/test-transaction/1',
'http.url': 'http://localhost:3030/test-transaction/1',
'http.user_agent': expect.any(String),
'net.host.ip': expect.any(String),
'net.host.name': 'localhost',
'net.host.port': 3030,
'net.peer.ip': expect.any(String),
'net.peer.port': expect.any(Number),
'net.transport': 'ip_tcp',
'otel.kind': 'SERVER',
'sentry.op': 'http.server',
'sentry.origin': 'auto.http.otel.http',
'sentry.sample_rate': 1,
'sentry.source': 'route',
url: 'http://localhost:3030/test-transaction/1',
}),
);
const spans = transactionEvent.spans || [];
expect(spans).toContainEqual({
data: {
'express.name': 'query',
'express.type': 'middleware',
'http.route': '/',
'otel.kind': 'INTERNAL',
'sentry.origin': 'auto.http.otel.express',
'sentry.op': 'middleware.express',
},
op: 'middleware.express',
description: 'query',
origin: 'auto.http.otel.express',
parent_span_id: expect.any(String),
span_id: expect.any(String),
start_timestamp: expect.any(Number),
status: 'ok',
timestamp: expect.any(Number),
trace_id: expect.any(String),
});
expect(spans).toContainEqual({
data: {
'express.name': 'expressInit',
'express.type': 'middleware',
'http.route': '/',
'otel.kind': 'INTERNAL',
'sentry.origin': 'auto.http.otel.express',
'sentry.op': 'middleware.express',
},
op: 'middleware.express',
description: 'expressInit',
origin: 'auto.http.otel.express',
parent_span_id: expect.any(String),
span_id: expect.any(String),
start_timestamp: expect.any(Number),
status: 'ok',
timestamp: expect.any(Number),
trace_id: expect.any(String),
});
expect(spans).toContainEqual({
data: {
'express.name': '/test-transaction/:param',
'express.type': 'request_handler',
'http.route': '/test-transaction/:param',
'otel.kind': 'INTERNAL',
'sentry.origin': 'auto.http.otel.express',
'sentry.op': 'request_handler.express',
},
op: 'request_handler.express',
description: '/test-transaction/:param',
origin: 'auto.http.otel.express',
parent_span_id: expect.any(String),
span_id: expect.any(String),
start_timestamp: expect.any(Number),
status: 'ok',
timestamp: expect.any(Number),
trace_id: expect.any(String),
});
});
// This fails https://github.com/getsentry/sentry-javascript/pull/12587#issuecomment-2181019422
// Skipping this for now so we don't block releases
test.skip('Should record spans from http instrumentation', async ({ request }) => {
const transactionEventPromise = waitForTransaction('node-express-esm-preload', transactionEvent => {
return transactionEvent.contexts?.trace?.data?.['http.target'] === '/http-req';
});
await request.get('/http-req');
const transactionEvent = await transactionEventPromise;
const httpClientSpan = transactionEvent.spans?.find(span => span.op === 'http.client');
expect(httpClientSpan).toEqual({
span_id: expect.any(String),
trace_id: expect.any(String),
data: {
'http.flavor': '1.1',
'http.host': 'example.com:80',
'http.method': 'GET',
'http.response.status_code': 200,
'http.response_content_length_uncompressed': expect.any(Number),
'http.status_code': 200,
'http.status_text': 'OK',
'http.target': '/',
'http.url': 'http://example.com/',
'net.peer.ip': expect.any(String),
'net.peer.name': 'example.com',
'net.peer.port': 80,
'net.transport': 'ip_tcp',
'otel.kind': 'CLIENT',
'sentry.op': 'http.client',
'sentry.origin': 'auto.http.otel.http',
url: 'http://example.com/',
},
description: 'GET http://example.com/',
parent_span_id: expect.any(String),
start_timestamp: expect.any(Number),
timestamp: expect.any(Number),
status: 'ok',
op: 'http.client',
origin: 'auto.http.otel.http',
});
});