Skip to content

Commit 1c58bf0

Browse files
committed
add routes
1 parent 8639883 commit 1c58bf0

11 files changed

+1760
-89
lines changed

apps/express/src/app.ts

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ Sentry.init({
1717
debug: true,
1818
tunnel: `http://127.0.0.1:3031/`, // proxy server
1919
tracesSampleRate: 1,
20+
integrations: [new Sentry.Integrations.Express({ app })],
2021
});
2122

2223
app.use(Sentry.Handlers.requestHandler());
@@ -26,11 +27,27 @@ app.get('/test-success', function (req, res) {
2627
res.send({ version: 'v1' });
2728
});
2829

29-
app.get('/test-param/:param', function (req, res) {
30+
app.get('/test-error', async function (req, res) {
31+
const exceptionId = Sentry.captureException(new Error('This is an error'));
32+
33+
await Sentry.flush(2000);
34+
35+
res.send({ exceptionId });
36+
});
37+
38+
app.get('/test-param-success/:param', function (req, res) {
3039
res.send({ paramWas: req.params.param });
3140
});
3241

33-
app.get('/test-transaction', async function (req, res) {
42+
app.get('/test-param-error/:param', async function (req, res) {
43+
const exceptionId = Sentry.captureException(new Error('This is an error'));
44+
45+
await Sentry.flush(2000);
46+
47+
res.send({ exceptionId, paramWas: req.params.param });
48+
});
49+
50+
app.get('/test-success-manual', async function (req, res) {
3451
Sentry.startSpan({ name: 'test-transaction', op: 'e2e-test' }, () => {
3552
Sentry.startSpan({ name: 'test-span' }, () => undefined);
3653
});
@@ -42,21 +59,27 @@ app.get('/test-transaction', async function (req, res) {
4259
});
4360
});
4461

45-
app.get('/test-error', async function (req, res) {
46-
const exceptionId = Sentry.captureException(new Error('This is an error'));
62+
app.get('/test-error-manual', async function (req, res) {
63+
Sentry.startSpan({ name: 'test-transaction', op: 'e2e-test' }, () => {
64+
Sentry.startSpan({ name: 'test-span' }, () => {
65+
Sentry.captureException(new Error('This is an error'));
66+
});
67+
});
4768

4869
await Sentry.flush(2000);
4970

50-
res.send({ exceptionId });
71+
res.send({
72+
transactionIds: global.transactionIds || [],
73+
});
5174
});
5275

5376
app.get('/test-local-variables-uncaught', function (req, res) {
54-
const randomVariableToRecord = Math.random();
77+
const randomVariableToRecord = 'LOCAL VARIABLE';
5578
throw new Error(`Uncaught Local Variable Error - ${JSON.stringify({ randomVariableToRecord })}`);
5679
});
5780

5881
app.get('/test-local-variables-caught', function (req, res) {
59-
const randomVariableToRecord = Math.random();
82+
const randomVariableToRecord = 'LOCAL VARIABLE';
6083

6184
let exceptionId: string;
6285
try {

utils/event-proxy-server/payload-files/express/test-error.json renamed to utils/event-proxy-server/payload-files/express/test-error--event.json

Lines changed: 35 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"name": "sentry.javascript.node",
77
"version": "7.109.0"
88
},
9-
"dsn": "https://3b6c388182fb435097f41d181be2b2ba@o4504321058471936.ingest.sentry.io/4504321066008576",
9+
"dsn": "[[dsn]]",
1010
"trace": {
1111
"environment": "qa",
1212
"public_key": "[[publicKey]]",
@@ -28,7 +28,7 @@
2828
"stacktrace": {
2929
"frames": [
3030
{
31-
"filename": "/Users/sigridh/Documents/DEV/sentry-javascript-examples/node_modules/express/lib/router/route.js",
31+
"filename": "[[FILENAME1]]",
3232
"module": "express.lib.router:route",
3333
"function": "Route.dispatch",
3434
"lineno": 119,
@@ -55,7 +55,7 @@
5555
]
5656
},
5757
{
58-
"filename": "/Users/sigridh/Documents/DEV/sentry-javascript-examples/node_modules/express/lib/router/route.js",
58+
"filename": "[[FILENAME1]]",
5959
"module": "express.lib.router:route",
6060
"function": "next",
6161
"lineno": 149,
@@ -71,10 +71,18 @@
7171
" } else {"
7272
],
7373
"context_line": " layer.handle_request(req, res, next);",
74-
"post_context": [" }", "", " sync = 0", " }", "};", "", "/**"]
74+
"post_context": [
75+
" }",
76+
"",
77+
" sync = 0",
78+
" }",
79+
"};",
80+
"",
81+
"/**"
82+
]
7583
},
7684
{
77-
"filename": "/Users/sigridh/Documents/DEV/sentry-javascript-examples/node_modules/express/lib/router/layer.js",
85+
"filename": "[[FILENAME2]]",
7886
"module": "express.lib.router:layer",
7987
"function": "Layer.handle [as handle_request]",
8088
"lineno": 95,
@@ -101,18 +109,18 @@
101109
]
102110
},
103111
{
104-
"filename": "/Users/sigridh/Documents/DEV/sentry-javascript-examples/apps/express/dist/app.js",
112+
"filename": "[[FILENAME3]]",
105113
"module": "app",
106114
"function": "<anonymous>",
107-
"lineno": 105,
115+
"lineno": 85,
108116
"colno": 12,
109117
"in_app": true,
110118
"pre_context": [
111-
" });",
112-
" return [2 /*return*/];",
113-
" }",
114-
" });",
115-
" });",
119+
"// todo: add express integration to docs",
120+
"app.use(Sentry.Handlers.requestHandler());",
121+
"app.use(Sentry.Handlers.tracingHandler());",
122+
"app.get('/test-success', function (req, res) {",
123+
" res.send({ version: 'v1' });",
116124
"});",
117125
"app.get('/test-error', function (req, res) {"
118126
],
@@ -128,7 +136,7 @@
128136
]
129137
},
130138
{
131-
"filename": "/Users/sigridh/Documents/DEV/sentry-javascript-examples/apps/express/dist/app.js",
139+
"filename": "[[FILENAME3]]",
132140
"module": "app",
133141
"function": "__awaiter",
134142
"lineno": 27,
@@ -155,13 +163,13 @@
155163
]
156164
},
157165
{
158-
"filename": "<anonymous>",
166+
"filename": "[[FILENAME4]]",
159167
"module": "<anonymous>",
160168
"function": "new Promise",
161169
"in_app": false
162170
},
163171
{
164-
"filename": "/Users/sigridh/Documents/DEV/sentry-javascript-examples/apps/express/dist/app.js",
172+
"filename": "[[FILENAME3]]",
165173
"module": "app",
166174
"function": "<anonymous>",
167175
"lineno": 31,
@@ -188,7 +196,7 @@
188196
]
189197
},
190198
{
191-
"filename": "/Users/sigridh/Documents/DEV/sentry-javascript-examples/apps/express/dist/app.js",
199+
"filename": "[[FILENAME3]]",
192200
"module": "app",
193201
"function": "Object.next",
194202
"lineno": 37,
@@ -215,7 +223,7 @@
215223
]
216224
},
217225
{
218-
"filename": "/Users/sigridh/Documents/DEV/sentry-javascript-examples/apps/express/dist/app.js",
226+
"filename": "[[FILENAME3]]",
219227
"module": "app",
220228
"function": "step",
221229
"lineno": 56,
@@ -242,10 +250,10 @@
242250
]
243251
},
244252
{
245-
"filename": "/Users/sigridh/Documents/DEV/sentry-javascript-examples/apps/express/dist/app.js",
253+
"filename": "[[FILENAME3]]",
246254
"module": "app",
247255
"function": "<anonymous>",
248-
"lineno": 110,
256+
"lineno": 90,
249257
"colno": 59,
250258
"in_app": true,
251259
"pre_context": [
@@ -282,13 +290,13 @@
282290
"contexts": {
283291
"trace": {
284292
"data": {
285-
"sentry.source": "url",
293+
"sentry.source": "route",
286294
"sentry.origin": "auto.http.node.tracingHandler",
287295
"sentry.op": "http.server",
288296
"sentry.sample_rate": 1
289297
},
290298
"op": "http.server",
291-
"span_id": "[[ID1]]",
299+
"span_id": "[[ID3]]",
292300
"trace_id": "[[ID2]]",
293301
"origin": "auto.http.node.tracingHandler"
294302
},
@@ -338,7 +346,8 @@
338346
"ContextLines",
339347
"LocalVariables",
340348
"Context",
341-
"Modules"
349+
"Modules",
350+
"Express"
342351
],
343352
"name": "sentry.javascript.node",
344353
"version": "7.109.0",
@@ -365,7 +374,7 @@
365374
"cookies": {},
366375
"headers": {
367376
"host": "localhost:3030",
368-
"user-agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:124.0) Gecko/20100101 Firefox/124.0",
377+
"user-agent": "[[user-agent]]",
369378
"accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8",
370379
"accept-language": "en-US,en;q=0.5",
371380
"accept-encoding": "gzip, deflate, br",
@@ -375,7 +384,8 @@
375384
"sec-fetch-mode": "navigate",
376385
"sec-fetch-site": "none",
377386
"sec-fetch-user": "?1",
378-
"if-none-match": "W/\"32-pMMsTilhCm5O0WdOKAWpxeIiRbs\""
387+
"pragma": "no-cache",
388+
"cache-control": "no-cache"
379389
},
380390
"query_string": {},
381391
"url": "http://localhost:3030/test-error"
@@ -446,4 +456,4 @@
446456
"serve-static": "1.15.0"
447457
}
448458
}
449-
]
459+
]

utils/event-proxy-server/payload-files/express/test-param_3.json renamed to utils/event-proxy-server/payload-files/express/test-error--transaction.json

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66
"name": "sentry.javascript.node",
77
"version": "7.109.0"
88
},
9-
"dsn": "https://3b6c388182fb435097f41d181be2b2ba@o4504321058471936.ingest.sentry.io/4504321066008576",
9+
"dsn": "[[dsn]]",
1010
"trace": {
1111
"environment": "qa",
1212
"public_key": "[[publicKey]]",
1313
"trace_id": "[[ID2]]",
1414
"sample_rate": "1",
15-
"transaction": "GET /test-param/3",
15+
"transaction": "GET /test-error",
1616
"sampled": "true"
1717
}
1818
},
@@ -23,16 +23,16 @@
2323
"contexts": {
2424
"trace": {
2525
"data": {
26-
"sentry.source": "url",
26+
"sentry.source": "route",
2727
"query": {},
2828
"http.response.status_code": 200,
2929
"sentry.origin": "auto.http.node.tracingHandler",
3030
"sentry.op": "http.server",
3131
"sentry.sample_rate": 1,
32-
"url": "/test-param/3"
32+
"url": "/test-error"
3333
},
3434
"op": "http.server",
35-
"span_id": "[[ID1]]",
35+
"span_id": "[[ID3]]",
3636
"status": "ok",
3737
"tags": {
3838
"http.status_code": "200"
@@ -75,10 +75,10 @@
7575
"http.status_code": "200"
7676
},
7777
"timestamp": "[[timestamp]]",
78-
"transaction": "GET /test-param/3",
78+
"transaction": "GET /test-error",
7979
"type": "transaction",
8080
"transaction_info": {
81-
"source": "custom"
81+
"source": "route"
8282
},
8383
"platform": "node",
8484
"server_name": "D9M3PY4LQ7.local",
@@ -98,7 +98,8 @@
9898
"ContextLines",
9999
"LocalVariables",
100100
"Context",
101-
"Modules"
101+
"Modules",
102+
"Express"
102103
],
103104
"name": "sentry.javascript.node",
104105
"version": "7.109.0",
@@ -122,7 +123,7 @@
122123
"cookies": {},
123124
"headers": {
124125
"host": "localhost:3030",
125-
"user-agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:124.0) Gecko/20100101 Firefox/124.0",
126+
"user-agent": "[[user-agent]]",
126127
"accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8",
127128
"accept-language": "en-US,en;q=0.5",
128129
"accept-encoding": "gzip, deflate, br",
@@ -131,10 +132,12 @@
131132
"sec-fetch-dest": "document",
132133
"sec-fetch-mode": "navigate",
133134
"sec-fetch-site": "none",
134-
"sec-fetch-user": "?1"
135+
"sec-fetch-user": "?1",
136+
"pragma": "no-cache",
137+
"cache-control": "no-cache"
135138
},
136139
"query_string": {},
137-
"url": "http://localhost:3030/test-param/3"
140+
"url": "http://localhost:3030/test-error"
138141
},
139142
"modules": {
140143
"express": "4.19.2",
@@ -201,4 +204,4 @@
201204
"serve-static": "1.15.0"
202205
}
203206
}
204-
]
207+
]

0 commit comments

Comments
 (0)