Skip to content
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,60 @@
import { loggingTransport } from '@sentry-internal/node-integration-tests';
import * as Sentry from '@sentry/node';

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

// We add http integration to ensure request isolation etc. works
const initialClient = Sentry.getClient();
initialClient?.addIntegration(Sentry.httpIntegration());

// Store this so we can update the client later
const initialCurrentScope = Sentry.getCurrentScope();

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

const app = express();

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

app.get('/test/no-init', (_req, res) => {
Sentry.addBreadcrumb({ message: 'no init breadcrumb' });
Sentry.setTag('no-init', 'tag');

res.send({});
});

app.get('/test/init', (_req, res) => {
// Call init again, but with DSN
Sentry.init({
dsn: 'https://[email protected]/1337',
release: '1.0',
transport: loggingTransport,
});
// Set this on initial scope, to ensure it can be inherited
initialCurrentScope.setClient(Sentry.getClient()!);

Sentry.addBreadcrumb({ message: 'init breadcrumb' });
Sentry.setTag('init', 'tag');

res.send({});
});

app.get('/test/error/:id', (req, res) => {
const id = req.params.id;
Sentry.addBreadcrumb({ message: `error breadcrumb ${id}` });
Sentry.setTag('error', id);

Sentry.captureException(new Error(`This is an exception ${id}`));

res.send({});
});

Sentry.setupExpressErrorHandler(app);

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

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

test('allows to call init multiple times', done => {
const runner = createRunner(__dirname, 'server.ts')
.ignore('session', 'sessions')
.expect({
event: {
exception: {
values: [
{
value: 'This is an exception 2',
},
],
},
breadcrumbs: [
{
message: 'error breadcrumb 2',
timestamp: expect.any(Number),
},
],
tags: {
global: 'tag',
error: '2',
},
},
})
.expect({
event: {
exception: {
values: [
{
value: 'This is an exception 3',
},
],
},
breadcrumbs: [
{
message: 'error breadcrumb 3',
timestamp: expect.any(Number),
},
],
tags: {
global: 'tag',
error: '3',
},
},
})
.start(done);

runner
.makeRequest('get', '/test/no-init')
.then(() => runner.makeRequest('get', '/test/error/1'))
.then(() => runner.makeRequest('get', '/test/init'))
.then(() => runner.makeRequest('get', '/test/error/2'))
.then(() => runner.makeRequest('get', '/test/error/3'));
});