Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle sfn->Lambda context injection when Payload is used without $ (case 2) #1462

Merged
merged 1 commit into from
Sep 18, 2024

Conversation

lym953
Copy link
Contributor

@lym953 lym953 commented Sep 18, 2024

What and why?

This PR handles Step Function context injection into Lambda when Payload (not Payload.$) is used in the Lambda execution step.

This is case # 2 in this design doc: Fixing Step Function Instrumentation

Sub-cases:

Case 2.1: Already instrumented

    "Lambda Invoke": {
      "Parameters": {
        "Payload": {
          "Execution.$": "$$.Execution",
          "State.$": "$$.State"
        },
      },
    },

Then just print a message.

Case 2.2: Already has Execution or State field

If the payload already has any of Execution.$, Execution, State.$ or State, e.g.

    "Lambda Invoke": {
      "Parameters": {
        "Payload": {
          "State": {
            "Name": 'Lambda Invoke'
          }
        },
      },
    },

and it's not case 2.1, then print a warning and skip context injection

Case 2.3: no Execution or State field

i.e. it's not Case 2.1 or 2.2, e.g.

    "Lambda Invoke": {
      "Parameters": {
        "Payload": {
          "CustomerId": 42
        },
      },
    },

then just add the two fields:

    "Lambda Invoke": {
      "Parameters": {
        "Payload": {
          "CustomerId": 42,
          "Execution.$": "$$.Execution",
          "State.$": "$$.State"
        },
      },
    },

Testing

Passed the added tests

Review checklist

  • Feature or bugfix MUST have appropriate tests (unit, integration)

@lym953 lym953 added enhancement New feature or request serverless Related to [lambda, stepfunctions, cloud-run] labels Sep 18, 2024
@lym953 lym953 requested review from a team as code owners September 18, 2024 17:52
@datadog-datadog-prod-us1
Copy link

datadog-datadog-prod-us1 bot commented Sep 18, 2024

Datadog Report

Branch report: yiming.luo/fix-step-func-11
Commit report: 5120374
Test service: datadog-ci-tests

✅ 0 Failed, 392 Passed, 0 Skipped, 1m 29.12s Total duration (2m 0.74s time saved)

Copy link
Contributor

@avedmala avedmala left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One minor change but LGTM otherwise, thank you!!

return false
} else {
const payload = step.Parameters.Payload
if (payload['Execution.$'] === '$$.Execution' && payload['State.$'] === '$$.State') {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we also check for StateMachine in this statement as the current layers require it to be set

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch!

Base automatically changed from yiming.luo/fix-step-func-10 to master September 18, 2024 18:58
@lym953 lym953 changed the title Handle xfn->Lambda context injection when Payload is used without $ (case 2) Handle sfn->Lambda context injection when Payload is used without $ (case 2) Sep 18, 2024
@lym953 lym953 merged commit e04a645 into master Sep 18, 2024
18 checks passed
@lym953 lym953 deleted the yiming.luo/fix-step-func-11 branch September 18, 2024 19:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request serverless Related to [lambda, stepfunctions, cloud-run]
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants