โšก Onwuachi Control Plane

X-Ray: Distributed Tracing

Overview

X-Ray is AWS’s distributed tracing service. While CloudWatch metrics tell you what’s slow on average, X-Ray traces individual requests as they flow through multiple services โ€” showing exactly where latency or errors occur within a single transaction.

Why It Matters

In a microservices or serverless architecture, a slow response could originate from any service in the call chain. CloudWatch metrics show aggregate latency but can’t isolate which specific service call within a request caused the problem. X-Ray traces the full path of a single request and shows latency at every hop.

Where It Fits

DOP-C02 Domain 4 โ€” Monitoring and Logging

User request | v ALB โ†’ EC2 App (200ms) | +– DynamoDB query (50ms) | +– Lambda call (120ms) | +– S3 GetObject (30ms) | v X-Ray Service Map: visual graph of call chain with latency at each node


The Big Picture

CloudWatch metrics โ†’ “average API latency is 800ms” (aggregate) X-Ray trace โ†’ “this request took 800ms: 50ms DynamoDB + 700ms Lambda cold start” (individual)


Core Concepts

Components:

X-Ray SDK โ€” instrument application code to emit trace data:

X-Ray Daemon โ€” sidecar process that buffers and ships trace segments:

Service Map โ€” visual graph of all services and their connections:

Trace anatomy:

Trace (one complete request) | +– Segment (one service’s contribution) | +– Subsegment (individual operation: DB call, HTTP call, annotation)

Annotations vs Metadata:

Annotations โ€” key/value indexed for filtering: user_id, order_id, tenant_id “Show me all traces where user_id=12345” Metadata โ€” key/value NOT indexed, for debugging context only

Sampling โ€” cost control: Default: 5% of requests + reservoir of 1 request/second (first request per second always traced) Custom rules: trace 100% of /api/checkout but 1% of /api/health

Native integration (no SDK needed):


Real-World Example

No live lab โ€” X-Ray requires instrumented application code.

Exam scenarios:

“Identify which microservice is causing latency” โ†’ X-Ray Service Map

“Trace a specific user’s failed request through Lambda + DynamoDB” โ†’ X-Ray with Annotations (filter by user_id annotation)

“Reduce X-Ray cost in high-traffic production” โ†’ Adjust sampling rules โ€” reduce % for high-volume low-value paths

“Enable tracing on Lambda without code changes” โ†’ Enable Active Tracing in Lambda configuration (one toggle)


Engineering Analogy

X-Ray is the AWS equivalent of Jaeger or Zipkin โ€” distributed tracing standards (OpenTracing/OpenTelemetry) that track requests across service boundaries. The X-Ray Service Map is equivalent to Jaeger’s dependency graph. Annotations are equivalent to span tags in OpenTelemetry โ€” indexed fields that enable trace filtering and search.


Best Practices


Common Mistakes


Pro Tip

X-Ray Daemon on EC2 needs UDP port 2000 open in the security group for loopback (127.0.0.1) โ€” the SDK sends segments to the daemon locally. Outbound HTTPS to xray.us-east-1.amazonaws.com is also required for the daemon to ship to the X-Ray service.


Key Takeaways


Related Articles


References

System Context

โ† Back to Kb