Skill 4.2.4

Implement tracing by using AWS services and tools.

Key Concepts

For Lambda, enable active tracing; for API Gateway, enable X-Ray tracing on the stage; Step Functions, SNS, SQS and EventBridge also propagate trace context. To trace calls your code makes, instrument the AWS SDK and HTTP clients with AWS Distro for OpenTelemetry (ADOT), Powertools Tracer or the X-Ray SDK, which create subsegments for each downstream call. The X-Ray SDKs and daemon entered maintenance mode in February 2026, so AWS recommends OpenTelemetry for new instrumentation.

On EC2, ECS and on-premises servers, run the X-Ray daemon or the ADOT collector (as a sidecar container on ECS) to send trace data, and give the role xray:PutTraceSegments and xray:PutTelemetryRecords. Sampling rules control volume and cost, and trace context passes between services in the X-Amzn-Trace-Id header.

With the X-Ray SDK or Powertools Tracer, code adds annotations (strings, numbers or booleans) to a segment or subsegment, such as customer_id or order_type. Annotations are indexed, so you can filter traces with expressions like annotation.customer_id = "123" and use them in trace groups.

Metadata can hold any object, such as full request payloads, but is not indexed or searchable. Each trace supports up to 50 annotations. You can also create custom subsegments around important blocks of code to time them separately.