DataDog / serverless-plugin-datadog

Serverless plugin to automagically instrument your Lambda functions with Datadog
Apache License 2.0
96 stars 49 forks source link

feat: Inject context for sfn->Lambda when Payload is an object (case 2) #530

Closed lym953 closed 2 months ago

lym953 commented 2 months ago

What and why?

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

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

Sub-cases:

Case 2.1: Already instrumented

      "Parameters": {
        "Payload": {
          "Execution.$": "$$.Execution",
          "State.$": "$$.State"
          "StateMachine.$": "$$.StateMachine"
        },
      },

Then just print a message.

Case 2.2: Already has Execution, State or StateMachine field

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

      "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, State or StateMachine field

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

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

then just add the two fields:

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

Testing

Passed the added tests

Types of changes

Check all that apply

lym953 commented 2 months ago

/merge

dd-devflow[bot] commented 2 months ago

:steam_locomotive: MergeQueue: waiting for PR to be ready

This merge request is not mergeable yet, because of pending checks/missing approvals. It will be added to the queue as soon as checks pass and/or get approvals. Note: if you pushed new commits since the last approval, you may need additional approval. You can remove it from the waiting list with /remove command.

Use /merge -c to cancel this operation!

dd-devflow[bot] commented 2 months ago

:steam_locomotive: MergeQueue: pull request added to the queue

The median merge time in main is 2m.

Use /merge -c to cancel this operation!