Skip to content

docs(js): Add note on nestjs OnEvent decorators #13734

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

Merged
merged 2 commits into from
May 23, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions docs/platforms/javascript/guides/nestjs/features/event-emitter.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,25 @@ The NestJS SDK wraps the `@OnEvent` decorator automatically to:

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.

<Alert level="info" title="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
}
```
</Alert>

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