1- import { InvokeStore } from '@aws/lambda-invoke-store' ;
21import {
32 POWERTOOLS_DEV_ENV_VAR ,
43 POWERTOOLS_SERVICE_NAME_ENV_VAR ,
@@ -250,19 +249,15 @@ const getServiceName = (): string => {
250249} ;
251250
252251/**
253- * Get the AWS X-Ray Trace data from the lambda RIC async context or the `_X_AMZN_TRACE_ID` environment variable.
252+ * Get the AWS X-Ray Trace data from the environment variable.
254253 *
255- * Checks the async context first and if that returns undefined, falls back to the environment variable
256- *
257- * The method parses the value and returns an object with the key-value pairs.
254+ * The method parses the environment variable `_X_AMZN_TRACE_ID` and returns an object with the key-value pairs.
258255 */
259256const getXrayTraceDataFromEnv = ( ) : Record < string , string > | undefined => {
260- const xRayTraceEnv =
261- InvokeStore . getXRayTraceId ( ) ??
262- getStringFromEnv ( {
263- key : XRAY_TRACE_ID_ENV_VAR ,
264- defaultValue : '' ,
265- } ) ;
257+ const xRayTraceEnv = getStringFromEnv ( {
258+ key : XRAY_TRACE_ID_ENV_VAR ,
259+ defaultValue : '' ,
260+ } ) ;
266261 if ( xRayTraceEnv === '' ) {
267262 return undefined ;
268263 }
@@ -285,22 +280,18 @@ const getXrayTraceDataFromEnv = (): Record<string, string> | undefined => {
285280/**
286281 * Determine if the current invocation is part of a sampled X-Ray trace.
287282 *
288- * The AWS X-Ray Trace data is available in either the RIC async context or the `_X_AMZN_TRACE_ID` environment variable has this format:
283+ * The AWS X-Ray Trace data available in the environment variable has this format:
289284 * `Root=1-5759e988-bd862e3fe1be46a994272793;Parent=557abcec3ee5a047;Sampled=1`,
290- *
291- * Checks the async context first and if that returns undefined, falls back to the environment variable
292285 */
293286const isRequestXRaySampled = ( ) : boolean => {
294287 const xRayTraceData = getXrayTraceDataFromEnv ( ) ;
295288 return xRayTraceData ?. Sampled === '1' ;
296289} ;
297290
298291/**
299- * AWS X-Ray Trace id from the lambda RIC async context or the `_X_AMZN_TRACE_ID` environment variable.
300- *
301- * Checks the async context first and if that returns undefined, falls back to the environment variable
292+ * Get the value of the `_X_AMZN_TRACE_ID` environment variable.
302293 *
303- * The AWS X-Ray Trace data has this format:
294+ * The AWS X-Ray Trace data available in the environment variable has this format:
304295 * `Root=1-5759e988-bd862e3fe1be46a994272793;Parent=557abcec3ee5a047;Sampled=1`,
305296 *
306297 * The actual Trace ID is: `1-5759e988-bd862e3fe1be46a994272793`.
0 commit comments