@@ -9,10 +9,11 @@ const serviceName = process.env.EXPECTED_SERVICE_NAME ?? 'MyFunctionWithStandard
99const customAnnotationKey = process . env . EXPECTED_CUSTOM_ANNOTATION_KEY ?? 'myAnnotation' ;
1010const customAnnotationValue = process . env . EXPECTED_CUSTOM_ANNOTATION_VALUE ?? 'myValue' ;
1111const customMetadataKey = process . env . EXPECTED_CUSTOM_METADATA_KEY ?? 'myMetadata' ;
12- const customMetadataValue = JSON . parse ( process . env . EXPECTED_CUSTOM_METADATA_VALUE ) ?? { bar : 'baz' } ;
13- const customResponseValue = JSON . parse ( process . env . EXPECTED_CUSTOM_RESPONSE_VALUE ) ?? { foo : 'bar' } ;
12+ const customMetadataValue = process . env . EXPECTED_CUSTOM_METADATA_VALUE ? JSON . parse ( process . env . EXPECTED_CUSTOM_METADATA_VALUE ) : { bar : 'baz' } ;
13+ const customResponseValue = process . env . EXPECTED_CUSTOM_RESPONSE_VALUE ? JSON . parse ( process . env . EXPECTED_CUSTOM_RESPONSE_VALUE ) : { foo : 'bar' } ;
1414const customErrorMessage = process . env . EXPECTED_CUSTOM_ERROR_MESSAGE ?? 'An error has occurred' ;
1515const testTableName = process . env . TEST_TABLE_NAME ?? 'TestTable' ;
16+ const customSubSegmentName = process . env . EXPECTED_CUSTOM_SUBSEGMENT_NAME ?? 'mySubsegment' ;
1617
1718interface CustomEvent {
1819 throw : boolean
@@ -35,16 +36,13 @@ const refreshAWSSDKImport = (): void => {
3536const tracer = new Tracer ( { serviceName : serviceName } ) ;
3637const dynamoDBv3 = tracer . captureAWSv3Client ( new DynamoDBClient ( { } ) ) ;
3738
38- export class MyFunctionWithDecorator {
39+ export class MyFunctionBase {
3940 private readonly returnValue : string ;
4041
4142 public constructor ( ) {
4243 this . returnValue = customResponseValue ;
4344 }
4445
45- @tracer . captureLambdaHandler ( )
46- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
47- // @ts -ignore
4846 public async handler ( event : CustomEvent , _context : Context ) : Promise < unknown > {
4947 tracer . putAnnotation ( customAnnotationKey , customAnnotationValue ) ;
5048 tracer . putMetadata ( customMetadataKey , customMetadataValue ) ;
@@ -74,13 +72,45 @@ export class MyFunctionWithDecorator {
7472 }
7573 }
7674
75+ public myMethod ( ) : string {
76+ return this . returnValue ;
77+ }
78+ }
79+
80+ class MyFunctionWithDecorator extends MyFunctionBase {
81+ @tracer . captureLambdaHandler ( )
82+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
83+ // @ts -ignore
84+ public async handler ( event : CustomEvent , _context : Context , _callback : Callback < unknown > ) : void | Promise < unknown > {
85+ return super . handler ( event , _context ) ;
86+ }
87+
7788 @tracer . captureMethod ( )
7889 // eslint-disable-next-line @typescript-eslint/ban-ts-comment
7990 // @ts -ignore
8091 public myMethod ( ) : string {
81- return this . returnValue ;
92+ return super . myMethod ( ) ;
8293 }
8394}
8495
8596const handlerClass = new MyFunctionWithDecorator ( ) ;
86- export const handler = handlerClass . handler . bind ( handlerClass ) ;
97+ export const handler = handlerClass . handler . bind ( handlerClass ) ;
98+
99+ export class MyFunctionWithDecoratorAndCustomNamedSubSegmentForMethod extends MyFunctionBase {
100+ @tracer . captureLambdaHandler ( )
101+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
102+ // @ts -ignore
103+ public async handler ( event : CustomEvent , _context : Context , _callback : Callback < unknown > ) : void | Promise < unknown > {
104+ return super . handler ( event , _context ) ;
105+ }
106+
107+ @tracer . captureMethod ( { subSegmentName : customSubSegmentName } )
108+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
109+ // @ts -ignore
110+ public myMethod ( ) : string {
111+ return super . myMethod ( ) ;
112+ }
113+ }
114+
115+ const handlerWithCustomSubsegmentNameInMethodClass = new MyFunctionWithDecoratorAndCustomNamedSubSegmentForMethod ( ) ;
116+ export const handlerWithCustomSubsegmentNameInMethod = handlerClass . handler . bind ( handlerWithCustomSubsegmentNameInMethodClass ) ;
0 commit comments