Skip to content

Commit

Permalink
Refactor step function code by flipping if-condition
Browse files Browse the repository at this point in the history
  • Loading branch information
lym953 committed Sep 16, 2024
1 parent 998b0be commit 27109b8
Showing 1 changed file with 44 additions and 44 deletions.
88 changes: 44 additions & 44 deletions src/commands/stepfunctions/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,36 +126,36 @@ export const addTraceContextToStepFunctionParameters = ({Parameters}: StepType):
}

export const shouldUpdateStepForTracesMerging = (step: StepType, context: BaseContext, stepName: string): boolean => {
// is default lambda api
if (step.Resource === 'arn:aws:states:::lambda:invoke') {
if (!step.Parameters) {
context.stdout
.write(`[Warn] Step ${stepName} does not have a Parameters field. Step Functions Context Object injection \
// not default lambda api
if (step.Resource !== 'arn:aws:states:::lambda:invoke') {
return false
}

if (!step.Parameters) {
context.stdout
.write(`[Warn] Step ${stepName} does not have a Parameters field. Step Functions Context Object injection \
skipped. Your Step Functions trace will not be merged with downstream Lambda traces. To manually merge these traces, \
check out https://docs.datadoghq.com/serverless/step_functions/troubleshooting/\n`)

return false
}
return false
}

// payload field not set
if (!step.Parameters.hasOwnProperty('Payload.$') && !step.Parameters.hasOwnProperty('Payload')) {
return true
}
// payload field not set
if (!step.Parameters.hasOwnProperty('Payload.$') && !step.Parameters.hasOwnProperty('Payload')) {
return true
}

// default payload
if (step.Parameters['Payload.$'] === '$') {
return true
}
// default payload
if (step.Parameters['Payload.$'] === '$') {
return true
}

// custom payload
context.stdout
.write(`[Warn] Step ${stepName} has a custom Payload field. Step Functions Context Object injection skipped. \
// custom payload
context.stdout
.write(`[Warn] Step ${stepName} has a custom Payload field. Step Functions Context Object injection skipped. \
Your Step Functions trace will not be merged with downstream Lambda traces. To manually merge these traces, \
check out https://docs.datadoghq.com/serverless/step_functions/troubleshooting/\n`)

return false
}

return false
}

Expand All @@ -172,42 +172,42 @@ export const shouldUpdateStepForStepFunctionContextInjection = (
context: BaseContext,
stepName: string
): boolean => {
// is default lambda api
if (step.Resource?.startsWith('arn:aws:states:::states:startExecution')) {
if (!step.Parameters) {
context.stdout
.write(`[Warn] Step ${stepName} does not have a Parameters field. Step Functions Context Object injection \
// not default lambda api
if (!step.Resource?.startsWith('arn:aws:states:::states:startExecution')) {
return false
}

if (!step.Parameters) {
context.stdout
.write(`[Warn] Step ${stepName} does not have a Parameters field. Step Functions Context Object injection \
skipped. Your Step Functions trace will not be merged with downstream Step Function traces. To manually merge these \
traces, check out https://docs.datadoghq.com/serverless/step_functions/troubleshooting/\n`)

return false
}
return false
}

if (!step.Parameters.Input) {
return true
}
if (!step.Parameters.Input) {
return true
}

if (typeof step.Parameters.Input !== 'object') {
context.stdout
.write(`[Warn] Step ${stepName}'s Parameters.Input field is not a JSON object. Step Functions Context Object \
if (typeof step.Parameters.Input !== 'object') {
context.stdout
.write(`[Warn] Step ${stepName}'s Parameters.Input field is not a JSON object. Step Functions Context Object \
injection skipped. Your Step Functions trace will not be merged with downstream Step Function traces. To manually \
merge these traces, check out https://docs.datadoghq.com/serverless/step_functions/troubleshooting/\n`)

return false
}
return false
}

if (!step.Parameters.Input['CONTEXT.$'] && !step.Parameters.Input['CONTEXT']) {
return true
}
if (!step.Parameters.Input['CONTEXT.$'] && !step.Parameters.Input['CONTEXT']) {
return true
}

context.stdout
.write(`[Warn] Step ${stepName}'s Parameters.Input field has a custom CONTEXT field. Step Functions Context \
context.stdout
.write(`[Warn] Step ${stepName}'s Parameters.Input field has a custom CONTEXT field. Step Functions Context \
Object injection skipped. Your Step Functions trace will not be merged with downstream Step Function traces. To \
manually merge these traces, check out https://docs.datadoghq.com/serverless/step_functions/troubleshooting/\n`)

return false
}

return false
}

Expand Down

0 comments on commit 27109b8

Please sign in to comment.