1- import type { Handler } from 'aws-lambda' ;
21import { Utility } from '@aws-lambda-powertools/commons' ;
32import type {
43 AsyncHandler ,
5- SyncHandler ,
64 HandlerMethodDecorator ,
5+ SyncHandler ,
76} from '@aws-lambda-powertools/commons/types' ;
7+ import type { Handler } from 'aws-lambda' ;
8+ import type { Segment , Subsegment } from 'aws-xray-sdk-core' ;
9+ import xraySdk from 'aws-xray-sdk-core' ;
810import { EnvironmentVariablesService } from './config/EnvironmentVariablesService.js' ;
11+ import { ProviderService } from './provider/ProviderService.js' ;
912import type { ConfigServiceInterface } from './types/ConfigServiceInterface.js' ;
13+ import type { ProviderServiceInterface } from './types/ProviderService.js' ;
1014import type {
11- TracerInterface ,
12- TracerOptions ,
1315 AnyClass ,
14- MethodDecorator ,
1516 CaptureLambdaHandlerOptions ,
1617 CaptureMethodOptions ,
18+ MethodDecorator ,
19+ TracerInterface ,
20+ TracerOptions ,
1721} from './types/Tracer.js' ;
18- import { ProviderService } from './provider/ProviderService.js' ;
19- import type { ProviderServiceInterface } from './types/ProviderService.js' ;
20- import type { Segment , Subsegment } from 'aws-xray-sdk-core' ;
21- import xraySdk from 'aws-xray-sdk-core' ;
2222const { Subsegment : XraySubsegment } = xraySdk ;
2323
2424/**
@@ -372,22 +372,16 @@ class Tracer extends Utility implements TracerInterface {
372372 options ?: CaptureLambdaHandlerOptions
373373 ) : HandlerMethodDecorator {
374374 return ( _target , _propertyKey , descriptor ) => {
375- /**
376- * The descriptor.value is the method this decorator decorates, it cannot be undefined.
377- */
378- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
375+ // biome-ignore lint/style/noNonNullAssertion: The descriptor.value is the method this decorator decorates, it cannot be undefined.
379376 const originalMethod = descriptor . value ! ;
380377
381378 // eslint-disable-next-line @typescript-eslint/no-this-alias
382379 const tracerRef = this ;
383380 // Use a function() {} instead of an () => {} arrow function so that we can
384381 // access `myClass` as `this` in a decorated `myClass.myMethod()`.
385382 descriptor . value = function ( this : Handler , event , context , callback ) {
386- // eslint-disable-next-line @typescript-eslint/no-this-alias
387- const handlerRef : Handler = this ;
388-
389383 if ( ! tracerRef . isTracingEnabled ( ) ) {
390- return originalMethod . apply ( handlerRef , [ event , context , callback ] ) ;
384+ return originalMethod . apply ( this , [ event , context , callback ] ) ;
391385 }
392386
393387 return tracerRef . provider . captureAsyncFunc (
@@ -397,7 +391,7 @@ class Tracer extends Utility implements TracerInterface {
397391 tracerRef . addServiceNameAnnotation ( ) ;
398392 let result : unknown ;
399393 try {
400- result = await originalMethod . apply ( handlerRef , [
394+ result = await originalMethod . apply ( this , [
401395 event ,
402396 context ,
403397 callback ,
@@ -413,7 +407,7 @@ class Tracer extends Utility implements TracerInterface {
413407 subsegment ?. close ( ) ;
414408 } catch ( error ) {
415409 console . warn (
416- ` Failed to close or serialize segment %s. We are catching the error but data might be lost.` ,
410+ ' Failed to close or serialize segment %s. We are catching the error but data might be lost.' ,
417411 subsegment ?. name ,
418412 error
419413 ) ;
@@ -469,8 +463,7 @@ class Tracer extends Utility implements TracerInterface {
469463 options ?: CaptureMethodOptions
470464 ) : MethodDecorator < T > {
471465 return ( _target , propertyKey , descriptor ) => {
472- // The descriptor.value is the method this decorator decorates, it cannot be undefined.
473- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
466+ // biome-ignore lint/style/noNonNullAssertion: The descriptor.value is the method this decorator decorates, it cannot be undefined.
474467 const originalMethod = descriptor . value ! ;
475468
476469 // eslint-disable-next-line @typescript-eslint/no-this-alias
@@ -490,7 +483,8 @@ class Tracer extends Utility implements TracerInterface {
490483 return tracerRef . provider . captureAsyncFunc (
491484 subsegmentName ,
492485 async ( subsegment ) => {
493- let result ;
486+ // biome-ignore lint/suspicious/noExplicitAny: we don't know the type of the result because we're decorating arbitrary functions
487+ let result : any ;
494488 try {
495489 result = await originalMethod . apply ( this , [ ...args ] ) ;
496490 if ( options ?. captureResponse ?? true ) {
@@ -505,7 +499,7 @@ class Tracer extends Utility implements TracerInterface {
505499 subsegment ?. close ( ) ;
506500 } catch ( error ) {
507501 console . warn (
508- ` Failed to close or serialize segment %s. We are catching the error but data might be lost.` ,
502+ ' Failed to close or serialize segment %s. We are catching the error but data might be lost.' ,
509503 subsegment ?. name ,
510504 error
511505 ) ;
@@ -702,7 +696,7 @@ class Tracer extends Utility implements TracerInterface {
702696 public setSegment ( segment : Segment | Subsegment ) : void {
703697 if ( ! this . isTracingEnabled ( ) ) return ;
704698
705- return this . provider . setSegment ( segment ) ;
699+ this . provider . setSegment ( segment ) ;
706700 }
707701
708702 /**
0 commit comments