Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/nicholas.hulston/upgrade-dd-trac…
Browse files Browse the repository at this point in the history
…e-4.50.0' into nicholas.hulston/upgrade-dd-trace-4.50.0
  • Loading branch information
nhulston committed Nov 22, 2024
2 parents 4da98ec + 9a03b27 commit 8a96e5a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 15 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
27 changes: 13 additions & 14 deletions src/trace/step-function-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -199,27 +199,26 @@ 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,
};
}

logDebug("Cannot extract StateMachine context! Invalid execution or state data.");
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.
Expand Down

0 comments on commit 8a96e5a

Please sign in to comment.