You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Apologies in advance, I do not have much experience in opening issues!
I have a case when I am wrapping a method with tracer.wrap and this methods takes a class constructor function as its last argument. This is triggering the if condition on line 125 of tracer.js in dd-trace which overrides the last argument. Later on this class constructor is being used create an instance and do something with it. As it stands, I get the following error:
TypeError: Class constructor MyClassConstructorArgument cannot be invoked without 'new'
Reproduction Code
A trace decorator, used to wrap class methods I want to trace
A class with a method I want to trace, whose last argument is a class constructor
import{DecorateAll}from'decorate-all';import{ClassConstructor,plainToInstance}from'class-transformer';
@DecorateAll(Trace,{deep: true})exportclassSomeService{publicasyncsomeMethodToTrace(someParam: SomeOtherType,validatorClass: ClassConstructor<DtoClassWithValidationAsDecorators>): Promise<SomeReturnType>{console.log(validatorClass.prototype)// logs {}// somewhere in the code this is called, which probably internally calls new validatorClass(...)// plainToInstance(validatorClass, someObjectPlainObject)}
This dto class extends a base class
classDtoClassWithValidationAsDecoratorsextendsDtoBaseClass{// some properties with some decorators with overriden validation logic from the base class}
So before the traced method is called, logging the prototype results in DtoBaseClass
But inside the traced method, because of what happens inside tracer.js line 125, logging results in {}
Error Logs
TypeError: Class constructor DtoClassWithValidationAsDecorators cannot be invoked without 'new'
Honestly, I do not know what to put in here. My situation is also a little bit weird as well. In principle I have some code that is upserting something, and I want to apply different validation logics in different scenarios, hence the class constructor function as a parameter. I have to say that the validation should happen separately and not inside the same function that is being traced (it is doing way too many things), but I am stuck with it for now and I cannot change it.
Tracer Config
No response
Operating System
No response
Bundling
Webpack
The text was updated successfully, but these errors were encountered:
jcelmeta14
changed the title
[BUG]: When calling tracer.wrap on a method that accepts a class constructor function as its last arguments causes weird behaviour
[BUG]: When calling tracer.wrap on a method that accepts a class constructor function as its last arguments causes unexpected behaviour
Jan 8, 2025
Tracer Version(s)
5.22.0
Node.js Version(s)
20.18.1
Bug Report
Apologies in advance, I do not have much experience in opening issues!
I have a case when I am wrapping a method with
tracer.wrap
and this methods takes a class constructor function as its last argument. This is triggering the if condition on line 125 of tracer.js in dd-trace which overrides the last argument. Later on this class constructor is being used create an instance and do something with it. As it stands, I get the following error:TypeError: Class constructor MyClassConstructorArgument cannot be invoked without 'new'
Reproduction Code
A trace decorator, used to wrap class methods I want to trace
A class with a method I want to trace, whose last argument is a class constructor
This dto class extends a base class
Somewhere the method is called:
So before the traced method is called, logging the prototype results in
DtoBaseClass
But inside the traced method, because of what happens inside tracer.js line 125, logging results in
{}
Error Logs
TypeError: Class constructor DtoClassWithValidationAsDecorators cannot be invoked without 'new'
Honestly, I do not know what to put in here. My situation is also a little bit weird as well. In principle I have some code that is upserting something, and I want to apply different validation logics in different scenarios, hence the class constructor function as a parameter. I have to say that the validation should happen separately and not inside the same function that is being traced (it is doing way too many things), but I am stuck with it for now and I cannot change it.
Tracer Config
No response
Operating System
No response
Bundling
Webpack
The text was updated successfully, but these errors were encountered: