1.Trace IDs, Segments, and Propagation
A trace follows one request through every service that handled it. Each service sends a segment describing its own work; a segment breaks down into subsegments for downstream calls it made. What ties them together is a trace ID carried in an HTTP header — `X-Amzn-Trace-Id` for X-Ray — added by the first traced service and passed along by everything after it.
Key features
- X-Ray receives data as segments, groups segments sharing a trace ID into a trace, and processes traces into a service graph
- A segment records the host, the request, the response, the timing, and any errors; subsegments break the work down into individual downstream calls
- The tracing header is `X-Amzn-Trace-Id`, carrying `Root` (the trace ID), optionally `Parent` (the calling segment id), and `Sampled`
- The first X-Ray-integrated service a request hits adds the tracing header; every service after it propagates the same trace ID
- For services that do not send their own segments (DynamoDB, an external API), X-Ray builds an inferred segment from the caller's subsegment so the dependency still appears
- A tracing header can come from the client, so an application should strip incoming `X-Amzn-Trace-Id` rather than trust a caller-supplied trace ID or sampling decision — trace and service graph data are retained for 30 days
The tracing header fields
- Client → API: POST /checkout (No trace header yet)
- API → API: Adds Root=1-5759e988-…;Sampled=1 (Segment: API)
- API → Orders service: POST /orders + same Root, Parent=API segment id (Subsegment on API, segment on Orders)
- Orders service → DynamoDB: PutItem (Subsegment only — DynamoDB sends no segment, so X-Ray infers one)
- DynamoDB → Orders service: 200
- Orders service → API: 201
Signature
trace = segments (per service) + subsegments (per downstream call), grouped by Root trace ID
Segments (one per service) + subsegments (one per downstream call) grouped by a trace ID = a trace. `X-Amzn-Trace-Id` carries Root / Parent / Sampled, added at the front door and propagated onward — and every non-HTTP hop is somewhere you must carry it yourself.