---
title: "NestJS Event Emitter"
description: "Learn about instrumenting NestJS event-based services."
url: https://docs.sentry.io/platforms/javascript/guides/nestjs/features/event-emitter/
---

# NestJS Event Emitter | Sentry for Nest.js

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

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.

##### Multiple decorators

If multiple decorators are used, we will collect all event names to determine the span's name. In case you want to map each event to a specific handler, use one decorator per handler and handle any shared logic through a separate function.

```typescript
@OnEvent('event.A')
function myHandlerA(payload: any) {
  commonHandler(payload)  
}

@OnEvent('event.B')
function myHandlerB(payload: any) {
  commonHandler(payload)  
}

function commonHandler(payload: any) {
  // handle stuff 
}
```

This instrumentation works transparently with existing NestJS event handlers without requiring any code changes to your application.
