Skip to content

Commit 49e095f

Browse files
authored
test(node): Add test for console.log & isolation scope (#11593)
Adds a test to ensure isolation scope is correctly applied to express spans, and also that console.log is correctly instrumented. We have related tests in E2E tests and in other places, but it doesn't hurt to have this explicitly here I guess...
1 parent 478f805 commit 49e095f

File tree

2 files changed

+68
-0
lines changed
  • dev-packages/node-integration-tests/suites/express/span-isolationScope

2 files changed

+68
-0
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { loggingTransport } from '@sentry-internal/node-integration-tests';
2+
import * as Sentry from '@sentry/node';
3+
4+
Sentry.init({
5+
dsn: 'https://public@dsn.ingest.sentry.io/1337',
6+
release: '1.0',
7+
tracesSampleRate: 1.0,
8+
transport: loggingTransport,
9+
});
10+
11+
import { startExpressServerAndSendPortToRunner } from '@sentry-internal/node-integration-tests';
12+
import express from 'express';
13+
14+
const app = express();
15+
16+
Sentry.setTag('global', 'tag');
17+
18+
app.get('/test/isolationScope', (_req, res) => {
19+
// eslint-disable-next-line no-console
20+
console.log('This is a test log.');
21+
Sentry.addBreadcrumb({ message: 'manual breadcrumb' });
22+
Sentry.setTag('isolation-scope', 'tag');
23+
24+
res.send({});
25+
});
26+
27+
Sentry.setupExpressErrorHandler(app);
28+
29+
startExpressServerAndSendPortToRunner(app);
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import { cleanupChildProcesses, createRunner } from '../../../utils/runner';
2+
3+
afterAll(() => {
4+
cleanupChildProcesses();
5+
});
6+
7+
test('correctly applies isolation scope to span', done => {
8+
createRunner(__dirname, 'server.ts')
9+
.ignore('session', 'sessions')
10+
.expect({
11+
transaction: {
12+
transaction: 'GET /test/isolationScope',
13+
breadcrumbs: [
14+
{
15+
category: 'console',
16+
level: 'log',
17+
message: expect.stringMatching(/\{"port":(\d+)\}/),
18+
timestamp: expect.any(Number),
19+
},
20+
{
21+
category: 'console',
22+
level: 'log',
23+
message: 'This is a test log.',
24+
timestamp: expect.any(Number),
25+
},
26+
{
27+
message: 'manual breadcrumb',
28+
timestamp: expect.any(Number),
29+
},
30+
],
31+
tags: {
32+
global: 'tag',
33+
'isolation-scope': 'tag',
34+
},
35+
},
36+
})
37+
.start(done)
38+
.makeRequest('get', '/test/isolationScope');
39+
});

0 commit comments

Comments
 (0)