diff --git a/dev-packages/e2e-tests/test-applications/node-fastify-app/package.json b/dev-packages/e2e-tests/test-applications/node-fastify-app/package.json index 9e8779cf9bdd..56c8818933af 100644 --- a/dev-packages/e2e-tests/test-applications/node-fastify-app/package.json +++ b/dev-packages/e2e-tests/test-applications/node-fastify-app/package.json @@ -3,10 +3,11 @@ "version": "1.0.0", "private": true, "scripts": { - "start": "node src/app.js", + "start": "ts-node src/app.ts", "test": "playwright test", "clean": "npx rimraf node_modules pnpm-lock.yaml", - "test:build": "pnpm install", + "typecheck": "tsc", + "test:build": "pnpm install && pnpm run typecheck", "test:assert": "pnpm test" }, "dependencies": { diff --git a/dev-packages/e2e-tests/test-applications/node-fastify-app/src/app.js b/dev-packages/e2e-tests/test-applications/node-fastify-app/src/app.ts similarity index 71% rename from dev-packages/e2e-tests/test-applications/node-fastify-app/src/app.js rename to dev-packages/e2e-tests/test-applications/node-fastify-app/src/app.ts index dbb239a4e340..187d259b1f5b 100644 --- a/dev-packages/e2e-tests/test-applications/node-fastify-app/src/app.js +++ b/dev-packages/e2e-tests/test-applications/node-fastify-app/src/app.ts @@ -1,8 +1,21 @@ -require('./tracing'); +import type * as S from '@sentry/node'; +const Sentry = require('@sentry/node') as typeof S; + +Sentry.init({ + environment: 'qa', // dynamic sampling bias to keep transactions + dsn: process.env.E2E_TEST_DSN, + integrations: [], + tracesSampleRate: 1, + tunnel: 'http://localhost:3031/', // proxy server + tracePropagationTargets: ['http://localhost:3030', '/external-allowed'], +}); + +import type * as H from 'http'; +import type * as F from 'fastify'; -const Sentry = require('@sentry/node'); -const { fastify } = require('fastify'); -const http = require('http'); +// Make sure fastify is imported after Sentry is initialized +const { fastify } = require('fastify') as typeof F; +const http = require('http') as typeof H; const app = fastify(); const port = 3030; @@ -10,28 +23,28 @@ const port2 = 3040; Sentry.setupFastifyErrorHandler(app); -app.get('/test-success', function (req, res) { +app.get('/test-success', function (_req, res) { res.send({ version: 'v1' }); }); -app.get('/test-param/:param', function (req, res) { +app.get<{ Params: { param: string } }>('/test-param/:param', function (req, res) { res.send({ paramWas: req.params.param }); }); -app.get('/test-inbound-headers/:id', function (req, res) { +app.get<{ Params: { id: string } }>('/test-inbound-headers/:id', function (req, res) { const headers = req.headers; res.send({ headers, id: req.params.id }); }); -app.get('/test-outgoing-http/:id', async function (req, res) { +app.get<{ Params: { id: string } }>('/test-outgoing-http/:id', async function (req, res) { const id = req.params.id; const data = await makeHttpRequest(`http://localhost:3030/test-inbound-headers/${id}`); res.send(data); }); -app.get('/test-outgoing-fetch/:id', async function (req, res) { +app.get<{ Params: { id: string } }>('/test-outgoing-fetch/:id', async function (req, res) { const id = req.params.id; const response = await fetch(`http://localhost:3030/test-inbound-headers/${id}`); const data = await response.json(); @@ -55,7 +68,7 @@ app.get('/test-error', async function (req, res) { res.send({ exceptionId }); }); -app.get('/test-exception/:id', async function (req, res) { +app.get<{ Params: { id: string } }>('/test-exception/:id', async function (req, res) { throw new Error(`This is an exception with id ${req.params.id}`); }); @@ -101,9 +114,9 @@ app2.get('/external-disallowed', function (req, res) { app2.listen({ port: port2 }); -function makeHttpRequest(url) { +function makeHttpRequest(url: string) { return new Promise(resolve => { - const data = []; + const data: any[] = []; http .request(url, httpRes => { diff --git a/dev-packages/e2e-tests/test-applications/node-fastify-app/src/tracing.js b/dev-packages/e2e-tests/test-applications/node-fastify-app/src/tracing.js deleted file mode 100644 index 136b401cbd73..000000000000 --- a/dev-packages/e2e-tests/test-applications/node-fastify-app/src/tracing.js +++ /dev/null @@ -1,10 +0,0 @@ -const Sentry = require('@sentry/node'); - -Sentry.init({ - environment: 'qa', // dynamic sampling bias to keep transactions - dsn: process.env.E2E_TEST_DSN, - integrations: [], - tracesSampleRate: 1, - tunnel: 'http://localhost:3031/', // proxy server - tracePropagationTargets: ['http://localhost:3030', '/external-allowed'], -}); diff --git a/packages/node/src/integrations/tracing/fastify.ts b/packages/node/src/integrations/tracing/fastify.ts index 87a820bd238e..aa2b2f275525 100644 --- a/packages/node/src/integrations/tracing/fastify.ts +++ b/packages/node/src/integrations/tracing/fastify.ts @@ -31,8 +31,10 @@ export const fastifyIntegration = defineIntegration(_fastifyIntegration); // We inline the types we care about here interface Fastify { - register: (plugin: unknown) => void; - addHook: (hook: string, handler: (request: unknown, reply: unknown, error: Error) => void) => void; + // eslint-disable-next-line @typescript-eslint/no-explicit-any + register: (plugin: any) => void; + // eslint-disable-next-line @typescript-eslint/no-explicit-any + addHook: (hook: string, handler: (request: any, reply: any, error: Error) => void) => void; } /** @@ -53,7 +55,7 @@ interface FastifyRequestRouteInfo { */ export function setupFastifyErrorHandler(fastify: Fastify): void { const plugin = Object.assign( - function (fastify: Fastify, options: unknown, done: () => void): void { + function (fastify: Fastify, _options: unknown, done: () => void): void { fastify.addHook('onError', async (_request, _reply, error) => { captureException(error); });