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.
| Field | Purpose | Typical example |
|---|---|---|
| Trace ID | Groups every span of one request | 16-byte random identifier |
| Span ID | Identifies this span uniquely | 8-byte random identifier |
| Parent span ID | Links the span to its caller | Empty for the root span |
| Name | Describes the operation | GET /orders/{id} |
| Start and end time | Gives the duration | Nanosecond timestamps |
| Span kind | States the role in the call | Server, client, producer |
| Attributes | Key-value context | http.response.status_code = 503 |
| Status | Marks success or failure | Unset, ok or error |
| Events and links | Timestamped notes and cross-trace references | Exception event with stack trace |
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 kind | Represents | Common example |
|---|---|---|
| Server | Handling an incoming synchronous request | An API endpoint receiving a call |
| Client | Making an outgoing synchronous request | A service calling a payment API |
| Producer | Sending a message for later processing | Publishing to a message queue |
| Consumer | Receiving and processing a message | A worker reading from the queue |
| Internal | An operation inside one process | Rendering a template or hashing data |
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.
| Signal | Unit of data | Best answers | Main limitation |
|---|---|---|---|
| Span | One timed operation | How long did this step take and why did it fail? | Little meaning in isolation |
| Trace | Tree of spans for one request | Where did the request spend its time? | Usually sampled, not complete |
| Log | Timestamped event record | What exactly happened at this moment? | Hard to correlate without IDs |
| Metric | Aggregated numeric time series | How is the system behaving overall? | No per-request detail |
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.