Skip to content

test(node): Add test for express without tracing #12014

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { loggingTransport } from '@sentry-internal/node-integration-tests';
import * as Sentry from '@sentry/node';

Sentry.init({
dsn: 'https://[email protected]/1337',
release: '1.0',
transport: loggingTransport,
});

import { startExpressServerAndSendPortToRunner } from '@sentry-internal/node-integration-tests';
import express from 'express';

const app = express();

Sentry.setTag('global', 'tag');

app.get('/test/isolationScope/:id', (req, res) => {
const id = req.params.id;
Sentry.setTag('isolation-scope', 'tag');
Sentry.setTag(`isolation-scope-${id}`, id);
Sentry.setTag('isolation-scope-transactionName', `${Sentry.getIsolationScope().getScopeData().transactionName}`);

Sentry.captureException(new Error('This is an exception'));

res.send({});
});

Sentry.setupExpressErrorHandler(app);

startExpressServerAndSendPortToRunner(app);
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { cleanupChildProcesses, createRunner } from '../../../utils/runner';

afterAll(() => {
cleanupChildProcesses();
});

test('correctly applies isolation scope even without tracing', done => {
const runner = createRunner(__dirname, 'server.ts')
.ignore('session', 'sessions')
.expect({
event: {
tags: {
global: 'tag',
'isolation-scope': 'tag',
'isolation-scope-1': '1',
// We can't properly test non-existance of fields here, so we cast this to a string to test it here
'isolation-scope-transactionName': 'undefined',
},
// Request is correctly set
request: {
url: expect.stringContaining('/test/isolationScope/1'),
headers: {
'user-agent': expect.stringContaining(''),
},
},
},
})
.expect({
event: {
tags: {
global: 'tag',
'isolation-scope': 'tag',
'isolation-scope-2': '2',
// We can't properly test non-existance of fields here, so we cast this to a string to test it here
'isolation-scope-transactionName': 'undefined',
},
// Request is correctly set
request: {
url: expect.stringContaining('/test/isolationScope/2'),
headers: {
'user-agent': expect.stringContaining(''),
},
},
},
})
.start(done);

runner.makeRequest('get', '/test/isolationScope/1').then(() => runner.makeRequest('get', '/test/isolationScope/2'));
});
Loading