Span · distributed tracing

Also known as: trace span

On this page 7

A span in distributed tracing is the basic unit of work recorded for a request: a named, timed operation with a start time, a duration, a parent reference and descriptive attributes. In observability for cloud systems, spans are linked into a tree called a trace, so engineers can follow a single request as it travels through gateways, microservices, queues and databases.

Each trace span answers three practical questions: what happened, how long it took and where it sat in the call chain. The term is used here only in this tracing sense, not for spans of time in metrics dashboards or for text spans in document markup.

What a span contains

A span carries a fixed core of identifiers and timing data plus optional context. The OpenTelemetry specification, which most modern tracing tools follow, defines the fields listed below; older formats such as Zipkin and Jaeger use nearly identical concepts with slightly different names.

FieldPurposeTypical example
Trace IDGroups every span of one request16-byte random identifier
Span IDIdentifies this span uniquely8-byte random identifier
Parent span IDLinks the span to its callerEmpty for the root span
NameDescribes the operationGET /orders/{id}
Start and end timeGives the durationNanosecond timestamps
Span kindStates the role in the callServer, client, producer
AttributesKey-value contexthttp.response.status_code = 503
StatusMarks success or failureUnset, ok or error
Events and linksTimestamped notes and cross-trace referencesException event with stack trace
Core fields of a span in the OpenTelemetry data model

Span names should have low cardinality. A name such as GET /orders/{id} groups thousands of requests usefully, while a name that embeds the actual order number creates millions of unique values and makes aggregation impossible. High-cardinality details belong in attributes, not in the name.

How spans form a trace

Spans become a trace through parent-child relationships and context propagation. When a service receives a request, it creates a server span; when it calls another service, it creates a client span and passes the trace ID and its own span ID in request headers, typically the W3C Trace Context traceparent header.

The receiving service reads that header and creates a new span whose parent is the caller’s client span. Repeating this at every hop produces a directed tree, with the root span representing the whole request as seen by the first component. Tracing backends render this tree as a waterfall or Gantt-style timeline in which nested bars show where time was spent.

The span kind tells the backend how to interpret each node in that tree, as the table below shows.

Span kindRepresentsCommon example
ServerHandling an incoming synchronous requestAn API endpoint receiving a call
ClientMaking an outgoing synchronous requestA service calling a payment API
ProducerSending a message for later processingPublishing to a message queue
ConsumerReceiving and processing a messageA worker reading from the queue
InternalAn operation inside one processRendering a template or hashing data
Span kinds and when each applies

Asynchronous flows often use span links rather than strict parenting. A batch job that processes a hundred queued messages can link to a hundred producer spans, because a single parent would misrepresent the causal relationship.

Spans compared with logs, metrics and traces

A span is one building block of a trace, and it overlaps with the other observability signals without replacing them. Understanding the boundaries helps teams decide where to record each piece of information.

SignalUnit of dataBest answersMain limitation
SpanOne timed operationHow long did this step take and why did it fail?Little meaning in isolation
TraceTree of spans for one requestWhere did the request spend its time?Usually sampled, not complete
LogTimestamped event recordWhat exactly happened at this moment?Hard to correlate without IDs
MetricAggregated numeric time seriesHow is the system behaving overall?No per-request detail
Span compared with related observability signals

Modern practice correlates the signals: logs include the active trace and span IDs, and metrics can carry exemplars that point to representative traces. Many teams also derive request rate, error rate and latency metrics directly from spans, which keeps the golden signals consistent with trace data.

Creating spans through instrumentation

Spans are produced by instrumentation, which can be automatic or manual. Automatic instrumentation wraps common libraries such as HTTP servers, gRPC clients and database drivers, so a service emits useful spans with little or no code change.

Manual instrumentation adds custom spans around business operations that libraries cannot see, such as pricing calculations or cache decisions. Good practice is to add attributes that aid diagnosis, such as tenant tier or feature flag state, while never recording secrets or personal data in span attributes.

Spans flow from the instrumented application to an exporter, often through a collector, and then to a backend such as Jaeger or a commercial platform. Because volume can be enormous, systems apply sampling: head-based sampling decides at the root whether to keep a trace, while tail-based sampling decides after the trace completes and can retain all slow or failed requests.

Common span design mistakes

Poorly designed spans make traces noisy, expensive or misleading. The following mistakes appear frequently in production systems.

  • Broken context propagation splits one request into several disconnected traces, often at a proxy or queue that drops headers.
  • Too many tiny spans, such as one per loop iteration, inflate storage costs and hide the important steps.
  • High-cardinality span names prevent grouping and overload backend indexes.
  • Unclosed spans caused by missing error handling produce incorrect durations or vanish from exports.
  • Clock skew between hosts can make a child span appear to start before its parent; backends adjust for it only partly.

A useful rule of thumb is to create a span for every network boundary and every significant unit of business logic, and to put everything else into attributes or span events.

In plain words

Imagine tracking a parcel. Each scan at a sorting center records where the parcel was, when it arrived and when it left. A span is one of those scans for a computer request.

Put all the scans for one parcel together and the whole journey becomes visible, including the depot where it sat for two days. Engineers do the same with spans to see exactly which step made a request slow or caused it to fail.

A real-world example

An online travel booking service sees its checkout page slow down from about 400 milliseconds to more than 3 seconds for some users. Dashboards show higher latency but no obvious cause, so an engineer opens a slow trace in the tracing backend.

The waterfall shows the root server span for the checkout request, child spans for the pricing, inventory and payment services, and inside the inventory span a client span to a database lasting 2.6 seconds. Its attributes show a query against a table that lost an index during a recent migration. The team restores the index, and within an hour traces confirm checkout latency is back below 450 milliseconds.