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
By default, Sentry only captures unhandled exceptions that aren't caught by an error filter.
45
+
Additionally, `HttpException`s (including [derivatives](https://docs.nestjs.com/exception-filters#built-in-http-exceptions)) aren't captured by default because they mostly act as control flow vehicles.
46
+
47
+
To make sure Sentry captures all your app's errors, configure error handling based on how your application manages exceptions:
48
+
49
+
### Using a Global Catch-All Exception Filter
50
+
51
+
If you have a global catch-all exception filter, add a `@SentryExceptionCaptured()` decorator to the filter's `catch()` method:
If you don't have a global catch-all exception filter, add the `SentryGlobalFilter` to the providers of your main module, **before** any other exception filters:
### Using Error Filters for Specific Exception Types
88
+
89
+
If you have error filters for specific types of exceptions (for example, `@Catch(HttpException)`) and you want to report these errors to Sentry, you need to capture them in the `catch()` handler using `Sentry.captureException()`:
If you're using `@nestjs/microservices` make sure to handle errors in RPC contexts correctly by providing your own `RpcExceptionFilter` (see [Nest.js Microservices documentation](https://docs.nestjs.com/microservices/exception-filters)).
108
+
`SentryGlobalFilter` in a [hybrid application](https://docs.nestjs.com/faq/hybrid-application) doesn't 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:
Make sure to import the `instrument.ts` file before any other modules:
2
2
3
-
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}
3
+
```typescript {filename: main.ts} {1-2}
6
4
// Import this first!
7
5
import"./instrument";
8
6
@@ -18,9 +16,9 @@ async function bootstrap() {
18
16
bootstrap();
19
17
```
20
18
21
-
Afterwards, add the `SentryModule` as a root module to your main module:
19
+
Afterward, add the `SentryModule` as a root module to your main module:
@@ -36,84 +34,3 @@ import { AppService } from "./app.service";
36
34
})
37
35
exportclassAppModule {}
38
36
```
39
-
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:
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.
58
-
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.
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:
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()`:
Copy file name to clipboardExpand all lines: platform-includes/getting-started-verify/javascript.nestjs.mdx
+3-11Lines changed: 3 additions & 11 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,15 +1,11 @@
1
1
### Issues
2
2
3
-
First, let's verify that Sentry captures errors and creates issues in your Sentry project. Add the following route to your application, which will call an undefined function, triggering an error that Sentry will capture:
3
+
First, let's verify that Sentry captures errors and creates issues in your Sentry project. Add the following route to your application, which will trigger an error that Sentry will capture:
4
4
5
5
```javascript
6
6
@Get("/debug-sentry")
7
7
getError() {
8
-
try {
9
-
foo();
10
-
} catch (e) {
11
-
Sentry.captureException(e);
12
-
}
8
+
thrownewError("My first Sentry error!");
13
9
}
14
10
```
15
11
@@ -28,11 +24,7 @@ To test your tracing configuration, update the previous code snippet by starting
0 commit comments