A trace (distributed trace) is the end-to-end record of a single request or transaction as it travels through a distributed system. It consists of spans, each describing one timed operation such as an HTTP call or a database query, linked by a shared trace ID and parent-child relationships, so you can see where time was spent and where errors occurred.
What is a trace?
A trace, often called a distributed trace, shows what happened to one request on its way through your system. When a user clicks "Pay", the request may pass through an API gateway, a checkout service, a payment service, a fraud check, a message queue and two databases. Each of these steps is recorded as a span. All spans of the same request share one trace ID, and together they form the trace.
Traces are one of the three classic telemetry signals next to metrics and logs. Metrics tell you that latency rose, logs tell you what a component reported, and a trace tells you where in the call chain the time was lost and which service caused an error. In architectures with many services, such as microservices, this request-centric view is often the fastest way to find the responsible component.
Structure: spans, parent-child relationships and timing
A trace is a tree, more precisely a directed acyclic graph, of spans. The first span, created where the request enters the system, is the root span. Every downstream operation creates a child span that references its parent span ID. Each span contains:
- a name, for example
GET /orders/{id}orSELECT orders, - start time and duration,
- a span kind such as server, client, producer, consumer or internal,
- attributes like
http.response.status_codeordb.system.name, - a status (unset, ok or error) and optional span events and links.
Visualized as a waterfall or Gantt chart, the trace shows which calls ran in sequence, which ran in parallel and which span dominated the total duration. Span links connect traces that are related but not in a direct parent-child relationship, for example a batch job that processes messages from many different requests.
How a trace crosses service boundaries
For spans from different processes to end up in the same trace, the trace context must travel with the request. This is called context propagation. Over HTTP, the W3C Trace Context standard defines the traceparent header, which carries the version, trace ID, parent span ID and trace flags:
traceparent: 00-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-01
For message queues the context is written into message headers. If one service in the chain does not forward the context, the trace breaks into separate fragments. Incomplete traces are therefore usually a propagation problem, not a storage problem.
Creating traces with OpenTelemetry
Today most traces are produced with OpenTelemetry. Automatic instrumentation for frameworks and libraries creates server, client and database spans without code changes, and the OpenTelemetry API lets you add custom spans for business logic, such as calculate_shipping. The SDK batches finished spans and sends them via OTLP, usually through an OpenTelemetry Collector, to the backend.
Because a busy system produces enormous numbers of spans, teams apply sampling. Head-based sampling decides at the start of a request, tail-based sampling decides after the trace is complete and can keep all slow or failed traces while discarding a share of the fast, successful ones.
What traces are used for
- Latency analysis: find the span responsible for slow requests, for example a slow query or a sequential chain of calls that could run in parallel.
- Error analysis: see in which service an error originated and how it propagated upstream.
- Dependency discovery: aggregated traces reveal which services call each other and form the basis of a service map.
- Pattern detection: recognize anti-patterns such as N+1 queries or retry loops directly in the span tree.
- Correlation: logs that carry the trace ID and metrics with exemplars lead straight to the matching trace.
A typical incident workflow: an alert reports higher p99 latency on the checkout endpoint. Through an exemplar on the latency chart you open a slow trace, see in the waterfall that a database span in the inventory service takes most of the time, and jump from there to the logs of exactly this request. Instead of testing hypotheses across many services, the trace leads straight to the affected spot.
Best practices
- Propagate context consistently across all protocols, including queues and asynchronous jobs.
- Use the OpenTelemetry semantic conventions for span names and attributes so that traces from different languages are comparable.
- Keep span names low in cardinality; put IDs into attributes, not into the name.
- Write the trace ID into every log line so you can jump from a log to the trace and back.
- Keep all error traces and the slowest requests when you sample.
How Obseria helps
Obseria ingests OpenTelemetry traces natively via OTLP. Distributed tracing in Obseria shows each trace as a waterfall with correlated logs, metrics and profiles. The Obseria Pipeline can apply tail-based sampling before storage, and TopoGraph derives the service topology automatically from the spans.