You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/platforms/javascript/common/install/commonjs.mdx
+1-115Lines changed: 1 addition & 115 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -27,118 +27,4 @@ You need to create a file named `instrument.js` that imports and initializes Sen
27
27
28
28
You need to require or import the `instrument.js` file before requiring any other modules in your application. This is necessary to ensure that Sentry can automatically instrument all modules in your application:
29
29
30
-
```javascript {filename: main.ts}
31
-
// Import this first!
32
-
import"./instrument";
33
-
34
-
// Now import other modules
35
-
import { NestFactory } from"@nestjs/core";
36
-
import { AppModule } from"./app.module";
37
-
38
-
asyncfunctionbootstrap() {
39
-
constapp=awaitNestFactory.create(AppModule);
40
-
awaitapp.listen(3000);
41
-
}
42
-
43
-
bootstrap();
44
-
```
45
-
46
-
Afterwards, add the `SentryModule` as a root module to your main module:
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.
66
-
This decorator will report all unexpected errors that are received by your global error filter to Sentry:
By default, only unhandled exceptions that are not caught by an error filter are reported to Sentry.
82
-
`HttpException`s (including [derivatives](https://docs.nestjs.com/exception-filters#built-in-http-exceptions)) are also not captured by default because they mostly act as control flow vehicles.
83
-
84
-
If you don't have a global catch-all exception filter, add the `SentryGlobalFilter` to the providers of your main module.
85
-
This filter will report any unhandled errors that aren't caught by other error filters to Sentry.
86
-
**Important:** The `SentryGlobalFilter` needs to be registered before any other exception filters.
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).
108
-
`SentryGlobalFilter` in a [hybrid application](https://docs.nestjs.com/faq/hybrid-application) does not extend `BaseRpcExceptionFilter` since this depends on `@nestjs/microservices`.
109
-
110
-
Use `Sentry.captureException(exception)` in your custom filter in case you want to send these errors to Sentry:
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()`:
You need to require or import the `instrument.js` file before requiring any other modules in your application. This is necessary to ensure that Sentry can automatically instrument all modules in your application:
4
+
5
+
```javascript {filename: main.ts} {1-2}
2
6
// Import this first!
3
7
import"./instrument";
4
8
@@ -14,7 +18,7 @@ async function bootstrap() {
14
18
bootstrap();
15
19
```
16
20
17
-
Afterward, add the `SentryModule` as a root module to your main module:
21
+
Afterwards, add the `SentryModule` as a root module to your main module:
18
22
19
23
```javascript {filename: app.module.ts} {2, 8}
20
24
import { Module } from"@nestjs/common";
@@ -33,17 +37,30 @@ import { AppService } from "./app.service";
33
37
exportclassAppModule {}
34
38
```
35
39
36
-
By default, only unhandled exceptions that are not caught by an error filter are reported to Sentry. Additionally, `HttpException`s (including [derivatives](https://docs.nestjs.com/exception-filters#built-in-http-exceptions)) are not captured automatically as they mostly act as control flow vehicles.
40
+
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.
41
+
This decorator will report all unexpected errors that are received by your global error filter to Sentry:
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.
56
+
By default, only unhandled exceptions that are not caught by an error filter are reported to Sentry.
57
+
`HttpException`s (including [derivatives](https://docs.nestjs.com/exception-filters#built-in-http-exceptions)) are also not captured by default because they mostly act as control flow vehicles.
41
58
42
-
<Alertlevel="warning"title="Important">
43
-
Make sure to register `SentryGlobalFilter` before any other exception filters.
44
-
</Alert>
59
+
If you don't have a global catch-all exception filter, add the `SentryGlobalFilter` to the providers of your main module.
60
+
This filter will report any unhandled errors that aren't caught by other error filters to Sentry.
61
+
**Important:** The `SentryGlobalFilter` needs to be registered before any other exception filters.
@@ -60,6 +77,43 @@ import { SentryGlobalFilter } from "@sentry/nestjs/setup";
60
77
exportclassAppModule {}
61
78
```
62
79
63
-
##### Fine-Tuning Error Capture
80
+
<Expandabletitle="Are you using Microservices?">
81
+
82
+
If you're 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).
83
+
`SentryGlobalFilter` in a [hybrid application](https://docs.nestjs.com/faq/hybrid-application) does not extend `BaseRpcExceptionFilter` since this depends on `@nestjs/microservices`.
84
+
85
+
Use `Sentry.captureException(exception)` in your custom filter in case you want to send these errors to Sentry:
For more precise control over error reporting in global catch-all exception filters, specific exception filters, or microservices, check out our [CommonJS installation documentation](/platforms/javascript/guides/nestjs/install/commonjs/).
104
+
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()`:
0 commit comments