@@ -76,7 +76,7 @@ export class StepFunctionContextService {
7676 if ( typeof event !== "object" ) return ;
7777
7878 // Extract Payload if available (Legacy lambda parsing)
79- if ( typeof event . Payload === "object" ) {
79+ if ( typeof event ? .Payload ?. _datadog === "object" || this . isValidContextObject ( event ?. Payload ) ) {
8080 event = event . Payload ;
8181 }
8282
@@ -199,27 +199,26 @@ export class StepFunctionContextService {
199199 state_entered_time : string ;
200200 state_name : string ;
201201 } | null {
202- const execution = event . Execution ;
203- const state = event . State ;
204-
205- if (
206- typeof execution === "object" &&
207- typeof execution . Id === "string" &&
208- typeof state === "object" &&
209- typeof state . EnteredTime === "string" &&
210- typeof state . Name === "string"
211- ) {
202+ if ( this . isValidContextObject ( event ) ) {
212203 return {
213- execution_id : execution . Id ,
214- state_entered_time : state . EnteredTime ,
215- state_name : state . Name ,
204+ execution_id : event . Execution . Id ,
205+ state_entered_time : event . State . EnteredTime ,
206+ state_name : event . State . Name ,
216207 } ;
217208 }
218209
219210 logDebug ( "Cannot extract StateMachine context! Invalid execution or state data." ) ;
220211 return null ;
221212 }
222213
214+ private isValidContextObject ( context : any ) : boolean {
215+ return (
216+ typeof context ?. Execution ?. Id === "string" &&
217+ typeof context ?. State ?. EnteredTime === "string" &&
218+ typeof context ?. State ?. Name === "string"
219+ ) ;
220+ }
221+
223222 /**
224223 * Parse a list of trace tags such as [_dd.p.tid=66bcb5eb00000000,_dd.p.dm=-0] and return the
225224 * value of the _dd.p.tid tag or an empty string if not found.
0 commit comments