Skip to content

Commit 34a3e8f

Browse files
docs: minor content improvements
1 parent a74cc99 commit 34a3e8f

File tree

1 file changed

+12
-22
lines changed

1 file changed

+12
-22
lines changed

content/recipes/sentry.md

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,13 @@
66

77
First, install the required dependencies:
88

9-
109
```bash
1110
$ npm install --save @sentry/nestjs @sentry/profiling-node
1211
```
13-
> info **Hint** we support `yarn` and `pnpm` as well. @sentry/profiling-node is optional, but recommended for performance profiling.
1412

13+
> info **Hint** `@sentry/profiling-node` is optional, but recommended for performance profiling.
1514
16-
#### Basic Setup
15+
#### Basic setup
1716

1817
To get started with Sentry, you'll need to create a file named `instrument.js` that should be imported before any other modules in your application:
1918

@@ -38,14 +37,10 @@ Sentry.init({
3837
// This is relative to tracesSampleRate
3938
profilesSampleRate: 1.0,
4039
});
41-
42-
4340
```
4441

45-
4642
Update your `main.ts` file to import `instrument.js` before other imports:
4743

48-
4944
```typescript
5045
@@filename(main)
5146
// Import this first!
@@ -61,13 +56,11 @@ async function bootstrap() {
6156
}
6257

6358
bootstrap();
64-
6559
```
6660

6761
Afterwards, add the `SentryModule` as a root module to your main module:
6862

69-
70-
```typescript {2, 8}
63+
```typescript
7164
@@filename(app.module)
7265
import { Module } from "@nestjs/common";
7366
import { SentryModule } from "@sentry/nestjs/setup";
@@ -85,11 +78,11 @@ import { AppService } from "./app.service";
8578
export class AppModule {}
8679
```
8780

88-
#### Exception Handling
81+
#### Exception handling
8982

9083
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:
9184

92-
```typescript {2, 6}
85+
```typescript
9386
import { Catch, ExceptionFilter } from '@nestjs/common';
9487
import { SentryExceptionCaptured } from '@sentry/nestjs';
9588

@@ -104,15 +97,15 @@ export class YourCatchAllExceptionFilter implements ExceptionFilter {
10497

10598
By default, only unhandled exceptions that are not caught by an error filter are reported to Sentry. `HttpExceptions` (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.
10699

107-
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.
100+
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.
108101

109-
> warning **Important** The `SentryGlobalFilter` needs to be registered before any other exception filters.
102+
> warning **Warning** The `SentryGlobalFilter` needs to be registered before any other exception filters.
110103
111-
```typescript {3, 9}
104+
```typescript
112105
@@filename(app.module)
113106
import { Module } from "@nestjs/common";
114107
import { APP_FILTER } from "@nestjs/core";
115-
+import { SentryGlobalFilter } from "@sentry/nestjs/setup";
108+
import { SentryGlobalFilter } from "@sentry/nestjs/setup";
116109

117110
@Module({
118111
providers: [
@@ -126,7 +119,7 @@ import { APP_FILTER } from "@nestjs/core";
126119
export class AppModule {}
127120
```
128121

129-
#### Add Readable Stack Traces to Errors
122+
#### Readable stack traces
130123

131124
Depending on how you've set up your project, the stack traces in your Sentry errors probably won't look like your actual code.
132125

@@ -136,22 +129,19 @@ To fix this, upload your source maps to Sentry. The easiest way to do this is by
136129
npx @sentry/wizard@latest -i sourcemaps
137130
```
138131

139-
140-
#### Testing the Integration
132+
#### Testing the integration
141133

142134
To verify your Sentry integration is working, you can add a test endpoint that throws an error:
143135

144136
```typescript
145-
@Get("/debug-sentry")
137+
@Get("debug-sentry")
146138
getError() {
147139
throw new Error("My first Sentry error!");
148140
}
149-
150141
```
151142

152143
Visit `/debug-sentry` in your application, and you should see the error appear in your Sentry dashboard.
153144

154-
155145
### Summary
156146

157147
For complete documentation about Sentry's NestJS SDK, including advanced configuration options and features, visit the [official Sentry documentation](https://docs.sentry.io/platforms/javascript/guides/nestjs/).

0 commit comments

Comments
 (0)