Skip to content

Commit

Permalink
fix(nestjs): Ensure Nest.js interceptor works with non-http context (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
mydea committed May 3, 2024
1 parent 56197af commit fd10a2b
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions packages/node/src/integrations/tracing/nest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import type { IntegrationFn } from '@sentry/types';
import { logger } from '@sentry/utils';

interface MinimalNestJsExecutionContext {
getType: () => string;

switchToHttp: () => {
// minimal request object
// according to official types, all properties are required but
Expand Down Expand Up @@ -57,10 +59,13 @@ export function setupNestErrorHandler(app: MinimalNestJsApp, baseFilter: NestJsE
return next.handle();
}

const req = context.switchToHttp().getRequest();
if (req.route) {
getIsolationScope().setTransactionName(`${req.method?.toUpperCase() || 'GET'} ${req.route.path}`);
if (context.getType() === 'http') {
const req = context.switchToHttp().getRequest();
if (req.route) {
getIsolationScope().setTransactionName(`${req.method?.toUpperCase() || 'GET'} ${req.route.path}`);
}
}

return next.handle();
},
});
Expand Down

0 comments on commit fd10a2b

Please sign in to comment.