Tracing Lambda functions

All the Python based lambda functions invoked by StepFunctions (ReadDynamoDB, PriceLessThan55, PriceGreatThan55) in the application use AWS Distro for Open Telemetry (ADOT) to collect traces and send them to AWS X-Ray. Read the documentation for additional details on this topic.

Enabling tracing using ADOT Collector

The AWS Distro for OpenTelemetry Lambda (ADOT Lambda) layer for AWS Lambda provides a plug and play user experience by automatically instrumenting a Lambda function, by packaging OpenTelemetry Python together with an out-of-the-box configuration for AWS Lambda and AWS X-Ray.

Tracing using ADOT can be done by simply following these 3 simple steps:

  1. Add the ADOT Lambda layer
  2. Add the environment variable AWS_LAMBDA_EXEC_WRAPPER = /opt/python/adot-instrument to your Lambda function.
  3. Enable Active Tracing in your Lambda function

Go to ./pet_stack/cdk/lib/services/stepfn.ts and see the CDK Typescript code below. A new Lambda layer gets added created as show below:

ADOT Lambda Layer

In the following function the ADOT Layer is being added and the environment variable is also added which enables tracing through ADOT. ADOT Lambda Layer

As a result, the traces from these lambda functions are being captured in X-Ray as shown in the screenshot below.

Service Lens Lambda tracing