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

feat: Support StepFunction->StepFunction trace merging #326

Merged
merged 2 commits into from
Nov 14, 2024

Conversation

lym953
Copy link
Contributor

@lym953 lym953 commented Nov 13, 2024

What does this PR do?

Support merging Step Function traces with downstream StepFunction StartExecution task traces.

If the user constructs the task using:

    const invokeChildStateMachineTask = new tasks.StepFunctionsStartExecution(this, "InvokeChildStateMachineTask", {
      stateMachine: childStateMachine,
      input: sfn.TaskInput.fromObject(
        DatadogStepFunctions.buildStepFunctionTaskPayloadToMergeTraces({ "custom-key": "custom-value" }),
      ),
    });

then we will add these fields to the input to the State Machine:

"CONTEXT.$": "$$['Execution', 'State', 'StateMachine']"

Motivation

Testing Guidelines

Testing Guidelines

Automated testing

Passed the added unit tests.

Manual testing

Steps
  1. Deploy the example typescript step function stack
  2. Run the State Machine once
Result
  1. The `CONTEXT.$1 field is added to Step Function step input
image 2. The flame graph of the step function also shows the flame graph of the inner step function Screenshot 2024-11-13 at 3 00 58 PM

Additional Notes

Types of Changes

  • Bug fix
  • New feature
  • Breaking change
  • Misc (docs, refactoring, dependency upgrade, etc.)

Check all that apply

  • This PR's description is comprehensive
  • This PR contains breaking changes that are documented in the description
  • This PR introduces new APIs or parameters that are documented and unlikely to change in the foreseeable future
  • This PR impacts documentation, and it has been updated (or a ticket has been logged)
  • This PR's changes are covered by the automated tests
  • This PR collects user input/sensitive content into Datadog

@lym953 lym953 requested a review from a team as a code owner November 13, 2024 20:08
@@ -26,6 +29,12 @@ export class DatadogStepFunctions extends Construct {
return buildStepFunctionLambdaStepPayloadToMergeTraces(payload);
}

public static buildStepFunctionTaskPayloadToMergeTraces(payload: { [key: string]: any } = {}): {

Choose a reason for hiding this comment

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

Code Quality Violation

Unexpected any. Specify a different type. (...read more)

Do not use the any type, as it is too broad and can lead to unexpected behavior.

View in Datadog  Leave us feedback  Documentation

*/

export function buildStepFunctionSfnExecutionStepPayloadToMergeTraces(payload: { [key: string]: any } = {}): {
[key: string]: any;

Choose a reason for hiding this comment

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

Code Quality Violation

Unexpected any. Specify a different type. (...read more)

Do not use the any type, as it is too broad and can lead to unexpected behavior.

View in Datadog  Leave us feedback  Documentation

@@ -26,6 +29,12 @@
return buildStepFunctionLambdaStepPayloadToMergeTraces(payload);
}

public static buildStepFunctionTaskPayloadToMergeTraces(payload: { [key: string]: any } = {}): {
[key: string]: any;

Choose a reason for hiding this comment

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

Code Quality Violation

Unexpected any. Specify a different type. (...read more)

Do not use the any type, as it is too broad and can lead to unexpected behavior.

View in Datadog  Leave us feedback  Documentation

src/span-link.ts Outdated
* @throws {ConflictError} If the payload already contains `CONTEXT` or `CONTEXT.$` fields.
*/

export function buildStepFunctionSfnExecutionStepPayloadToMergeTraces(payload: { [key: string]: any } = {}): {

Choose a reason for hiding this comment

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

Code Quality Violation

Unexpected any. Specify a different type. (...read more)

Do not use the any type, as it is too broad and can lead to unexpected behavior.

View in Datadog  Leave us feedback  Documentation

@lym953 lym953 force-pushed the yiming.luo/step-function-support-6 branch from f6c4700 to b48ae76 Compare November 13, 2024 20:13
@lym953 lym953 force-pushed the yiming.luo/step-function-support-7 branch from faacd0d to b58f77d Compare November 13, 2024 20:17
Copy link

@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.

LGTM, thanks Yiming!

@@ -26,6 +29,12 @@ export class DatadogStepFunctions extends Construct {
return buildStepFunctionLambdaTaskPayloadToMergeTraces(payload);
}

public static buildStepFunctionTaskPayloadToMergeTraces(payload: { [key: string]: any } = {}): {

Choose a reason for hiding this comment

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

nit: StepFunctions have "Input" argument while Lambda has "Payload" argument

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! Will fix.

Base automatically changed from yiming.luo/step-function-support-6 to main November 14, 2024 18:17
@lym953 lym953 force-pushed the yiming.luo/step-function-support-7 branch from b58f77d to 44dabdc Compare November 14, 2024 18:29
@lym953 lym953 merged commit 0fc4e7d into main Nov 14, 2024
9 checks passed
@lym953 lym953 deleted the yiming.luo/step-function-support-7 branch November 14, 2024 18:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants