Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs(nestjs): Update NestJS setup + event emitter #11830

Merged
merged 11 commits into from
Nov 22, 2024
18 changes: 18 additions & 0 deletions docs/platforms/javascript/guides/nestjs/features/event-emitter.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
title: NestJS Event Emitter
description: "Learn about instrumenting NestJS event-based services."
---

<Note>
The @nestjs/event-emitter module is auto-instrumented in `@sentry/nestjs` 8.39.0 and up.
</Note>

The NestJS SDK wraps the `@OnEvent` decorator automatically to:

- Create performance traces for event handler executions.
- Automatically capture any unhandled exceptions that occur in event handlers.
- Maintain visibility into asynchronous event-driven flows.

When an event handler is executed, a new span is created to track its performance, and any errors are automatically reported to Sentry while preserving the original error behavior.

This instrumentation works transparently with existing NestJS event handlers without requiring any code changes to your application.
17 changes: 9 additions & 8 deletions platform-includes/getting-started-config/javascript.nestjs.mdx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
```javascript {tabTitle:CommonJS} {filename: instrument.js} {"onboardingOptions": {"performance": "11-14", "profiling": "2, 7-10, 15-18"}}
const Sentry = require("@sentry/nestjs");
const { nodeProfilingIntegration } = require("@sentry/profiling-node");
```javascript {tabTitle:ESM} {filename: instrument.mjs} {"onboardingOptions": {"performance": "11-14", "profiling": "2, 7-10, 15-18"}}
import * as Sentry from "@sentry/nestjs";
import { nodeProfilingIntegration } from '@sentry/profiling-node';

// Ensure to call this before requiring any other modules!
// Ensure to call this before importing any other modules!
Sentry.init({
dsn: "___PUBLIC_DSN___",
integrations: [
Expand All @@ -20,11 +20,11 @@ Sentry.init({
});
```

```javascript {tabTitle:ESM} {filename: instrument.mjs} {"onboardingOptions": {"performance": "11-14", "profiling": "2, 7-10, 15-18"}}
import * as Sentry from "@sentry/nestjs";
import { nodeProfilingIntegration } from '@sentry/profiling-node';
```javascript {tabTitle:CommonJS} {filename: instrument.js} {"onboardingOptions": {"performance": "11-14", "profiling": "2, 7-10, 15-18"}}
const Sentry = require("@sentry/nestjs");
const { nodeProfilingIntegration } = require("@sentry/profiling-node");

// Ensure to call this before importing any other modules!
// Ensure to call this before requiring any other modules!
Sentry.init({
dsn: "___PUBLIC_DSN___",
integrations: [
Expand All @@ -41,3 +41,4 @@ Sentry.init({
profilesSampleRate: 1.0,
});
```

Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export class YourCatchAllExceptionFilter implements ExceptionFilter {
}
```


{/* TODO(v9): Remove this note */}
_Note that `@SentryExceptionCaptured()` was called `@WithSentry` in SDK versions `8.38.0` and prior._

Expand All @@ -72,7 +73,6 @@ import { SentryGlobalFilter } from "@sentry/nestjs/setup";
})
export class AppModule {}
```

{/* TODO(v9): Remove this note. */}

**Note:** If you have a NestJS + GraphQL application and you are using the `@sentry/nestjs` SDK version `8.38.0` or earlier, replace the `SentryGlobalFilter` with the `SentryGlobalGenericFilter`.
Expand Down
Loading