From e1515b69ad5089df7ec4ddd1972787b7837f7a99 Mon Sep 17 00:00:00 2001 From: Luca Forstner Date: Fri, 15 Nov 2024 14:26:17 +0100 Subject: [PATCH 1/3] Suggest using `SentryExceptionCaptured` instead of `WithSentry` --- .../getting-started-use/javascript.nestjs.mdx | 35 ++++++++++--------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/platform-includes/getting-started-use/javascript.nestjs.mdx b/platform-includes/getting-started-use/javascript.nestjs.mdx index 0c94c841ef363..ebf26ee05fe1e 100644 --- a/platform-includes/getting-started-use/javascript.nestjs.mdx +++ b/platform-includes/getting-started-use/javascript.nestjs.mdx @@ -1,10 +1,10 @@ ```javascript {filename: main.ts} // Import this first! -import './instrument'; +import "./instrument"; // Now import other modules -import { NestFactory } from '@nestjs/core'; -import { AppModule } from './app.module'; +import { NestFactory } from "@nestjs/core"; +import { AppModule } from "./app.module"; async function bootstrap() { const app = await NestFactory.create(AppModule); @@ -17,15 +17,15 @@ bootstrap(); Afterwards, add the `SentryModule` as a root module to your main module: ```javascript {filename: app.module.ts} {2, 8} -import { Module } from '@nestjs/common'; -import { SentryModule } from '@sentry/nestjs/setup'; -import { AppController } from './app.controller'; -import { AppService } from './app.service'; +import { Module } from "@nestjs/common"; +import { SentryModule } from "@sentry/nestjs/setup"; +import { AppController } from "./app.controller"; +import { AppService } from "./app.service"; @Module({ imports: [ - SentryModule.forRoot(), - // ...other modules + SentryModule.forRoot(), + // ...other modules ], controllers: [AppController], providers: [AppService], @@ -33,10 +33,8 @@ import { AppService } from './app.service'; export class AppModule {} ``` -In case you are using a global catch-all exception filter (which is either a filter registered with -`app.useGlobalFilters()` or a filter registered in your app module providers annotated with a `@Catch()` decorator -without arguments), add a `@WithSentry()` decorator to the `catch()` method of this global error filter. This decorator -will report all unexpected errors that are received by your global error filter to Sentry: +In case you are using a global catch-all exception filter (which is either a filter registered with `app.useGlobalFilters()` or a filter registered in your app module providers annotated with a `@Catch()` decorator without arguments), add a `@SentryExceptionCaptured()` decorator to the `catch()` method of this global error filter. +This decorator will report all unexpected errors that are received by your global error filter to Sentry: ```javascript {2, 6} import { Catch, ExceptionFilter } from '@nestjs/common'; @@ -44,21 +42,24 @@ import { WithSentry } from '@sentry/nestjs'; @Catch() export class YourCatchAllExceptionFilter implements ExceptionFilter { - @WithSentry() + @SentryExceptionCaptured() catch(exception, host): void { // your implementation here } } ``` +{/* TODO(v9): Remove this note */} +_Note that `@SentryExceptionCaptured()` was called `@WithSentry` in SDK versions `8.38.0` and prior._ + In case you do not have a global catch-all exception filter, add the `SentryGlobalFilter` to the providers of your main module. This filter will report all unhandled errors to Sentry that are not caught by any other error filter. **Important:** The `SentryGlobalFilter` needs to be registered before any other exception filters. ```javascript {3, 9} -import { Module } from '@nestjs/common'; -import { APP_FILTER } from '@nestjs/core'; -import { SentryGlobalFilter } from '@sentry/nestjs/setup'; +import { Module } from "@nestjs/common"; +import { APP_FILTER } from "@nestjs/core"; +import { SentryGlobalFilter } from "@sentry/nestjs/setup"; @Module({ providers: [ From fdf7a7a52cf0edb9592d5671a7514407fdb6183e Mon Sep 17 00:00:00 2001 From: Luca Forstner Date: Fri, 15 Nov 2024 14:27:19 +0100 Subject: [PATCH 2/3] . --- platform-includes/getting-started-use/javascript.nestjs.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platform-includes/getting-started-use/javascript.nestjs.mdx b/platform-includes/getting-started-use/javascript.nestjs.mdx index ebf26ee05fe1e..22ed5b7d68e15 100644 --- a/platform-includes/getting-started-use/javascript.nestjs.mdx +++ b/platform-includes/getting-started-use/javascript.nestjs.mdx @@ -38,7 +38,7 @@ This decorator will report all unexpected errors that are received by your globa ```javascript {2, 6} import { Catch, ExceptionFilter } from '@nestjs/common'; -import { WithSentry } from '@sentry/nestjs'; +import { SentryExceptionCaptured } from '@sentry/nestjs'; @Catch() export class YourCatchAllExceptionFilter implements ExceptionFilter { From 2efb9d1ca1ad2634267ef8f342402a0c8da540d3 Mon Sep 17 00:00:00 2001 From: Luca Forstner Date: Tue, 19 Nov 2024 10:01:34 +0100 Subject: [PATCH 3/3] Review feedback --- platform-includes/getting-started-use/javascript.nestjs.mdx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/platform-includes/getting-started-use/javascript.nestjs.mdx b/platform-includes/getting-started-use/javascript.nestjs.mdx index 22ed5b7d68e15..ef34c41d8c4af 100644 --- a/platform-includes/getting-started-use/javascript.nestjs.mdx +++ b/platform-includes/getting-started-use/javascript.nestjs.mdx @@ -33,7 +33,7 @@ import { AppService } from "./app.service"; export class AppModule {} ``` -In case you are using a global catch-all exception filter (which is either a filter registered with `app.useGlobalFilters()` or a filter registered in your app module providers annotated with a `@Catch()` decorator without arguments), add a `@SentryExceptionCaptured()` decorator to the `catch()` method of this global error filter. +If you're using a global catch-all exception filter (which is either a filter registered with `app.useGlobalFilters()` or a filter registered in your app module providers annotated with a `@Catch()` decorator without arguments), add a `@SentryExceptionCaptured()` decorator to the filter's `catch()` method. This decorator will report all unexpected errors that are received by your global error filter to Sentry: ```javascript {2, 6} @@ -52,8 +52,8 @@ export class YourCatchAllExceptionFilter implements ExceptionFilter { {/* TODO(v9): Remove this note */} _Note that `@SentryExceptionCaptured()` was called `@WithSentry` in SDK versions `8.38.0` and prior._ -In case you do not have a global catch-all exception filter, add the `SentryGlobalFilter` to the providers of your main -module. This filter will report all unhandled errors to Sentry that are not caught by any other error filter. +If you don't have a global catch-all exception filter, add the `SentryGlobalFilter` to the providers of your main module. +This filter will report any unhandled errors that aren't caught by other error filters to Sentry. **Important:** The `SentryGlobalFilter` needs to be registered before any other exception filters. ```javascript {3, 9}