Skip to content
Merged
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 from version `@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,
});
```

12 changes: 6 additions & 6 deletions platform-includes/getting-started-use/javascript.nestjs.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -51,28 +51,28 @@ export class YourCatchAllExceptionFilter implements ExceptionFilter {
}
```

In case you do not have a global catch-all exception filter, add the `SentryGlobalFilter` to the providers of your main
In case you do not have a global catch-all exception filter, add the `SentryGlobalGenericFilter` to the providers of your main
module. This filter will report all unhandled errors to Sentry that are not caught by any other error filter.
**Important:** The `SentryGlobalFilter` needs to be registered before any other exception filters.
**Important:** The `SentryGlobalGenericFilter` needs to be registered before any other exception filters.

```javascript {3, 9}
```javascript {filename: app.module.ts} {3, 9}
import { Module } from '@nestjs/common';
import { APP_FILTER } from '@nestjs/core';
import { SentryGlobalFilter } from '@sentry/nestjs/setup';
import { SentryGlobalGenericFilter } from '@sentry/nestjs/setup';

@Module({
providers: [
{
provide: APP_FILTER,
useClass: SentryGlobalFilter,
useClass: SentryGlobalGenericFilter,
},
// ..other providers
],
})
export class AppModule {}
```

**Note:** In NestJS + GraphQL applications replace the `SentryGlobalFilter` with the `SentryGlobalGraphQLFilter`.
**Note:** SentryGlobalGenericFilter will catch both HTTP and GraphQL errors.

By default, exceptions with status code 4xx are not sent to Sentry. If you still want to capture these exceptions, you can do so manually with `Sentry.captureException()`:

Expand Down
Loading