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

(stepfunctions): cannot disable x-ray tracing #30796

Closed
Labels
@aws-cdk/aws-stepfunctions Related to AWS StepFunctions bug This issue is a bug. effort/small Small work item – less than a day of effort p3

Comments

@Tietew
Copy link
Contributor

Tietew commented Jul 9, 2024

Describe the bug

When I have a StateMachine with X-Ray tracing is enabled,
Setting tracingEnabled to false does not disable X-Ray tracing.

Expected Behavior

Changing tracingEnabled from true to false disables X-Ray tracing.

Current Behavior

Changing tracingEnabled to false does not modify X-Ray tracing.

Reproduction Steps

First deploy a StateMachine with tracingEnabled: true.
The stack creates an StateMacine with X-Ray tracing enabled.

new sfn.StateMachine(stack, 'StateMachine', {
  definitionBody: sfn.DefinitionBody.fromChainable(...),
  tracingEnabled: true,
});

Then, change tracingEnabled: false and deploy again.
X-Ray tracing is still enabled.

new sfn.StateMachine(stack, 'StateMachine', {
  definitionBody: sfn.DefinitionBody.fromChainable(...),
  tracingEnabled: false,
});

Possible Solution

When tracingEnabled is explictly false, render "TrancingConfiguration": {"Enabled": false} in template instead of undefined.

Additional Information/Context

Workaround: Following escape hatch can diable X-Ray tracing.

const machine = new sfn.StateMachine(stack, 'StateMachine', {
  definitionBody: sfn.DefinitionBody.fromChainable(...),
  tracingEnabled: false,
});
(machine.node.defaultChild as cdk.CfnResource).addPropertyOverride('TracingConfiguration', { Enabled: false });

CDK CLI Version

2.148.0

Framework Version

No response

Node.js Version

20.15.1

OS

Linux

Language

TypeScript

Language Version

No response

Other information

No response

@Tietew Tietew added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Jul 9, 2024
@github-actions github-actions bot added the @aws-cdk/aws-stepfunctions Related to AWS StepFunctions label Jul 9, 2024
@ashishdhingra ashishdhingra self-assigned this Jul 10, 2024
@ashishdhingra ashishdhingra added needs-reproduction This issue needs reproduction. and removed needs-triage This issue or PR still needs to be triaged. labels Jul 10, 2024
@ashishdhingra
Copy link
Contributor

Reproducible using code below (reference Creating a Lambda state machine for Step Functions using AWS CDK):

import * as cdk from 'aws-cdk-lib';
import { Construct } from 'constructs';
import * as lambda from 'aws-cdk-lib/aws-lambda';
import * as sfn from 'aws-cdk-lib/aws-stepfunctions';
import * as tasks from 'aws-cdk-lib/aws-stepfunctions-tasks';

export class Issue30796Stack extends cdk.Stack {
  constructor(scope: Construct, id: string, props?: cdk.StackProps) {
    super(scope, id, props);

    const helloFunction = new lambda.Function(this, 'MyLambdaFunction', {
      code: lambda.Code.fromInline(`
            exports.handler = (event, context, callback) => {
                callback(null, "Hello World!");
            };
        `),
      runtime: lambda.Runtime.NODEJS_18_X,
      handler: "index.handler",
      timeout: cdk.Duration.seconds(3)
    });
  
    const stateMachine = new sfn.StateMachine(this, 'MyStateMachine', {
      definition: new tasks.LambdaInvoke(this, "MyLambdaTask", {
        lambdaFunction: helloFunction
      }).next(new sfn.Succeed(this, "GreetedWorld")),
      tracingEnabled: true // false
    });
  }
}

Running cdk synth on 2nd deployment with tracingEnabled set to false generates the following CF template:

Resources:
  MyLambdaFunctionServiceRole313A4D46:
    Type: AWS::IAM::Role
    Properties:
      AssumeRolePolicyDocument:
        Statement:
          - Action: sts:AssumeRole
            Effect: Allow
            Principal:
              Service: lambda.amazonaws.com
        Version: "2012-10-17"
      ManagedPolicyArns:
        - Fn::Join:
            - ""
            - - "arn:"
              - Ref: AWS::Partition
              - :iam::aws:policy/service-role/AWSLambdaBasicExecutionRole
    Metadata:
      aws:cdk:path: Issue30796Stack/MyLambdaFunction/ServiceRole/Resource
  MyLambdaFunction67CCA873:
    Type: AWS::Lambda::Function
    Properties:
      Code:
        ZipFile: "

          \            exports.handler = (event, context, callback) => {

          \                callback(null, \"Hello World!\");

          \            };

          \        "
      Handler: index.handler
      Role:
        Fn::GetAtt:
          - MyLambdaFunctionServiceRole313A4D46
          - Arn
      Runtime: nodejs18.x
      Timeout: 3
    DependsOn:
      - MyLambdaFunctionServiceRole313A4D46
    Metadata:
      aws:cdk:path: Issue30796Stack/MyLambdaFunction/Resource
  MyStateMachineRoleD59FFEBC:
    Type: AWS::IAM::Role
    Properties:
      AssumeRolePolicyDocument:
        Statement:
          - Action: sts:AssumeRole
            Effect: Allow
            Principal:
              Service: states.amazonaws.com
        Version: "2012-10-17"
    Metadata:
      aws:cdk:path: Issue30796Stack/MyStateMachine/Role/Resource
  MyStateMachineRoleDefaultPolicyE468EB18:
    Type: AWS::IAM::Policy
    Properties:
      PolicyDocument:
        Statement:
          - Action: lambda:InvokeFunction
            Effect: Allow
            Resource:
              - Fn::GetAtt:
                  - MyLambdaFunction67CCA873
                  - Arn
              - Fn::Join:
                  - ""
                  - - Fn::GetAtt:
                        - MyLambdaFunction67CCA873
                        - Arn
                    - :*
        Version: "2012-10-17"
      PolicyName: MyStateMachineRoleDefaultPolicyE468EB18
      Roles:
        - Ref: MyStateMachineRoleD59FFEBC
    Metadata:
      aws:cdk:path: Issue30796Stack/MyStateMachine/Role/DefaultPolicy/Resource
  MyStateMachine6C968CA5:
    Type: AWS::StepFunctions::StateMachine
    Properties:
      DefinitionString:
        Fn::Join:
          - ""
          - - '{"StartAt":"MyLambdaTask","States":{"MyLambdaTask":{"Next":"GreetedWorld","Retry":[{"ErrorEquals":["Lambda.ClientExecutionTimeoutException","Lambda.ServiceException","Lambda.AWSLambdaException","Lambda.SdkClientException"],"IntervalSeconds":2,"MaxAttempts":6,"BackoffRate":2}],"Type":"Task","Resource":"arn:'
            - Ref: AWS::Partition
            - :states:::lambda:invoke","Parameters":{"FunctionName":"
            - Fn::GetAtt:
                - MyLambdaFunction67CCA873
                - Arn
            - '","Payload.$":"$"}},"GreetedWorld":{"Type":"Succeed"}}}'
      RoleArn:
        Fn::GetAtt:
          - MyStateMachineRoleD59FFEBC
          - Arn
    DependsOn:
      - MyStateMachineRoleDefaultPolicyE468EB18
      - MyStateMachineRoleD59FFEBC
    UpdateReplacePolicy: Delete
    DeletionPolicy: Delete
    Metadata:
      aws:cdk:path: Issue30796Stack/MyStateMachine/Resource
  CDKMetadata:
    Type: AWS::CDK::Metadata
    Properties:
      Analytics: v2:deflate64:H4sIAAAAAAAA/1WO0QqCQBBFv6X3dVLpoXchCApCP0DG3YkmdTecVYnFfw+1wJ7uucPMvZNCcjhCvMNRIm3qqOEKQuFR1wpHKUODbWUQwqm32rOzKrvbH0+KsYWQu4bm8aI317B+z3alSYmn1/17IaVHqQUuS+rZDq6m/wUIRa81kVGFR09X1A+2S/zWT5PKSVzf6bV5w5mzhtfvrDMET9kPaQxJAsnuKcxR11vPLUG+6gf2Bp9OAQEAAA==
...

Notice that it doesn't include below TracingConfiguration::Enabled property (which was included in 1st deployment as shown below):

      TracingConfiguration:
        Enabled: true

@ashishdhingra ashishdhingra added p2 effort/small Small work item – less than a day of effort and removed needs-reproduction This issue needs reproduction. labels Jul 10, 2024
@ashishdhingra ashishdhingra removed their assignment Jul 10, 2024
@ashishdhingra ashishdhingra added p3 and removed p2 labels Jul 10, 2024
mergify bot pushed a commit that referenced this issue Jul 31, 2024
### Issue # (if applicable)

Closes [#30796 .](#30796)

### Reason for this change



### Description of changes



### Description of how you validated changes



### Checklist
- [x] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md)

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
@mergify mergify bot closed this as completed in #30808 Jul 31, 2024
Copy link

Comments on closed issues and PRs are hard for our team to see.
If you need help, please open a new issue that references this one.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 31, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.