From ca76fdb14f4bf2abdcf800c30ba2d9b9f25f7475 Mon Sep 17 00:00:00 2001 From: Charly Gomez Date: Tue, 15 Apr 2025 13:25:28 +0200 Subject: [PATCH 1/2] update nest docs --- .../getting-started-use/javascript.nestjs.mdx | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/platform-includes/getting-started-use/javascript.nestjs.mdx b/platform-includes/getting-started-use/javascript.nestjs.mdx index dff137e0dd33b..0b70396cfa4aa 100644 --- a/platform-includes/getting-started-use/javascript.nestjs.mdx +++ b/platform-includes/getting-started-use/javascript.nestjs.mdx @@ -73,6 +73,35 @@ import { SentryGlobalFilter } from "@sentry/nestjs/setup"; export class AppModule {} ``` + + +If you are using `@nestjs/microservices` you can also include our `SentryRpcFilter` to make sure to handle errors in RPC contexts correctly: + +```javascript {3-4, 8-15} +import { Module } from "@nestjs/common"; +import { APP_FILTER } from "@nestjs/core"; +import { SentryGlobalFilter } from "@sentry/nestjs/setup"; +import { SentryRpcFilter } from "@sentry/nestjs/microservices"; + +@Module({ + providers: [ + { + provide: APP_FILTER, + useClass: SentryGlobalFilter, + }, + { + provide: APP_FILTER, + useClass: SentryRpcFilter, + }, + // ..other providers + ], +}) +export class AppModule {} +``` + + + + If you have error filters for specific types of exceptions (for example `@Catch(HttpException)`, or any other `@Catch(...)` with arguments) and you want to capture errors caught by these filters, capture the errors in the `catch()` handler with `Sentry.captureException()`: ```javascript {9} From d0b8f4cb819a2dca3075e87a91ab79c798e87892 Mon Sep 17 00:00:00 2001 From: Charly Gomez Date: Thu, 17 Apr 2025 14:03:17 +0200 Subject: [PATCH 2/2] update --- .../getting-started-use/javascript.nestjs.mdx | 37 +++++++++---------- 1 file changed, 17 insertions(+), 20 deletions(-) diff --git a/platform-includes/getting-started-use/javascript.nestjs.mdx b/platform-includes/getting-started-use/javascript.nestjs.mdx index 0b70396cfa4aa..e18fc00fb03a2 100644 --- a/platform-includes/getting-started-use/javascript.nestjs.mdx +++ b/platform-includes/getting-started-use/javascript.nestjs.mdx @@ -75,30 +75,27 @@ export class AppModule {} -If you are using `@nestjs/microservices` you can also include our `SentryRpcFilter` to make sure to handle errors in RPC contexts correctly: +If you are using `@nestjs/microservices` make sure to handle errors in RPC contexts correctly by providing your own `RpcExceptionFilter` (see https://docs.nestjs.com/microservices/exception-filters). +`SentryGlobalFilter` in a [hybrid application](https://docs.nestjs.com/faq/hybrid-application) does not extend `BaseRpcExceptionFilter` since this depends on `@nestjs/microservices`. -```javascript {3-4, 8-15} -import { Module } from "@nestjs/common"; -import { APP_FILTER } from "@nestjs/core"; -import { SentryGlobalFilter } from "@sentry/nestjs/setup"; -import { SentryRpcFilter } from "@sentry/nestjs/microservices"; +Use `Sentry.captureException(exception)` in your custom filter in case you want to send these errors to Sentry: -@Module({ - providers: [ - { - provide: APP_FILTER, - useClass: SentryGlobalFilter, - }, - { - provide: APP_FILTER, - useClass: SentryRpcFilter, - }, - // ..other providers - ], -}) -export class AppModule {} +```typescript +import { Catch, RpcExceptionFilter, ArgumentsHost } from '@nestjs/common'; +import { Observable, throwError } from 'rxjs'; +import { RpcException } from '@nestjs/microservices'; +import * as Sentry from '@sentry/nestjs'; + +@Catch(RpcException) +export class ExceptionFilter implements RpcExceptionFilter { + catch(exception: RpcException, host: ArgumentsHost): Observable { + Sentry.captureException(exception); // optional + return throwError(() => exception.getError()); + } +} ``` +