Description
Is there an existing issue for this?
- I have checked for existing issues https://github.com/getsentry/sentry-javascript/issues
- I have reviewed the documentation https://docs.sentry.io/
- I am using the latest SDK release https://github.com/getsentry/sentry-javascript/releases
How do you use Sentry?
Sentry Saas (sentry.io)
Which SDK are you using?
@sentry/nestjs
SDK Version
8.52.0
Framework Version
Nestjs 10.4.7
Link to Sentry event
No response
Reproduction Example/SDK Setup
I set up a minimal repro here :
https://github.com/matthieuMay/sentry_nest_event_repro
This is a minimal nestjs + nestjs/event-emitter + sentry configuration.
It contains:
- instrument.ts : sentry initialization
- app.module.ts: main nestjs module
- app.controller.ts: main nestjs module
- app.service.ts: service setting a event listener on two events and emitting the two events when application is bootstrapped
Steps to Reproduce
- npm install
- set environnement SENTRY_DSN variable
- run
npm run start:dev
- see that event handler is called only once
![Image](https://private-user-images.githubusercontent.com/104060209/407739676-2b2dd86e-6ce0-43b2-b6e9-eb6e7a223096.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzg5MzAzNDUsIm5iZiI6MTczODkzMDA0NSwicGF0aCI6Ii8xMDQwNjAyMDkvNDA3NzM5Njc2LTJiMmRkODZlLTZjZTAtNDNiMi1iNmU5LWViNmU3YTIyMzA5Ni5wbmc_WC1BbXotQWxnb3JpdGhtPUFXUzQtSE1BQy1TSEEyNTYmWC1BbXotQ3JlZGVudGlhbD1BS0lBVkNPRFlMU0E1M1BRSzRaQSUyRjIwMjUwMjA3JTJGdXMtZWFzdC0xJTJGczMlMkZhd3M0X3JlcXVlc3QmWC1BbXotRGF0ZT0yMDI1MDIwN1QxMjA3MjVaJlgtQW16LUV4cGlyZXM9MzAwJlgtQW16LVNpZ25hdHVyZT00ZTQ4YTAyNzQwYTZhNDE2YmJjMGRhZjZlNDgwOGNiNDM4OTUzNWU1YzMyMmVhNzA0NjgwYjY1MjlmMTkyOTg0JlgtQW16LVNpZ25lZEhlYWRlcnM9aG9zdCJ9.U03gbnSGHxt0JGxYhWsXmGDT6rIXpTWsVmLR8VwTNTI)
- comment the import of instrument.js or unset SENTRY_DSN variable
- run
npm run start:dev
- see that event handler is called twice as expected
![Image](https://private-user-images.githubusercontent.com/104060209/407740127-945432e0-8758-44c0-bdaa-d0778d5fabb7.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzg5MzAzNDUsIm5iZiI6MTczODkzMDA0NSwicGF0aCI6Ii8xMDQwNjAyMDkvNDA3NzQwMTI3LTk0NTQzMmUwLTg3NTgtNDRjMC1iZGFhLWQwNzc4ZDVmYWJiNy5wbmc_WC1BbXotQWxnb3JpdGhtPUFXUzQtSE1BQy1TSEEyNTYmWC1BbXotQ3JlZGVudGlhbD1BS0lBVkNPRFlMU0E1M1BRSzRaQSUyRjIwMjUwMjA3JTJGdXMtZWFzdC0xJTJGczMlMkZhd3M0X3JlcXVlc3QmWC1BbXotRGF0ZT0yMDI1MDIwN1QxMjA3MjVaJlgtQW16LUV4cGlyZXM9MzAwJlgtQW16LVNpZ25hdHVyZT0wMzExZGQwYTI2Y2FhZjlhNDczMzA1NzM2MGJmMzIyMDIxNmVhYjYyZjYzZTQzNTJjN2VhNmFmNGE3ZDI3NmEwJlgtQW16LVNpZ25lZEhlYWRlcnM9aG9zdCJ9.PoEqxxnxov1iH3ypHOQ4VCFrTlUrGyoyqhv2yiyAWXA)
Expected Result
We should see the handler being called twice
Explanation of the bug
Nestjs initialize in two steps : first the decorators set metadata on the decorated functions and once all decorators have been read, this metadata is traducted in method modifications.
Sentry instrumentation overrides the OnEvent decorator in SentryNestEventInstrumentation._createWrapOnEvent
method. This new decorator ovverides descriptor.value on every call.
Therefore, when decorating the same handler with multiple @onevent, descriptor.value changes on every call changing the target of the metadata on every call. As a consequence, only the last called decorator is actually applied
Actual Result
![Image](https://private-user-images.githubusercontent.com/104060209/407744930-0a685b8a-1a6e-472e-8e27-d2dc5130e621.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzg5MzAzNDUsIm5iZiI6MTczODkzMDA0NSwicGF0aCI6Ii8xMDQwNjAyMDkvNDA3NzQ0OTMwLTBhNjg1YjhhLTFhNmUtNDcyZS04ZTI3LWQyZGM1MTMwZTYyMS5wbmc_WC1BbXotQWxnb3JpdGhtPUFXUzQtSE1BQy1TSEEyNTYmWC1BbXotQ3JlZGVudGlhbD1BS0lBVkNPRFlMU0E1M1BRSzRaQSUyRjIwMjUwMjA3JTJGdXMtZWFzdC0xJTJGczMlMkZhd3M0X3JlcXVlc3QmWC1BbXotRGF0ZT0yMDI1MDIwN1QxMjA3MjVaJlgtQW16LUV4cGlyZXM9MzAwJlgtQW16LVNpZ25hdHVyZT00ZTdkNWU5Yzg4NmZkYWE2ZjExYWM0NTI0OGRjYzNjZTNhODE3OGM3MzE4MzQxMzBiNzYwMzVjZDE3YjAyYWY4JlgtQW16LVNpZ25lZEhlYWRlcnM9aG9zdCJ9.hAesn4HoozJr_NnDLBHOT9XDBa6ANYER2Mm35y2xNt8)
Metadata
Assignees
Type
Projects
Status
No status