Skip to content

Commit 887592c

Browse files
committed
feat(node): Support hapi v21 & fix E2E test
This PR bumps the hapi instrumentation to v0.38.0, which now supports hapi 21: https://github.com/open-telemetry/opentelemetry-js-contrib/releases/tag/instrumentation-hapi-v0.38.0 It also re-adds the hapi E2E test.
1 parent 5114e44 commit 887592c

File tree

13 files changed

+222
-349
lines changed

13 files changed

+222
-349
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1017,7 +1017,7 @@ jobs:
10171017
'generic-ts3.8',
10181018
'node-fastify-app',
10191019
# TODO(v8): Re-enable hapi tests
1020-
# 'node-hapi-app',
1020+
'node-hapi',
10211021
'node-nestjs-app',
10221022
'node-exports-test-app',
10231023
'node-koa-app',

dev-packages/e2e-tests/test-applications/node-hapi-app/tests/server.test.ts

Lines changed: 0 additions & 208 deletions
This file was deleted.

dev-packages/e2e-tests/test-applications/node-hapi-app/package.json renamed to dev-packages/e2e-tests/test-applications/node-hapi/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "node-hapi-app",
2+
"name": "node-hapi",
33
"version": "1.0.0",
44
"private": true,
55
"scripts": {

dev-packages/e2e-tests/test-applications/node-hapi-app/src/app.js renamed to dev-packages/e2e-tests/test-applications/node-hapi/src/app.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,4 @@
11
const Sentry = require('@sentry/node');
2-
const Hapi = require('@hapi/hapi');
3-
4-
const server = Hapi.server({
5-
port: 3030,
6-
host: 'localhost',
7-
});
82

93
Sentry.init({
104
environment: 'qa', // dynamic sampling bias to keep transactions
@@ -15,6 +9,13 @@ Sentry.init({
159
tracesSampleRate: 1,
1610
});
1711

12+
const Hapi = require('@hapi/hapi');
13+
14+
const server = Hapi.server({
15+
port: 3030,
16+
host: 'localhost',
17+
});
18+
1819
const init = async () => {
1920
server.route({
2021
method: 'GET',
@@ -28,6 +29,8 @@ const init = async () => {
2829
method: 'GET',
2930
path: '/test-param/{param}',
3031
handler: function (request, h) {
32+
Sentry.setTag(`param-${request.params.param}`, 'yes');
33+
3134
return { paramWas: request.params.param };
3235
},
3336
});

dev-packages/e2e-tests/test-applications/node-hapi-app/start-event-proxy.ts renamed to dev-packages/e2e-tests/test-applications/node-hapi/start-event-proxy.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@ import { startEventProxyServer } from '@sentry-internal/event-proxy-server';
22

33
startEventProxyServer({
44
port: 3031,
5-
proxyServerName: 'node-hapi-app',
5+
proxyServerName: 'node-hapi',
66
});
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
import { expect, test } from '@playwright/test';
2+
import { waitForError } from '@sentry-internal/event-proxy-server';
3+
import axios, { AxiosError } from 'axios';
4+
5+
const authToken = process.env.E2E_TEST_AUTH_TOKEN;
6+
const sentryTestOrgSlug = process.env.E2E_TEST_SENTRY_ORG_SLUG;
7+
const sentryTestProject = process.env.E2E_TEST_SENTRY_TEST_PROJECT;
8+
const EVENT_POLLING_TIMEOUT = 90_000;
9+
10+
test('Sends captured exception to Sentry', async ({ baseURL }) => {
11+
const { data } = await axios.get(`${baseURL}/test-error`);
12+
const { exceptionId } = data;
13+
14+
const url = `https://sentry.io/api/0/projects/${sentryTestOrgSlug}/${sentryTestProject}/events/${exceptionId}/`;
15+
16+
console.log(`Polling for error eventId: ${exceptionId}`);
17+
18+
await expect
19+
.poll(
20+
async () => {
21+
try {
22+
const response = await axios.get(url, { headers: { Authorization: `Bearer ${authToken}` } });
23+
24+
return response.status;
25+
} catch (e) {
26+
if (e instanceof AxiosError && e.response) {
27+
if (e.response.status !== 404) {
28+
throw e;
29+
} else {
30+
return e.response.status;
31+
}
32+
} else {
33+
throw e;
34+
}
35+
}
36+
},
37+
{ timeout: EVENT_POLLING_TIMEOUT },
38+
)
39+
.toBe(200);
40+
});
41+
42+
test('Sends thrown error to Sentry', async ({ baseURL }) => {
43+
const errorEventPromise = waitForError('node-hapi', errorEvent => {
44+
return errorEvent?.exception?.values?.[0]?.value === 'This is an error';
45+
});
46+
47+
try {
48+
await axios.get(`${baseURL}/test-failure`);
49+
} catch (e) {}
50+
51+
const errorEvent = await errorEventPromise;
52+
const errorEventId = errorEvent.event_id;
53+
54+
await expect
55+
.poll(
56+
async () => {
57+
try {
58+
const response = await axios.get(
59+
`https://sentry.io/api/0/projects/${sentryTestOrgSlug}/${sentryTestProject}/events/${errorEventId}/`,
60+
{ headers: { Authorization: `Bearer ${authToken}` } },
61+
);
62+
63+
return response.status;
64+
} catch (e) {
65+
if (e instanceof AxiosError && e.response) {
66+
if (e.response.status !== 404) {
67+
throw e;
68+
} else {
69+
return e.response.status;
70+
}
71+
} else {
72+
throw e;
73+
}
74+
}
75+
},
76+
{
77+
timeout: EVENT_POLLING_TIMEOUT,
78+
},
79+
)
80+
.toBe(200);
81+
});
82+
83+
test('sends error with parameterized transaction name', async ({ baseURL }) => {
84+
const errorEventPromise = waitForError('node-hapi', errorEvent => {
85+
return errorEvent?.exception?.values?.[0]?.value === 'This is an error with id 123';
86+
});
87+
88+
try {
89+
await axios.get(`${baseURL}/test-error/123`);
90+
} catch {}
91+
92+
const errorEvent = await errorEventPromise;
93+
94+
expect(errorEvent?.transaction).toBe('GET /test-error/{id}');
95+
});

0 commit comments

Comments
 (0)