Skip to content

Commit c2028cb

Browse files
committed
fix & improve plugin & test
1 parent 220ce22 commit c2028cb

File tree

14 files changed

+70
-17
lines changed

14 files changed

+70
-17
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1021,7 +1021,7 @@ jobs:
10211021
'sveltekit',
10221022
'sveltekit-2',
10231023
'generic-ts3.8',
1024-
'node-experimental-fastify-app',
1024+
'node-fastify-app',
10251025
# TODO(v8): Re-enable hapi tests
10261026
# 'node-hapi-app',
10271027
'node-exports-test-app',
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "node-experimental-fastify-app",
2+
"name": "node-fastify-app",
33
"version": "1.0.0",
44
"private": true,
55
"scripts": {
@@ -17,7 +17,6 @@
1717
"@sentry/opentelemetry": "latest || *",
1818
"@types/node": "18.15.1",
1919
"fastify": "4.23.2",
20-
"fastify-plugin": "4.5.1",
2120
"typescript": "4.9.5",
2221
"ts-node": "10.9.1"
2322
},
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ app.get('/test-error', async function (req, res) {
5252
res.send({ exceptionId });
5353
});
5454

55+
app.get('/test-exception', async function (req, res) {
56+
throw new Error('This is an exception');
57+
});
58+
5559
app.listen({ port: port });
5660

5761
function makeHttpRequest(url) {
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@ import { startEventProxyServer } from './event-proxy-server';
22

33
startEventProxyServer({
44
port: 3031,
5-
proxyServerName: 'node-experimental-fastify-app',
5+
proxyServerName: 'node-fastify-app',
66
});
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { expect, test } from '@playwright/test';
22
import axios, { AxiosError } from 'axios';
3+
import { waitForError } from '../event-proxy-server';
34

45
const authToken = process.env.E2E_TEST_AUTH_TOKEN;
56
const sentryTestOrgSlug = process.env.E2E_TEST_SENTRY_ORG_SLUG;
@@ -37,3 +38,36 @@ test('Sends exception to Sentry', async ({ baseURL }) => {
3738
)
3839
.toBe(200);
3940
});
41+
42+
test('Sends correct error event', async ({ baseURL }) => {
43+
const errorEventPromise = waitForError('node-fastify-app', event => {
44+
return !event.type;
45+
});
46+
47+
await axios.get(`${baseURL}/test-exception`);
48+
49+
const errorEvent = await errorEventPromise;
50+
51+
console.log(JSON.stringify(errorEvent, null, 2));
52+
53+
expect(errorEvent.exception?.values).toHaveLength(1);
54+
expect(errorEvent.exception?.values?.[0]?.value).toBe('This is an exception.');
55+
56+
expect(errorEvent.request).toEqual({});
57+
58+
expect(errorEvent).toEqual({
59+
request: {
60+
method: 'GET',
61+
cookies: {},
62+
headers: expect.any(Object),
63+
url: 'http://localhost:3030/test-exception',
64+
},
65+
});
66+
67+
expect(errorEvent.transaction).toEqual('GET /test-exception');
68+
69+
expect(errorEvent.contexts?.trace).toEqual({
70+
trace_id: expect.any(String),
71+
span_id: expect.any(String),
72+
});
73+
});

0 commit comments

Comments
 (0)