Lesson 4 of 4 Monitoring and Governance

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.

An X-Ray trace of a slow checkout request. Each component records a segment with its time and errors, and the service map shows that most of the request's time is spent in the call to the payment API, which is where to look first.
The timings are illustrative. The slow segment, not the function that called it, is where tuning starts.

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.

ComputeHow to enable tracing
LambdaTurn on active tracing
API GatewayEnable tracing on the stage
EC2, ECS, EKSRun 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.

True or false

Tracing with X-Ray

Exam skills 2.2.3

Check how tracing is enabled on each service.

Log in to try this activity Interactive activities are free with an account.
Worked example

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.

StepFinding
Enable tracing on API Gateway and the functionsEach request becomes a trace
Open the service mapThe payment function shows high latency
Inspect the tracesMost 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.

Check yourself

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