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 and 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 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.

The ./pet_stack/cdk/lib/services/stepfn.ts file contains the following CDK Typescript code. A new Lambda layer gets added created as show below:

ADOT Lambda Layer

The following function adds the ADOT Layer. 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

This concludes the AWS Distro for OpenTelemetry module.