diff --git a/package.json b/package.json index 80cc8ef76..5f0c2ed74 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "datadog-lambda-js", - "version": "9.115.0", + "version": "9.116.0", "description": "Lambda client library that supports hybrid tracing in node js", "main": "dist/index.js", "types": "dist/index.d.ts", diff --git a/src/trace/step-function-service.ts b/src/trace/step-function-service.ts index 7aa636267..92e6725fb 100644 --- a/src/trace/step-function-service.ts +++ b/src/trace/step-function-service.ts @@ -76,7 +76,7 @@ export class StepFunctionContextService { if (typeof event !== "object") return; // Extract Payload if available (Legacy lambda parsing) - if (typeof event.Payload === "object") { + if (typeof event?.Payload?._datadog === "object" || this.isValidContextObject(event?.Payload)) { event = event.Payload; } @@ -199,20 +199,11 @@ export class StepFunctionContextService { state_entered_time: string; state_name: string; } | null { - const execution = event.Execution; - const state = event.State; - - if ( - typeof execution === "object" && - typeof execution.Id === "string" && - typeof state === "object" && - typeof state.EnteredTime === "string" && - typeof state.Name === "string" - ) { + if (this.isValidContextObject(event)) { return { - execution_id: execution.Id, - state_entered_time: state.EnteredTime, - state_name: state.Name, + execution_id: event.Execution.Id, + state_entered_time: event.State.EnteredTime, + state_name: event.State.Name, }; } @@ -220,6 +211,14 @@ export class StepFunctionContextService { return null; } + private isValidContextObject(context: any): boolean { + return ( + typeof context?.Execution?.Id === "string" && + typeof context?.State?.EnteredTime === "string" && + typeof context?.State?.Name === "string" + ); + } + /** * Parse a list of trace tags such as [_dd.p.tid=66bcb5eb00000000,_dd.p.dm=-0] and return the * value of the _dd.p.tid tag or an empty string if not found.