1
1
import { Handler } from 'aws-lambda' ;
2
+ import { Utility } from '@aws-lambda-powertools/commons' ;
2
3
import { TracerInterface } from '.' ;
3
4
import { ConfigServiceInterface , EnvironmentVariablesService } from './config' ;
4
5
import { HandlerMethodDecorator , TracerOptions , MethodDecorator } from './types' ;
@@ -109,9 +110,7 @@ import { Segment, Subsegment } from 'aws-xray-sdk-core';
109
110
* }
110
111
* ```
111
112
*/
112
- class Tracer implements TracerInterface {
113
-
114
- public static coldStart : boolean = true ;
113
+ class Tracer extends Utility implements TracerInterface {
115
114
116
115
public provider : ProviderServiceInterface ;
117
116
@@ -128,6 +127,8 @@ class Tracer implements TracerInterface {
128
127
private tracingEnabled : boolean = true ;
129
128
130
129
public constructor ( options : TracerOptions = { } ) {
130
+ super ( ) ;
131
+
131
132
this . setOptions ( options ) ;
132
133
this . provider = new ProviderService ( ) ;
133
134
if ( ! this . isTracingEnabled ( ) ) {
@@ -196,10 +197,7 @@ class Tracer implements TracerInterface {
196
197
*/
197
198
public annotateColdStart ( ) : void {
198
199
if ( this . isTracingEnabled ( ) ) {
199
- this . putAnnotation ( 'ColdStart' , Tracer . coldStart ) ;
200
- }
201
- if ( Tracer . coldStart ) {
202
- Tracer . coldStart = false ;
200
+ this . putAnnotation ( 'ColdStart' , this . getColdStart ( ) ) ;
203
201
}
204
202
}
205
203
@@ -430,27 +428,6 @@ class Tracer implements TracerInterface {
430
428
return descriptor ;
431
429
} ;
432
430
}
433
-
434
- /**
435
- * Retrieve the current value of `ColdStart`.
436
- *
437
- * If Tracer has been initialized outside the Lambda handler then the same instance
438
- * of Tracer will be reused throughout the lifecycle of that same Lambda execution environment
439
- * and this method will return `false` after the first invocation.
440
- *
441
- * @see https://docs.aws.amazon.com/lambda/latest/dg/runtimes-context.html
442
- *
443
- * @returns boolean - `true` if is cold start, otherwise `false`
444
- */
445
- public static getColdStart ( ) : boolean {
446
- if ( Tracer . coldStart ) {
447
- Tracer . coldStart = false ;
448
-
449
- return true ;
450
- }
451
-
452
- return false ;
453
- }
454
431
455
432
/**
456
433
* Get the active segment or subsegment in the current scope.
0 commit comments