Skip to content

Commit 655f6f5

Browse files
Lms24mydea
authored andcommitted
test(e2e): Add ESM http instrumentation test (#12379)
add a test to our ESM Express e2e test app to test that http instrumentation is working correctly by ensuring a `http.client` span is captured. --------- Co-authored-by: Francesco Novy <[email protected]>
1 parent b2ec9ad commit 655f6f5

File tree

2 files changed

+58
-0
lines changed

2 files changed

+58
-0
lines changed

dev-packages/e2e-tests/test-applications/node-express-esm-preload/src/app.mjs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import * as http from 'http';
12
import * as Sentry from '@sentry/node';
23
import express from 'express';
34

@@ -25,6 +26,20 @@ app.get('/test-error', function (req, res) {
2526
}, 100);
2627
});
2728

29+
app.get('/http-req', function (req, res) {
30+
http
31+
.request('http://example.com', httpRes => {
32+
let data = '';
33+
httpRes.on('data', d => {
34+
data += d;
35+
});
36+
httpRes.on('end', () => {
37+
res.status(200).send(data).end();
38+
});
39+
})
40+
.end();
41+
});
42+
2843
Sentry.setupExpressErrorHandler(app);
2944

3045
app.use(function onError(err, req, res, next) {

dev-packages/e2e-tests/test-applications/node-express-esm-preload/tests/server.test.ts

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,3 +121,46 @@ test('Should record a transaction for route with parameters', async ({ request }
121121
trace_id: expect.any(String),
122122
});
123123
});
124+
125+
test('Should record spans from http instrumentation', async ({ request }) => {
126+
const transactionEventPromise = waitForTransaction('node-express-esm-preload', transactionEvent => {
127+
return transactionEvent.contexts?.trace?.data?.['http.target'] === '/http-req';
128+
});
129+
130+
await request.get('/http-req');
131+
132+
const transactionEvent = await transactionEventPromise;
133+
134+
const httpClientSpan = transactionEvent.spans?.find(span => span.op === 'http.client');
135+
136+
expect(httpClientSpan).toEqual({
137+
span_id: expect.any(String),
138+
trace_id: expect.any(String),
139+
data: {
140+
'http.flavor': '1.1',
141+
'http.host': 'example.com:80',
142+
'http.method': 'GET',
143+
'http.response.status_code': 200,
144+
'http.response_content_length_uncompressed': expect.any(Number),
145+
'http.status_code': 200,
146+
'http.status_text': 'OK',
147+
'http.target': '/',
148+
'http.url': 'http://example.com/',
149+
'net.peer.ip': expect.any(String),
150+
'net.peer.name': 'example.com',
151+
'net.peer.port': 80,
152+
'net.transport': 'ip_tcp',
153+
'otel.kind': 'CLIENT',
154+
'sentry.op': 'http.client',
155+
'sentry.origin': 'auto.http.otel.http',
156+
url: 'http://example.com/',
157+
},
158+
description: 'GET http://example.com/',
159+
parent_span_id: expect.any(String),
160+
start_timestamp: expect.any(Number),
161+
timestamp: expect.any(Number),
162+
status: 'ok',
163+
op: 'http.client',
164+
origin: 'auto.http.otel.http',
165+
});
166+
});

0 commit comments

Comments
 (0)