Tracing Distributed Requests with AWS X-Ray
This lesson explains how AWS X-Ray traces requests as they travel through distributed applications, showing where latency and errors occur between services.
Learning outcomes
After completing this lesson, you will be able to:
- Describe traces, segments and the service map.
- Describe how tracing is enabled on each compute service.
How X-Ray works
AWS X-Ray traces requests as they pass through the components of an application. Each request becomes a trace made of segments and subsegments, one for each service and each downstream call, recording the time spent and any errors. The service map draws every component with its latency and error rates, which shows where a slow or failing request spends its time.
Annotations, indexed key-value pairs added to traces, make traces searchable, for example by customer ID. Sampling records a representative share of requests to control cost. Applications are instrumented with OpenTelemetry, which AWS now recommends, because the X-Ray SDKs and daemon entered maintenance mode in February 2026.
The following diagram shows a trace through four components and its timeline.

Instrumentation
X-Ray traces each request through the services it passes, showing where time is spent and where errors occur, and tracing is enabled differently on each compute service. In Lambda, active tracing records a segment for every sampled invocation. In API Gateway, tracing is enabled on the stage, so traces start at the API. On EC2, ECS and EKS, the application sends trace data to a collector running beside it, an OpenTelemetry collector or the X-Ray daemon, which forwards it to X-Ray. The X-Ray SDKs and daemon entered maintenance mode in February 2026, so new applications use OpenTelemetry. The following table summarises the methods.
| Compute | How to enable tracing |
|---|---|
| Lambda | Turn on active tracing |
| API Gateway | Enable tracing on the stage |
| EC2, ECS, EKS | Run an OpenTelemetry collector (or the X-Ray daemon, in maintenance mode) beside the application |
AWS recommends OpenTelemetry for new instrumentation, and CloudWatch Application Signals builds service health dashboards and SLOs on the same trace data.
Tracing with X-Ray
A slow checkout
Checkout requests take five seconds, but every service's own metrics look normal. The request passes through API Gateway, three Lambda functions, DynamoDB and a third-party payment API.
| Step | Finding |
|---|---|
| Enable tracing on API Gateway and the functions | Each request becomes a trace |
| Open the service map | The payment function shows high latency |
| Inspect the traces | Most of the time is in calls to the payment API, retried three times |
The team adds a timeout and circuit breaker around the payment call. Without tracing, the delay between services would have been invisible.
What does an X-Ray service map show?
Show answer
The services a request passes through, with latency, error rates and faults for each connection, so bottlenecks can be found.
Exam Tips
Remember for the exam
- To find which microservice causes latency, use X-Ray.
- To trace requests across Lambda, API Gateway and other services, enable X-Ray tracing on each.
- On EC2 and containers, X-Ray needs a collector running beside the application: an OpenTelemetry collector, or the X-Ray daemon (in maintenance mode since February 2026).