Skip to content

Commit bb448d1

Browse files
committed
PR feedback
1 parent 90ab40a commit bb448d1

File tree

3 files changed

+71
-133
lines changed

3 files changed

+71
-133
lines changed

docs/platforms/javascript/common/install/commonjs.mdx

Lines changed: 1 addition & 115 deletions
Original file line numberDiff line numberDiff line change
@@ -27,118 +27,4 @@ You need to create a file named `instrument.js` that imports and initializes Sen
2727

2828
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:
2929

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-
async function bootstrap() {
39-
const app = await NestFactory.create(AppModule);
40-
await app.listen(3000);
41-
}
42-
43-
bootstrap();
44-
```
45-
46-
Afterwards, add the `SentryModule` as a root module to your main module:
47-
48-
```javascript {filename: app.module.ts} {2, 8}
49-
import { Module } from "@nestjs/common";
50-
import { SentryModule } from "@sentry/nestjs/setup";
51-
import { AppController } from "./app.controller";
52-
import { AppService } from "./app.service";
53-
54-
@Module({
55-
imports: [
56-
SentryModule.forRoot(),
57-
// ...other modules
58-
],
59-
controllers: [AppController],
60-
providers: [AppService],
61-
})
62-
export class AppModule {}
63-
```
64-
65-
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:
67-
68-
```javascript {2, 6}
69-
import { Catch, ExceptionFilter } from '@nestjs/common';
70-
import { SentryExceptionCaptured } from '@sentry/nestjs';
71-
72-
@Catch()
73-
export class YourCatchAllExceptionFilter implements ExceptionFilter {
74-
@SentryExceptionCaptured()
75-
catch(exception, host): void {
76-
// your implementation here
77-
}
78-
}
79-
```
80-
81-
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.
87-
88-
```javascript {3, 9}
89-
import { Module } from "@nestjs/common";
90-
import { APP_FILTER } from "@nestjs/core";
91-
import { SentryGlobalFilter } from "@sentry/nestjs/setup";
92-
93-
@Module({
94-
providers: [
95-
{
96-
provide: APP_FILTER,
97-
useClass: SentryGlobalFilter,
98-
},
99-
// ..other providers
100-
],
101-
})
102-
export class AppModule {}
103-
```
104-
105-
<Expandable title="Using Microservices?">
106-
107-
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:
111-
112-
```typescript
113-
import { Catch, RpcExceptionFilter, ArgumentsHost } from "@nestjs/common";
114-
import { Observable, throwError } from "rxjs";
115-
import { RpcException } from "@nestjs/microservices";
116-
import * as Sentry from "@sentry/nestjs";
117-
118-
@Catch(RpcException)
119-
export class ExceptionFilter implements RpcExceptionFilter<RpcException> {
120-
catch(exception: RpcException, host: ArgumentsHost): Observable<any> {
121-
Sentry.captureException(exception); // optional
122-
return throwError(() => exception.getError());
123-
}
124-
}
125-
```
126-
127-
</Expandable>
128-
129-
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()`:
130-
131-
```javascript {9}
132-
import { ArgumentsHost, BadRequestException, Catch } from '@nestjs/common';
133-
import { BaseExceptionFilter } from '@nestjs/core';
134-
import { ExampleException } from './example.exception';
135-
import * as Sentry from '@sentry/nestjs';
136-
137-
@Catch(ExampleException)
138-
export class ExampleExceptionFilter extends BaseExceptionFilter {
139-
catch(exception: unknown, host: ArgumentsHost) {
140-
Sentry.captureException(exception);
141-
return super.catch(new BadRequestException(exception.message), host)
142-
}
143-
}
144-
```
30+
<PlatformContent includePath="getting-started-use" />

platform-includes/getting-started-use/javascript.nestjs.mdx

Lines changed: 65 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
```javascript {filename: main.ts}
1+
<PlatformContent includePath="getting-started-config" />
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}
26
// Import this first!
37
import "./instrument";
48

@@ -14,7 +18,7 @@ async function bootstrap() {
1418
bootstrap();
1519
```
1620

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:
1822

1923
```javascript {filename: app.module.ts} {2, 8}
2024
import { Module } from "@nestjs/common";
@@ -33,17 +37,30 @@ import { AppService } from "./app.service";
3337
export class AppModule {}
3438
```
3539

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:
3742

38-
##### Basic Error Capture
43+
```javascript {2, 6}
44+
import { Catch, ExceptionFilter } from '@nestjs/common';
45+
import { SentryExceptionCaptured } from '@sentry/nestjs';
46+
47+
@Catch()
48+
export class YourCatchAllExceptionFilter implements ExceptionFilter {
49+
@SentryExceptionCaptured()
50+
catch(exception, host): void {
51+
// your implementation here
52+
}
53+
}
54+
```
3955

40-
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.
4158

42-
<Alert level="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.
4562

46-
```javascript {3, 9}
63+
```javascript {2-3, 7-10}
4764
import { Module } from "@nestjs/common";
4865
import { APP_FILTER } from "@nestjs/core";
4966
import { SentryGlobalFilter } from "@sentry/nestjs/setup";
@@ -60,6 +77,43 @@ import { SentryGlobalFilter } from "@sentry/nestjs/setup";
6077
export class AppModule {}
6178
```
6279

63-
##### Fine-Tuning Error Capture
80+
<Expandable title="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:
86+
87+
```typescript
88+
import { Catch, RpcExceptionFilter, ArgumentsHost } from "@nestjs/common";
89+
import { Observable, throwError } from "rxjs";
90+
import { RpcException } from "@nestjs/microservices";
91+
import * as Sentry from "@sentry/nestjs";
92+
93+
@Catch(RpcException)
94+
export class ExceptionFilter implements RpcExceptionFilter<RpcException> {
95+
catch(exception: RpcException, host: ArgumentsHost): Observable<any> {
96+
Sentry.captureException(exception); // optional
97+
return throwError(() => exception.getError());
98+
}
99+
}
100+
```
101+
102+
</Expandable>
64103

65-
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()`:
105+
106+
```javascript {4-9}
107+
import { ArgumentsHost, BadRequestException, Catch } from '@nestjs/common';
108+
import { BaseExceptionFilter } from '@nestjs/core';
109+
import { ExampleException } from './example.exception';
110+
import * as Sentry from '@sentry/nestjs';
111+
112+
@Catch(ExampleException)
113+
export class ExampleExceptionFilter extends BaseExceptionFilter {
114+
catch(exception: unknown, host: ArgumentsHost) {
115+
Sentry.captureException(exception);
116+
return super.catch(new BadRequestException(exception.message), host)
117+
}
118+
}
119+
```

platform-includes/getting-started-verify/javascript.nestjs.mdx

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,11 @@ First, let's verify that Sentry captures errors and creates issues in your Sentr
55
```javascript
66
@Get("/debug-sentry")
77
getError() {
8-
setTimeout(() => {
9-
try {
10-
foo();
11-
} catch (e) {
12-
Sentry.captureException(e);
13-
}
14-
}, 99);
8+
try {
9+
foo();
10+
} catch (e) {
11+
Sentry.captureException(e);
12+
}
1513
}
1614
```
1715

0 commit comments

Comments
 (0)