-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
Copy pathserver.ts
40 lines (30 loc) · 1.18 KB
/
server.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
import * as Sentry from '@sentry/node';
import * as Tracing from '@sentry/tracing';
import cors from 'cors';
import express from 'express';
import http from 'http';
const app = express();
export type TestAPIResponse = { test_data: { host: string; 'sentry-trace': string; baggage: string } };
Sentry.init({
dsn: 'https://[email protected]/1337',
release: '1.0',
environment: 'prod',
integrations: [new Sentry.Integrations.Http({ tracing: true }), new Tracing.Integrations.Express({ app })],
tracesSampleRate: 1.0,
});
Sentry.setUser({ id: 'user123', segment: 'SegmentA' });
app.use(Sentry.Handlers.requestHandler());
app.use(Sentry.Handlers.tracingHandler());
app.use(cors());
app.get('/test/express', (_req, res) => {
const transaction = Sentry.getCurrentHub().getScope()?.getTransaction();
if (transaction) {
transaction.traceId = '86f39e84263a4de99c326acab3bfe3bd';
transaction.metadata.source = undefined;
}
const headers = http.get('http://somewhere.not.sentry/').getHeaders();
// Responding with the headers outgoing request headers back to the assertions.
res.send({ test_data: headers });
});
app.use(Sentry.Handlers.errorHandler());
export default app;