Skip to content

Commit 50c48da

Browse files
authored
test(node): Add test for express without tracing (#12014)
Just to ensure we do not regress here. Request isolation should work even without tracing (which means, even without the express integration added - that is only added when tracing is enabled, today!). Really, the only thing missing should be `transactionName`.
1 parent 1390402 commit 50c48da

File tree

2 files changed

+79
-0
lines changed
  • dev-packages/node-integration-tests/suites/express/without-tracing

2 files changed

+79
-0
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { loggingTransport } from '@sentry-internal/node-integration-tests';
2+
import * as Sentry from '@sentry/node';
3+
4+
Sentry.init({
5+
dsn: 'https://[email protected]/1337',
6+
release: '1.0',
7+
transport: loggingTransport,
8+
});
9+
10+
import { startExpressServerAndSendPortToRunner } from '@sentry-internal/node-integration-tests';
11+
import express from 'express';
12+
13+
const app = express();
14+
15+
Sentry.setTag('global', 'tag');
16+
17+
app.get('/test/isolationScope/:id', (req, res) => {
18+
const id = req.params.id;
19+
Sentry.setTag('isolation-scope', 'tag');
20+
Sentry.setTag(`isolation-scope-${id}`, id);
21+
Sentry.setTag('isolation-scope-transactionName', `${Sentry.getIsolationScope().getScopeData().transactionName}`);
22+
23+
Sentry.captureException(new Error('This is an exception'));
24+
25+
res.send({});
26+
});
27+
28+
Sentry.setupExpressErrorHandler(app);
29+
30+
startExpressServerAndSendPortToRunner(app);
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import { cleanupChildProcesses, createRunner } from '../../../utils/runner';
2+
3+
afterAll(() => {
4+
cleanupChildProcesses();
5+
});
6+
7+
test('correctly applies isolation scope even without tracing', done => {
8+
const runner = createRunner(__dirname, 'server.ts')
9+
.ignore('session', 'sessions')
10+
.expect({
11+
event: {
12+
tags: {
13+
global: 'tag',
14+
'isolation-scope': 'tag',
15+
'isolation-scope-1': '1',
16+
// We can't properly test non-existance of fields here, so we cast this to a string to test it here
17+
'isolation-scope-transactionName': 'undefined',
18+
},
19+
// Request is correctly set
20+
request: {
21+
url: expect.stringContaining('/test/isolationScope/1'),
22+
headers: {
23+
'user-agent': expect.stringContaining(''),
24+
},
25+
},
26+
},
27+
})
28+
.expect({
29+
event: {
30+
tags: {
31+
global: 'tag',
32+
'isolation-scope': 'tag',
33+
'isolation-scope-2': '2',
34+
// We can't properly test non-existance of fields here, so we cast this to a string to test it here
35+
'isolation-scope-transactionName': 'undefined',
36+
},
37+
// Request is correctly set
38+
request: {
39+
url: expect.stringContaining('/test/isolationScope/2'),
40+
headers: {
41+
'user-agent': expect.stringContaining(''),
42+
},
43+
},
44+
},
45+
})
46+
.start(done);
47+
48+
runner.makeRequest('get', '/test/isolationScope/1').then(() => runner.makeRequest('get', '/test/isolationScope/2'));
49+
});

0 commit comments

Comments
 (0)