Skip to content

Commit a5c6811

Browse files
author
cod1k
committed
Add endpoint and tests for withMonitor error handling to cover issue:16749
Introduce a new endpoint `/crash-in-with-monitor/:id` that demonstrates error handling using Sentry's `withMonitor` API. Added tests to ensure the app gracefully handles exceptions and validates consistent PID behavior during monitoring.
1 parent fda28e8 commit a5c6811

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

dev-packages/e2e-tests/test-applications/node-express/src/app.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,18 @@ const port = 3030;
2929

3030
app.use(mcpRouter);
3131

32+
app.get('/crash-in-with-monitor/:id', async (req, res) => {
33+
try {
34+
await Sentry.withMonitor('express-crash', async () => {
35+
throw new Error(`This is an exception withMonitor: ${req.params.id}`);
36+
});
37+
res.sendStatus(200);
38+
} catch (error: any) {
39+
res.status(500);
40+
res.send({ message: error.message, pid: process.pid });
41+
}
42+
});
43+
3244
app.get('/test-success', function (req, res) {
3345
res.send({ version: 'v1' });
3446
});

dev-packages/e2e-tests/test-applications/node-express/tests/errors.test.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,14 @@ test('Should record caught exceptions with local variable', async ({ baseURL })
4040
const frames = errorEvent.exception?.values?.[0]?.stacktrace?.frames;
4141
expect(frames?.[frames.length - 1]?.vars?.randomVariableToRecord).toBeDefined();
4242
});
43+
44+
test('To not crush app from withMonitor', async ({ baseURL }) => {
45+
const doRequest = async (id: number) => {
46+
const response = await fetch(`${baseURL}/crash-in-with-monitor/${id}`)
47+
return response.json();
48+
}
49+
const [response1, response2] = await Promise.all([doRequest(1), doRequest(2)])
50+
expect(response1.message).toBe('This is an exception withMonitor: 1')
51+
expect(response2.message).toBe('This is an exception withMonitor: 2')
52+
expect(response1.pid).toBe(response2.pid) //Just to double-check, TBS
53+
});

0 commit comments

Comments
 (0)