Skip to content

Commit 9bbc37c

Browse files
committed
chore: read trace id from Labda Invoke Store
1 parent 29e34ba commit 9bbc37c

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

packages/middleware-recursion-detection/src/recursionDetectionMiddleware.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { InvokeStore } from "@aws/lambda-invoke-store";
12
import { HttpRequest } from "@smithy/protocol-http";
23
import {
34
BuildHandler,
@@ -31,7 +32,11 @@ export const recursionDetectionMiddleware =
3132
return next(args);
3233
}
3334
const functionName = process.env[ENV_LAMBDA_FUNCTION_NAME];
34-
const traceId = process.env[ENV_TRACE_ID];
35+
36+
const traceIdFromEnv = process.env[ENV_TRACE_ID];
37+
const traceIdFromInvokeStore = InvokeStore.getXRayTraceId();
38+
const traceId = traceIdFromInvokeStore ?? traceIdFromEnv;
39+
3540
const nonEmptyString = (str: unknown): str is string => typeof str === "string" && str.length > 0;
3641
if (nonEmptyString(functionName) && nonEmptyString(traceId)) {
3742
request.headers[TRACE_ID_HEADER_NAME] = traceId;

0 commit comments

Comments
 (0)