@@ -83,8 +83,7 @@ import { Segment, Subsegment } from 'aws-xray-sdk-core';
83
83
* const segment = tracer.getSegment(); // This is the facade segment (the one that is created by AWS Lambda)
84
84
* // Create subsegment for the function
85
85
* const handlerSegment = segment.addNewSubsegment(`## ${context.functionName}`);
86
- * // TODO: expose tracer.annotateColdStart()
87
- * this.putAnnotation('ColdStart', tracer.isColdStart());
86
+ * tracer.annotateColdStart()
88
87
*
89
88
* let res;
90
89
* try {
@@ -104,6 +103,7 @@ import { Segment, Subsegment } from 'aws-xray-sdk-core';
104
103
* ```
105
104
*/
106
105
class Tracer implements TracerInterface {
106
+
107
107
public static coldStart : boolean = true ;
108
108
109
109
public provider : ProviderServiceInterface ;
@@ -163,6 +163,25 @@ class Tracer implements TracerInterface {
163
163
this . putMetadata ( `${ methodName } response` , data ) ;
164
164
}
165
165
166
+ /**
167
+ * Add ColdStart annotation to the current segment or subsegment.
168
+ *
169
+ * If Tracer has been initialized outside of the Lambda handler then the same instance
170
+ * of Tracer will be reused throghout the lifecycle of that same Lambda execution environment
171
+ * and this method will return `false` after the first invocation.
172
+ *
173
+ * @see https://docs.aws.amazon.com/lambda/latest/dg/runtimes-context.html
174
+ */
175
+ public annotateColdStart ( ) : void {
176
+ if ( Tracer . coldStart === true ) {
177
+ Tracer . coldStart = false ;
178
+
179
+ if ( this . tracingEnabled === true ) {
180
+ this . putAnnotation ( 'ColdStart' , true ) ;
181
+ }
182
+ }
183
+ }
184
+
166
185
/**
167
186
* Patch all AWS SDK v2 clients and create traces when your application makes calls to AWS services.
168
187
*
@@ -376,6 +395,27 @@ class Tracer implements TracerInterface {
376
395
return descriptor ;
377
396
} ;
378
397
}
398
+
399
+ /**
400
+ * Retrieve the current value of `ColdStart`.
401
+ *
402
+ * If Tracer has been initialized outside of the Lambda handler then the same instance
403
+ * of Tracer will be reused throghout the lifecycle of that same Lambda execution environment
404
+ * and this method will return `false` after the first invocation.
405
+ *
406
+ * @see https://docs.aws.amazon.com/lambda/latest/dg/runtimes-context.html
407
+ *
408
+ * @returns boolean - `true` if is cold start, otherwise `false`
409
+ */
410
+ public static getColdStart ( ) : boolean {
411
+ if ( Tracer . coldStart === true ) {
412
+ Tracer . coldStart = false ;
413
+
414
+ return true ;
415
+ }
416
+
417
+ return false ;
418
+ }
379
419
380
420
/**
381
421
* Get the active segment or subsegment in the current scope.
@@ -408,27 +448,6 @@ class Tracer implements TracerInterface {
408
448
return segment ;
409
449
}
410
450
411
- /**
412
- * Retrieve the current value of `ColdStart`.
413
- *
414
- * If Tracer has been initialized outside of the Lambda handler then the same instance
415
- * of Tracer will be reused throghout the lifecycle of that same Lambda execution environment
416
- * and this method will return `false` after the first invocation.
417
- *
418
- * @see https://docs.aws.amazon.com/lambda/latest/dg/runtimes-context.html
419
- *
420
- * @returns boolean - `true` if is cold start, otherwise `false`
421
- */
422
- public static isColdStart ( ) : boolean {
423
- if ( Tracer . coldStart === true ) {
424
- Tracer . coldStart = false ;
425
-
426
- return true ;
427
- }
428
-
429
- return false ;
430
- }
431
-
432
451
/**
433
452
* Get the current value of the `tracingEnabled` property.
434
453
*
@@ -532,16 +551,6 @@ class Tracer implements TracerInterface {
532
551
public setSegment ( segment : Segment | Subsegment ) : void {
533
552
return this . provider . setSegment ( segment ) ;
534
553
}
535
-
536
- /**
537
- * Add ColdStart annotation to the current segment or subsegment.
538
- * Used internally by decoratorators and middlewares.
539
- */
540
- private annotateColdStart ( ) : void {
541
- if ( Tracer . isColdStart ( ) ) {
542
- this . putAnnotation ( 'ColdStart' , true ) ;
543
- }
544
- }
545
554
546
555
/**
547
556
* Getter for `customConfigService`.
0 commit comments