Skip to content

Commit 6b2e76b

Browse files
authored
docs(js): Add note on nestjs OnEvent decorators (#13734)
1 parent 423028c commit 6b2e76b

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

docs/platforms/javascript/guides/nestjs/features/event-emitter.mdx

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,25 @@ The NestJS SDK wraps the `@OnEvent` decorator automatically to:
1515

1616
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.
1717

18+
<Alert level="info" title="Multiple decorators">
19+
If multiple decorators are used, we will collect all event names to determine the span's name.
20+
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.
21+
22+
```typescript
23+
@OnEvent('event.A')
24+
function myHandlerA(payload: any) {
25+
commonHandler(payload)
26+
}
27+
28+
@OnEvent('event.B')
29+
function myHandlerB(payload: any) {
30+
commonHandler(payload)
31+
}
32+
33+
function commonHandler(payload: any) {
34+
// handle stuff
35+
}
36+
```
37+
</Alert>
38+
1839
This instrumentation works transparently with existing NestJS event handlers without requiring any code changes to your application.

0 commit comments

Comments
 (0)