@@ -22,6 +22,7 @@ import {
2222} from '@sentry/core' ;
2323import type { Observable } from 'rxjs' ;
2424import { isExpectedError } from './helpers' ;
25+ import type { FastifyRequest , ExpressRequest } from '@sentry/node' ;
2526
2627/**
2728 * Note: We cannot use @ syntax to add the decorators, so we add them directly below the classes as function wrappers.
@@ -52,18 +53,16 @@ class SentryTracingInterceptor implements NestInterceptor {
5253 }
5354
5455 if ( context . getType ( ) === 'http' ) {
55- const req = context . switchToHttp ( ) . getRequest ( ) ;
56- /* eslint-disable @typescript-eslint/no-unsafe-member-access, @sentry-internal/sdk/no-optional-chaining */
57- if ( req . routeOptions && req . routeOptions . url ) {
56+ const req = context . switchToHttp ( ) . getRequest ( ) as FastifyRequest | ExpressRequest ;
57+ if ( 'routeOptions' in req && req . routeOptions && req . routeOptions . url ) {
5858 // fastify case
5959 getIsolationScope ( ) . setTransactionName (
60- `${ req . routeOptions . method ?. toUpperCase ( ) || 'GET' } ${ req . routeOptions . url } ` ,
60+ `${ ( req . routeOptions . method || 'GET' ) . toUpperCase ( ) } ${ req . routeOptions . url } ` ,
6161 ) ;
62- } else if ( req . route && req . route . path ) {
62+ } else if ( 'route' in req && req . route && req . route . path ) {
6363 // express case
64- getIsolationScope ( ) . setTransactionName ( `${ req . method ?. toUpperCase ( ) || 'GET' } ${ req . route . path } ` ) ;
64+ getIsolationScope ( ) . setTransactionName ( `${ ( req . method || 'GET' ) . toUpperCase ( ) } ${ req . route . path } ` ) ;
6565 }
66- /* eslint-enable @typescript-eslint/no-unsafe-member-access, @sentry-internal/sdk/no-optional-chaining */
6766 }
6867
6968 return next . handle ( ) ;
0 commit comments