diff --git a/dev-packages/e2e-tests/test-applications/nestjs-fastify/src/app.controller.ts b/dev-packages/e2e-tests/test-applications/nestjs-fastify/src/app.controller.ts index 33a6b1957d99..ca29bb9fb9ae 100644 --- a/dev-packages/e2e-tests/test-applications/nestjs-fastify/src/app.controller.ts +++ b/dev-packages/e2e-tests/test-applications/nestjs-fastify/src/app.controller.ts @@ -1,4 +1,4 @@ -import { Controller, Get, Param, ParseIntPipe, UseFilters, UseGuards, UseInterceptors } from '@nestjs/common'; +import { All, Controller, Get, Param, ParseIntPipe, UseFilters, UseGuards, UseInterceptors } from '@nestjs/common'; import { flush } from '@sentry/nestjs'; import { AppService } from './app.service'; import { AsyncInterceptor } from './async-example.interceptor'; @@ -121,4 +121,9 @@ export class AppController { testFunctionName() { return this.appService.getFunctionName(); } + + @All('test-all') + testAll() { + return {}; + } } diff --git a/dev-packages/e2e-tests/test-applications/nestjs-fastify/tests/transactions.test.ts b/dev-packages/e2e-tests/test-applications/nestjs-fastify/tests/transactions.test.ts index 609e01709650..96b60e5d976f 100644 --- a/dev-packages/e2e-tests/test-applications/nestjs-fastify/tests/transactions.test.ts +++ b/dev-packages/e2e-tests/test-applications/nestjs-fastify/tests/transactions.test.ts @@ -808,3 +808,8 @@ test('Calling canActivate method on service with Injectable decorator returns 20 const response = await fetch(`${baseURL}/test-service-canActivate`); expect(response.status).toBe(200); }); + +test('Calling @All method on service with Injectable decorator returns 200', async ({ baseURL }) => { + const response = await fetch(`${baseURL}/test-all`); + expect(response.status).toBe(200); +}); diff --git a/packages/nestjs/src/setup.ts b/packages/nestjs/src/setup.ts index e75054d3391d..a32751c22ae4 100644 --- a/packages/nestjs/src/setup.ts +++ b/packages/nestjs/src/setup.ts @@ -27,9 +27,9 @@ import { isExpectedError } from './helpers'; // https://github.com/fastify/fastify/blob/87f9f20687c938828f1138f91682d568d2a31e53/types/request.d.ts#L41 interface FastifyRequest { routeOptions?: { - method?: string; url?: string; }; + method?: string; } // Partial extract of ExpressRequest interface @@ -72,9 +72,7 @@ class SentryTracingInterceptor implements NestInterceptor { const req = context.switchToHttp().getRequest() as FastifyRequest | ExpressRequest; if ('routeOptions' in req && req.routeOptions && req.routeOptions.url) { // fastify case - getIsolationScope().setTransactionName( - `${(req.routeOptions.method || 'GET').toUpperCase()} ${req.routeOptions.url}`, - ); + getIsolationScope().setTransactionName(`${(req.method || 'GET').toUpperCase()} ${req.routeOptions.url}`); } else if ('route' in req && req.route && req.route.path) { // express case getIsolationScope().setTransactionName(`${(req.method || 'GET').toUpperCase()} ${req.route.path}`); diff --git a/packages/node/src/integrations/tracing/fastify.ts b/packages/node/src/integrations/tracing/fastify.ts index a87980045b54..92936b5d6ee8 100644 --- a/packages/node/src/integrations/tracing/fastify.ts +++ b/packages/node/src/integrations/tracing/fastify.ts @@ -25,10 +25,10 @@ interface Fastify { * Works for Fastify 3, 4 and presumably 5. */ interface FastifyRequestRouteInfo { + method?: string; // since fastify@4.10.0 routeOptions?: { url?: string; - method?: string; }; routerPath?: string; } @@ -107,7 +107,7 @@ export function setupFastifyErrorHandler(fastify: Fastify): void { // Taken from Otel Fastify instrumentation: // https://github.com/open-telemetry/opentelemetry-js-contrib/blob/main/plugins/node/opentelemetry-instrumentation-fastify/src/instrumentation.ts#L94-L96 const routeName = reqWithRouteInfo.routeOptions?.url || reqWithRouteInfo.routerPath; - const method = reqWithRouteInfo.routeOptions?.method || 'GET'; + const method = reqWithRouteInfo.method || 'GET'; getIsolationScope().setTransactionName(`${method} ${routeName}`); }); diff --git a/packages/node/src/integrations/tracing/nest/nest.ts b/packages/node/src/integrations/tracing/nest/nest.ts index b5c9ea4bb61f..0b5be4cc116a 100644 --- a/packages/node/src/integrations/tracing/nest/nest.ts +++ b/packages/node/src/integrations/tracing/nest/nest.ts @@ -91,9 +91,7 @@ export function setupNestErrorHandler(app: MinimalNestJsApp, baseFilter: NestJsE const req = context.switchToHttp().getRequest(); if ('routeOptions' in req && req.routeOptions && req.routeOptions.url) { // fastify case - getIsolationScope().setTransactionName( - `${req.routeOptions.method?.toUpperCase() || 'GET'} ${req.routeOptions.url}`, - ); + getIsolationScope().setTransactionName(`${req.method?.toUpperCase() || 'GET'} ${req.routeOptions.url}`); } else if ('route' in req && req.route && req.route.path) { // express case getIsolationScope().setTransactionName(`${req.method?.toUpperCase() || 'GET'} ${req.route.path}`); diff --git a/packages/node/src/integrations/tracing/nest/types.ts b/packages/node/src/integrations/tracing/nest/types.ts index a983832ac8c6..8283e652edfb 100644 --- a/packages/node/src/integrations/tracing/nest/types.ts +++ b/packages/node/src/integrations/tracing/nest/types.ts @@ -4,9 +4,9 @@ // https://github.com/fastify/fastify/blob/87f9f20687c938828f1138f91682d568d2a31e53/types/request.d.ts#L41 interface FastifyRequest { routeOptions?: { - method?: string; url?: string; }; + method?: string; } // Partial extract of ExpressRequest interface