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

Refactor sfn Lambda injection code my merging two functions #1459

Merged
merged 2 commits into from
Sep 18, 2024

Conversation

lym953
Copy link
Contributor

@lym953 lym953 commented Sep 16, 2024

What

Currently the injectContextForLambdaFunctions() function roughly looks like this:

const injectContextForLambdaFunctions = (...): boolean => {
  if (shouldUpdateStepForTracesMerging()) {
    addTraceContextToLambdaParameters()
    return true
  }
  return false
}

It calls shouldUpdateStepForTracesMerging().

This PR merges the two functions by moving the code of shouldUpdateStepForTracesMerging() into injectContextForLambdaFunctions().

Why?

We will soon have different instrumentation strategies depending on the existing state of Lambda definition, so shouldUpdateStepForTracesMerging() which has a boolean return value will no longer work.

Design doc: Fixing Step Function Instrumentation
A short description of what changes this PR introduces and why.

Testing

Passed the touched automated tests

Review checklist

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

if (Parameters) {
Parameters[`Payload.$`] = 'States.JsonMerge($$, $, false)'
}
export const addTraceContextToLambdaParameters = (Parameters: ParametersType): void => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Change Parameters param to be non-null, so the null-check can be removed.


// payload field not set
if (!step.Parameters.hasOwnProperty('Payload.$') && !step.Parameters.hasOwnProperty('Payload')) {
addTraceContextToLambdaParameters(step.Parameters)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Adding addTraceContextToLambdaParameters() before every return true

@datadog-datadog-prod-us1
Copy link

Datadog Report

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

✅ 0 Failed, 376 Passed, 0 Skipped, 1m 26.56s Total duration (2m 2.32s time saved)

@lym953 lym953 added serverless Related to [lambda, stepfunctions, cloud-run] chores Related to the CI or developer experience labels Sep 16, 2024
@lym953 lym953 marked this pull request as ready for review September 16, 2024 22:07
@lym953 lym953 requested review from a team as code owners September 16, 2024 22:07
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.

lgtm! 🚢

Base automatically changed from yiming.luo/fix-step-func-9 to master September 18, 2024 16:44
@lym953 lym953 merged commit f6d78ec into master Sep 18, 2024
19 of 20 checks passed
@lym953 lym953 deleted the yiming.luo/fix-step-func-7 branch September 18, 2024 16:44
@lym953 lym953 changed the title Refactor xfn Lambda injection code my merging two functions Refactor sfn Lambda injection code my merging two functions Sep 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
chores Related to the CI or developer experience serverless Related to [lambda, stepfunctions, cloud-run]
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants