AWS X-Ray and StepFunctions -> can't get TraceHeader

633 views Asked by At

I would like to get to get the trace of a specific execution of my Stepfunction.
I'm 100% i enable X-Ray for my stepfunction and give it a full access permissions.

I created a lambda with boto3 that describe_execution of a given executionArn.
The problem is that the response is incomplete ! It doesn't give me the traceHeader. (https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/stepfunctions.html)

My Lambda code:

import json
import boto3
import pprint
import botocore

def lambda_handler(event, context):

    clientStepFunction = boto3.client('stepfunctions')
    
    try:
        response = clientStepFunction.describe_execution(executionArn="execArn...")
        pprint.pprint(response)
    except clientStepFunction.exceptions.ExecutionDoesNotExist:
        print("Error Execution doesn't exists")
    except clientStepFunction.exceptions.InvalidArn:
        print("Error invalid arn")

    return {
        'statusCode': 200,
        'body': json.dumps('Hello from Lamerarara!')
    }

I pretty printed the response:

{'ResponseMetadata': {...},
 'executionArn': 'execArn',
 'input': '{\n  "IsHelloWorldExample": true\n}',
 'name': 'execName',
 'output': '[{\n'
           '  "IsHelloWorldExample": true\n'
           '},{\n'
           '  "IsHelloWorldExample": true\n'
           '}]',
 'startDate': datetime.datetime(2020, 10, 16, 13, 21, 6, 724000, tzinfo=tzlocal()),
 'stateMachineArn': 'stepMachineArn',
 'status': 'SUCCEEDED',
 'stopDate': datetime.datetime(2020, 10, 16, 13, 21, 10, 191000, tzinfo=tzlocal())}

Thanks!

SOLUTION:

finally it was a the version of boto3. Currently boto3 version on aws is not the latest. you need boto3 1.15+ to get traceHeader

1

There are 1 answers

1
Lei Wang On

Have you tried to follow this sample to add xray patch_all() to enable AWS sdk instrumentation in your Lambda? also don't forget to add dependency aws-xray-sdk