import { ExceptionFilter, Catch, ArgumentsHost } from '@nestjs/common'; import { BaseExceptionFilter } from '@nestjs/core'; import * as Sentry from '@sentry/node'; @Catch() export class SentryExceptionFilter extends BaseExceptionFilter implements ExceptionFilter { catch(exception: any, host: ArgumentsHost) { Sentry.captureException(exception); super.catch(exception, host); } } ``` --- `src/ngsentry/ngsentry.interceptor.ts` ```ts import { CallHandler, ExecutionContext, Injectable, NestInterceptor, Scope, } from '@nestjs/common'; import * as Sentry from '@sentry/node'; import { catchError, finalize, Observable, throwError } from 'rxjs'; import { NgSentryService } from './ngsentry.service'; /** * We must be in Request scope as we inject SentryService */ @Injectable({ scope: Scope.REQUEST }) export class NgSentryInterceptor implements NestInterceptor { constructor(private sentryService: NgSentryService) {} intercept(context: ExecutionContext, next: CallHandler): Observable { // start a child span for performance tracing const span = this.sentryService.startChild({ op: `route handler` }); return next.handle().pipe( catchError(error => { // capture the error, you can filter out some errors here Sentry.captureException( error, this.sentryService.span.getTraceContext(), ); // throw again the error return throwError(() => error); }), finalize(() => { span.finish(); this.sentryService.span.finish(); }), ); } }