Skip to content

Commit d058fa8

Browse files
committed
httpIntegration
1 parent 68d0733 commit d058fa8

File tree

3 files changed

+58
-63
lines changed

3 files changed

+58
-63
lines changed

dev-packages/node-integration-tests/suites/tracing/httpIntegration/server.js renamed to dev-packages/node-integration-tests/suites/tracing/httpIntegration/instrument.mjs

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
const { loggingTransport } = require('@sentry-internal/node-integration-tests');
2-
const Sentry = require('@sentry/node');
1+
import * as Sentry from '@sentry/node';
2+
import { loggingTransport } from '@sentry-internal/node-integration-tests';
33

44
Sentry.init({
55
dsn: 'https://[email protected]/1337',
@@ -39,20 +39,3 @@ Sentry.init({
3939
}),
4040
],
4141
});
42-
43-
// express must be required after Sentry is initialized
44-
const express = require('express');
45-
const cors = require('cors');
46-
const { startExpressServerAndSendPortToRunner } = require('@sentry-internal/node-integration-tests');
47-
48-
const app = express();
49-
50-
app.use(cors());
51-
52-
app.get('/test', (_req, res) => {
53-
res.send({ response: 'response 1' });
54-
});
55-
56-
Sentry.setupExpressErrorHandler(app);
57-
58-
startExpressServerAndSendPortToRunner(app);
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import * as Sentry from '@sentry/node';
2+
import { startExpressServerAndSendPortToRunner } from '@sentry-internal/node-integration-tests';
3+
import cors from 'cors';
4+
import express from 'express';
5+
6+
const app = express();
7+
8+
app.use(cors());
9+
10+
app.get('/test', (_req, res) => {
11+
res.send({ response: 'response 1' });
12+
});
13+
14+
Sentry.setupExpressErrorHandler(app);
15+
16+
startExpressServerAndSendPortToRunner(app);

dev-packages/node-integration-tests/suites/tracing/httpIntegration/test.ts

Lines changed: 40 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,54 @@
11
import { afterAll, describe, expect, test } from 'vitest';
2-
import { cleanupChildProcesses, createRunner } from '../../../utils/runner';
2+
import { cleanupChildProcesses, createEsmAndCjsTests, createRunner } from '../../../utils/runner';
33
import { createTestServer } from '../../../utils/server';
44

55
describe('httpIntegration', () => {
66
afterAll(() => {
77
cleanupChildProcesses();
88
});
99

10-
test('allows to pass instrumentation options to integration', async () => {
11-
// response shape seems different on Node 14, so we skip this there
12-
const nodeMajorVersion = Number(process.versions.node.split('.')[0]);
13-
if (nodeMajorVersion <= 14) {
14-
return;
15-
}
16-
17-
const runner = createRunner(__dirname, 'server.js')
18-
.expect({
19-
transaction: {
20-
contexts: {
21-
trace: {
22-
span_id: expect.stringMatching(/[a-f0-9]{16}/),
23-
trace_id: expect.stringMatching(/[a-f0-9]{32}/),
24-
data: {
25-
url: expect.stringMatching(/\/test$/),
26-
'http.response.status_code': 200,
27-
attr1: 'yes',
28-
attr2: 'yes',
29-
attr3: 'yes',
10+
createEsmAndCjsTests(__dirname, 'server.mjs', 'instrument.mjs', (createRunner, test) => {
11+
test('allows to pass instrumentation options to integration', async () => {
12+
const runner = createRunner()
13+
.expect({
14+
transaction: {
15+
contexts: {
16+
trace: {
17+
span_id: expect.stringMatching(/[a-f0-9]{16}/),
18+
trace_id: expect.stringMatching(/[a-f0-9]{32}/),
19+
data: {
20+
url: expect.stringMatching(/\/test$/),
21+
'http.response.status_code': 200,
22+
attr1: 'yes',
23+
attr2: 'yes',
24+
attr3: 'yes',
25+
},
26+
op: 'http.server',
27+
status: 'ok',
3028
},
31-
op: 'http.server',
32-
status: 'ok',
33-
},
34-
},
35-
extra: {
36-
requestHookCalled: {
37-
url: expect.stringMatching(/\/test$/),
38-
method: 'GET',
39-
},
40-
responseHookCalled: {
41-
url: expect.stringMatching(/\/test$/),
42-
method: 'GET',
4329
},
44-
applyCustomAttributesOnSpanCalled: {
45-
reqUrl: expect.stringMatching(/\/test$/),
46-
reqMethod: 'GET',
47-
resUrl: expect.stringMatching(/\/test$/),
48-
resMethod: 'GET',
30+
extra: {
31+
requestHookCalled: {
32+
url: expect.stringMatching(/\/test$/),
33+
method: 'GET',
34+
},
35+
responseHookCalled: {
36+
url: expect.stringMatching(/\/test$/),
37+
method: 'GET',
38+
},
39+
applyCustomAttributesOnSpanCalled: {
40+
reqUrl: expect.stringMatching(/\/test$/),
41+
reqMethod: 'GET',
42+
resUrl: expect.stringMatching(/\/test$/),
43+
resMethod: 'GET',
44+
},
4945
},
5046
},
51-
},
52-
})
53-
.start();
54-
runner.makeRequest('get', '/test');
55-
await runner.completed();
47+
})
48+
.start();
49+
runner.makeRequest('get', '/test');
50+
await runner.completed();
51+
});
5652
});
5753

5854
test('allows to pass experimental config through to integration', async () => {
@@ -155,7 +151,7 @@ describe('httpIntegration', () => {
155151
expect(breadcrumbs![0]?.data?.url).toEqual(`${SERVER_URL}/pass`);
156152
},
157153
})
158-
.start(closeTestServer);
154+
.start();
159155
runner.makeRequest('get', '/testUrl');
160156
await runner.completed();
161157
closeTestServer();

0 commit comments

Comments
 (0)