From daaadde91d344e4147bb012d142a15172c4467a4 Mon Sep 17 00:00:00 2001 From: Charly Gomez Date: Fri, 16 May 2025 09:56:36 +0200 Subject: [PATCH 1/2] add note on decorators --- .../guides/nestjs/features/event-emitter.mdx | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/docs/platforms/javascript/guides/nestjs/features/event-emitter.mdx b/docs/platforms/javascript/guides/nestjs/features/event-emitter.mdx index 8613f849cc76e..def20ffa2c024 100644 --- a/docs/platforms/javascript/guides/nestjs/features/event-emitter.mdx +++ b/docs/platforms/javascript/guides/nestjs/features/event-emitter.mdx @@ -15,4 +15,26 @@ 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. + + Annotating one function with multiple `@OnEvent` decorators is not recommended, as NestJS provides no way for us to determine the triggering event. Therefore, the resulting span name will include all decorated event names. + + Instead, use one decorator per event name 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. From 53a9cda10ee475f6bf18283badb93722d986fd80 Mon Sep 17 00:00:00 2001 From: Charly Gomez Date: Tue, 20 May 2025 14:24:47 +0200 Subject: [PATCH 2/2] Update event-emitter.mdx --- .../javascript/guides/nestjs/features/event-emitter.mdx | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/docs/platforms/javascript/guides/nestjs/features/event-emitter.mdx b/docs/platforms/javascript/guides/nestjs/features/event-emitter.mdx index def20ffa2c024..067a83911cb7d 100644 --- a/docs/platforms/javascript/guides/nestjs/features/event-emitter.mdx +++ b/docs/platforms/javascript/guides/nestjs/features/event-emitter.mdx @@ -16,9 +16,8 @@ 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. - Annotating one function with multiple `@OnEvent` decorators is not recommended, as NestJS provides no way for us to determine the triggering event. Therefore, the resulting span name will include all decorated event names. - - Instead, use one decorator per event name and handle any shared logic through a separate function. + 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')