Skip to content

Commit 7bd81ae

Browse files
authored
fix(tracer): pass args of decorated method as they are (aws-powertools#4312)
1 parent cc23ae7 commit 7bd81ae

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

packages/tracer/src/Tracer.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -428,9 +428,12 @@ class Tracer extends Utility implements TracerInterface {
428428
const tracerRef = this;
429429
// Use a function() {} instead of an () => {} arrow function so that we can
430430
// access `myClass` as `this` in a decorated `myClass.myMethod()`.
431-
descriptor.value = function (this: Handler, event, context, callback) {
431+
descriptor.value = function (
432+
this: Handler,
433+
...args: Parameters<Handler>
434+
) {
432435
if (!tracerRef.isTracingEnabled()) {
433-
return originalMethod.apply(this, [event, context, callback]);
436+
return originalMethod.apply(this, args);
434437
}
435438

436439
return tracerRef.provider.captureAsyncFunc(
@@ -440,11 +443,7 @@ class Tracer extends Utility implements TracerInterface {
440443
tracerRef.addServiceNameAnnotation();
441444
let result: unknown;
442445
try {
443-
result = await originalMethod.apply(this, [
444-
event,
445-
context,
446-
callback,
447-
]);
446+
result = await originalMethod.apply(this, args);
448447
if (options?.captureResponse ?? true) {
449448
tracerRef.addResponseAsMetadata(result, process.env._HANDLER);
450449
}

0 commit comments

Comments
 (0)