Skip to content

feat(node): Support hapi v21 & fix E2E test #11906

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1017,7 +1017,7 @@ jobs:
'generic-ts3.8',
'node-fastify-app',
# TODO(v8): Re-enable hapi tests
# 'node-hapi-app',
'node-hapi',
'node-nestjs-app',
'node-exports-test-app',
'node-koa-app',
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "node-hapi-app",
"name": "node-hapi",
"version": "1.0.0",
"private": true,
"scripts": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
const Sentry = require('@sentry/node');
const Hapi = require('@hapi/hapi');

const server = Hapi.server({
port: 3030,
host: 'localhost',
});

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

const Hapi = require('@hapi/hapi');

const server = Hapi.server({
port: 3030,
host: 'localhost',
});

const init = async () => {
server.route({
method: 'GET',
Expand All @@ -28,6 +29,8 @@ const init = async () => {
method: 'GET',
path: '/test-param/{param}',
handler: function (request, h) {
Sentry.setTag(`param-${request.params.param}`, 'yes');

return { paramWas: request.params.param };
},
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ import { startEventProxyServer } from '@sentry-internal/event-proxy-server';

startEventProxyServer({
port: 3031,
proxyServerName: 'node-hapi-app',
proxyServerName: 'node-hapi',
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
import { expect, test } from '@playwright/test';
import { waitForError } from '@sentry-internal/event-proxy-server';
import axios, { AxiosError } from 'axios';

const authToken = process.env.E2E_TEST_AUTH_TOKEN;
const sentryTestOrgSlug = process.env.E2E_TEST_SENTRY_ORG_SLUG;
const sentryTestProject = process.env.E2E_TEST_SENTRY_TEST_PROJECT;
const EVENT_POLLING_TIMEOUT = 90_000;

test('Sends captured exception to Sentry', async ({ baseURL }) => {
const { data } = await axios.get(`${baseURL}/test-error`);
const { exceptionId } = data;

const url = `https://sentry.io/api/0/projects/${sentryTestOrgSlug}/${sentryTestProject}/events/${exceptionId}/`;

console.log(`Polling for error eventId: ${exceptionId}`);

await expect
.poll(
async () => {
try {
const response = await axios.get(url, { headers: { Authorization: `Bearer ${authToken}` } });

return response.status;
} catch (e) {
if (e instanceof AxiosError && e.response) {
if (e.response.status !== 404) {
throw e;
} else {
return e.response.status;
}
} else {
throw e;
}
}
},
{ timeout: EVENT_POLLING_TIMEOUT },
)
.toBe(200);
});

test('Sends thrown error to Sentry', async ({ baseURL }) => {
const errorEventPromise = waitForError('node-hapi', errorEvent => {
return errorEvent?.exception?.values?.[0]?.value === 'This is an error';
});

try {
await axios.get(`${baseURL}/test-failure`);
} catch (e) {}

const errorEvent = await errorEventPromise;
const errorEventId = errorEvent.event_id;

await expect
.poll(
async () => {
try {
const response = await axios.get(
`https://sentry.io/api/0/projects/${sentryTestOrgSlug}/${sentryTestProject}/events/${errorEventId}/`,
{ headers: { Authorization: `Bearer ${authToken}` } },
);

return response.status;
} catch (e) {
if (e instanceof AxiosError && e.response) {
if (e.response.status !== 404) {
throw e;
} else {
return e.response.status;
}
} else {
throw e;
}
}
},
{
timeout: EVENT_POLLING_TIMEOUT,
},
)
.toBe(200);
});

test('sends error with parameterized transaction name', async ({ baseURL }) => {
const errorEventPromise = waitForError('node-hapi', errorEvent => {
return errorEvent?.exception?.values?.[0]?.value === 'This is an error with id 123';
});

try {
await axios.get(`${baseURL}/test-error/123`);
} catch {}

const errorEvent = await errorEventPromise;

expect(errorEvent?.transaction).toBe('GET /test-error/{id}');
});
Loading
Loading