-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
Copy pathapp.ts
53 lines (39 loc) · 1.3 KB
/
app.ts
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
import './instrument';
// Other imports below
import * as Sentry from '@sentry/node';
import express from 'express';
const app = express();
const port = 3030;
app.get('/test-success', function (req, res) {
res.send({ version: 'v1' });
});
app.get('/test-param/:param', function (req, res) {
res.send({ paramWas: req.params.param });
});
app.get('/test-transaction', function (req, res) {
Sentry.withActiveSpan(null, async () => {
Sentry.startSpan({ name: 'test-transaction', op: 'e2e-test' }, () => {
Sentry.startSpan({ name: 'test-span' }, () => undefined);
});
await Sentry.flush();
res.send({});
});
});
app.get('/test-error', async function (req, res) {
const exceptionId = Sentry.captureException(new Error('This is an error'));
await Sentry.flush(2000);
res.send({ exceptionId });
});
app.get('/test-exception/:id', function (req, _res) {
throw new Error(`This is an exception with id ${req.params.id}`);
});
Sentry.setupExpressErrorHandler(app);
app.use(function onError(err: unknown, req: any, res: any, next: any) {
// The error id is attached to `res.sentry` to be returned
// and optionally displayed to the user for support.
res.statusCode = 500;
res.end(res.sentry + '\n');
});
app.listen(port, () => {
console.log(`Example app listening on port ${port}`);
});