-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Expand file tree
/
Copy pathscenario.mjs
More file actions
62 lines (49 loc) · 1.68 KB
/
Copy pathscenario.mjs
File metadata and controls
62 lines (49 loc) · 1.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import * as Sentry from '@sentry/node';
import { loggingTransport, startExpressServerAndSendPortToRunner } from '@sentry-internal/node-integration-tests';
import express from 'express';
const app = express();
// Store this so we can update the client later
const initialCurrentScope = Sentry.getCurrentScope();
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({
traceLifecycle: 'static',
dsn: 'https://public@dsn.ingest.sentry.io/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}`));
setTimeout(() => {
// We flush to ensure we are sending exceptions in a certain order
Sentry.flush(1000).then(
() => {
// We send this so we can wait for this, to know the test is ended & server can be closed
if (id === '3') {
Sentry.captureException(new Error('Final exception was captured'));
}
res.send({});
},
() => {
res.send({});
},
);
}, 1);
});
Sentry.setupExpressErrorHandler(app);
startExpressServerAndSendPortToRunner(app);