Skip to content

Commit fd10a2b

Browse files
authored
fix(nestjs): Ensure Nest.js interceptor works with non-http context (#11880)
Fixes #11877
1 parent 56197af commit fd10a2b

File tree

1 file changed

+8
-3
lines changed
  • packages/node/src/integrations/tracing

1 file changed

+8
-3
lines changed

packages/node/src/integrations/tracing/nest.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import type { IntegrationFn } from '@sentry/types';
55
import { logger } from '@sentry/utils';
66

77
interface MinimalNestJsExecutionContext {
8+
getType: () => string;
9+
810
switchToHttp: () => {
911
// minimal request object
1012
// according to official types, all properties are required but
@@ -57,10 +59,13 @@ export function setupNestErrorHandler(app: MinimalNestJsApp, baseFilter: NestJsE
5759
return next.handle();
5860
}
5961

60-
const req = context.switchToHttp().getRequest();
61-
if (req.route) {
62-
getIsolationScope().setTransactionName(`${req.method?.toUpperCase() || 'GET'} ${req.route.path}`);
62+
if (context.getType() === 'http') {
63+
const req = context.switchToHttp().getRequest();
64+
if (req.route) {
65+
getIsolationScope().setTransactionName(`${req.method?.toUpperCase() || 'GET'} ${req.route.path}`);
66+
}
6367
}
68+
6469
return next.handle();
6570
},
6671
});

0 commit comments

Comments
 (0)