Inferensys

Glossary

Span

A span is the fundamental unit of work in distributed tracing, representing a named, timed operation for a contiguous segment of work within a service.
Wide-angle shot of a modern WeWork open floor plan with creative walls covered in AI system architecture diagrams, product team collaborating in standing desk area with industrial lighting.
DISTRIBUTED TRACE COLLECTION

What is a Span?

In distributed tracing, a span is the fundamental building block for visualizing and diagnosing request flow across services.

A span is the fundamental unit of work in distributed tracing, representing a named, timed operation that constitutes a contiguous segment of execution within a single service, such as a function call, database query, or HTTP request. Each span contains a start time, duration, and a set of span attributes (key-value metadata) that describe the operation. Spans are linked together via parent-child relationships using trace IDs and span IDs to form a complete trace, which visualizes the end-to-end path of a request.

Spans are semantically classified by span kind (e.g., Client, Server, Internal) to clarify their role in the workflow. They can also include span links to causally connect to operations in other traces. Generated through manual or auto-instrumentation, spans are propagated between services via distributed context propagation standards like W3C Trace Context. This granular data is essential for constructing flame graphs for latency analysis and service graphs for dependency mapping in observability platforms.

ANATOMY OF A TRACE

Key Components of a Span

A span is the fundamental building block of a distributed trace. It represents a single, named, and timed operation within a service's workflow. Understanding its core components is essential for effective instrumentation and analysis.

01

Span Name & Identity

Every span is defined by a name (a string describing the operation, e.g., GET /api/user) and a set of unique identifiers. The Span ID uniquely identifies this specific span. Crucially, the span also carries a Trace ID, which is shared by all spans in the same end-to-end request, enabling correlation across services. These IDs are typically 16-byte random values.

02

Timing & Duration

A span encapsulates precise timing data, defining its lifecycle within the system.

  • Start Timestamp: The nanosecond-precise time the operation began.
  • End Timestamp: The time the operation completed.
  • Duration: Calculated as (End Timestamp - Start Timestamp). This is the primary metric for performance analysis, revealing latency bottlenecks in database queries, external API calls, or internal functions.
03

Span Context & Propagation

The span context is the immutable trace state that must be propagated across process boundaries. It contains the Trace ID, Span ID, and other metadata like sampling decisions. This context is injected into outbound requests (e.g., via HTTP headers like traceparent) and extracted from inbound requests, which is the mechanism that stitches distributed work into a single trace. The W3C Trace Context standard ensures interoperability between different tracing systems.

04

Span Kind

The span kind is a semantic attribute that classifies the span's role in a trace, which affects how timing and relationships are interpreted by analysis tools. The primary kinds are:

  • SERVER: For the receiver of a remote procedure call (e.g., an HTTP server handling a request).
  • CLIENT: For the initiator of a remote procedure call (e.g., an outgoing HTTP client call).
  • INTERNAL: For operations within the application boundary where no remote context is propagated.
  • PRODUCER/CONSUMER: For messaging systems (e.g., Kafka, RabbitMQ).
05

Attributes & Events

Attributes are key-value pairs that describe the span with contextual metadata. They are essential for filtering, grouping, and debugging. Examples include:

  • http.method: "GET"
  • db.system: "postgresql"
  • db.statement: "SELECT * FROM users"
  • Custom business data like user.id or order.value.

Events (or Annotations) are timestamped logs within a span's lifetime, such as exceptions (exception.type), debug messages, or significant state changes.

06

Relationships: Parent, Links, & Status

Spans exist within a hierarchy. A parent span represents the broader operation that triggered the current child span. This parent-child relationship forms the trace's call graph.

Span Links connect a span to zero or more causally related spans in other traces, used for modeling batch processing or asynchronous triggers.

Finally, a span status (e.g., OK, ERROR) provides a simple signal of the operation's success or failure, often derived from error attributes.

FUNDAMENTAL UNIT

How Spans Work in Distributed Tracing

A span is the fundamental, atomic building block of a distributed trace, representing a single, named, and timed operation within a service's execution path.

A span encapsulates a contiguous segment of work, such as a function call, database query, or HTTP request to another service. It is defined by an operation name, start and end timestamps, a set of span attributes (key-value metadata), a span kind (e.g., Client, Server), and a status. Each span has a unique Span ID and belongs to a trace via a shared Trace ID, forming the core data structure for observing latency and behavior within microservices and agentic systems.

Spans are organized into parent-child relationships to model call hierarchies, creating a visual timeline of a request's journey. This nesting allows the construction of a flame graph, where the width of each span bar represents its duration. By propagating span context (containing trace and span IDs) across service boundaries, disparate spans can be linked into a complete trace, enabling engineers to perform root-cause analysis across complex, distributed architectures like those used in autonomous agents.

DISTRIBUTED TRACING

Common Examples of Spans

A span is the fundamental building block of a trace, representing a single, timed operation. These are typical spans you will encounter when instrumenting a distributed system.

01

HTTP Client Request

A span representing an outbound HTTP call from a service to an external API or another microservice. This is a Client span kind.

  • Key Attributes: http.method (GET, POST), http.url, http.status_code, peer.service (name of the called service).
  • Timing: The span's duration measures the full round-trip time from sending the request to receiving the response.
  • Context Propagation: The span's trace context is injected into the HTTP headers (e.g., traceparent) to link to the downstream server span.
02

HTTP Server Handler

A span representing the processing of an incoming HTTP request. This is a Server span kind and is typically the parent of the client span that made the request.

  • Key Attributes: http.method, http.route (e.g., /api/v1/users), http.target (the full path), http.status_code.
  • Root Spans: Often the root span for a trace if the request originates from an uninstrumented source (like a user's browser or a load balancer).
  • Work Context: Encompasses the entire business logic executed to service the request, including any internal function calls or database queries.
03

Database Query

A span representing the execution of a single database operation, such as a SELECT, INSERT, or stored procedure call. This is typically an Internal span kind.

  • Key Attributes: db.system (postgresql, mysql, redis), db.statement (the query text, often sanitized), db.operation (query, insert), db.name (database name).
  • Performance Insight: This span's duration is critical for identifying slow queries and database bottlenecks.
  • Nesting: Usually a child span of a server handler or an internal processing span.
04

Message Producer/Consumer

Spans representing the publishing to or consumption from a message queue (e.g., Kafka, RabbitMQ, AWS SQS).

  • Producer Span (Kind: Producer): Created when a message is sent. Attributes include messaging.system, messaging.destination, and message.id.
  • Consumer Span (Kind: Consumer): Created when a message is processed. It is linked to the producer span via a span link, not a parent-child relationship, as they are in separate traces.
  • Asynchronous Context: Essential for tracing asynchronous, event-driven workflows where a request triggers a background job.
05

Internal Function/Method

A span representing a significant unit of work within a service's codebase, such as a core business logic function, algorithm, or external library call. This is an Internal span kind.

  • Purpose: Provides granular visibility into the internal call stack of a service, breaking down a server handler's work.
  • Attributes: Custom attributes like function.name, business.order_id, or processing.stage.
  • Instrumentation: Often requires manual or decorator-based instrumentation to create these fine-grained spans, as they are specific to the application's logic.
06

External API Call (RPC)

A span representing a call to an external service via a Remote Procedure Call (RPC) framework like gRPC or Thrift. This functions similarly to an HTTP client span but for RPC semantics.

  • Key Attributes: rpc.system (grpc), rpc.service, rpc.method, rpc.grpc.status_code.
  • High Precision: gRPC spans are particularly valuable due to the structured nature of the calls and the prevalence of streaming, which can be broken into multiple spans.
  • Propagation: Trace context is propagated through the RPC framework's metadata headers.
SPAN

Frequently Asked Questions

A span is the fundamental building block of distributed tracing. These questions address its core concepts, implementation, and role in agentic observability.

A span is the fundamental unit of work in distributed tracing, representing a named, timed operation that constitutes a contiguous segment of execution within a single service. It captures the lifecycle of a discrete piece of logic, such as a function call, a database query, an HTTP request to an external API, or an internal computation step within an autonomous agent.

Each span contains essential metadata:

  • Name: A descriptive identifier for the operation (e.g., tool.call:get_weather).
  • Start and End Timestamps: Precisely defines the operation's duration.
  • Span Context: Contains the globally unique Trace ID and its own unique Span ID, which are used to link spans into a complete trace.
  • Span Kind: A semantic classification (e.g., INTERNAL, CLIENT, SERVER) that defines the span's role.
  • Attributes/ Tags: Key-value pairs that add context (e.g., { "db.system": "postgresql", "db.statement": "SELECT * FROM users" }).
  • Status: Typically OK, ERROR, or UNSET.
  • Events: Timed, structured logs within the span (e.g., an exception being thrown).
  • Links: References to causally related spans in other traces.

In agentic observability, a single agent's execution—such as planning, tool calling, and reflection—is decomposed into a hierarchy of spans, providing a granular, step-by-step audit trail of its autonomous behavior.

Prasad Kumkar

About the author

Prasad Kumkar

CEO & MD, Inference Systems

Prasad Kumkar is the CEO & MD of Inference Systems and writes about AI systems architecture, LLM infrastructure, model serving, evaluation, and production deployment. Over 5+ years, he has worked across computer vision models, L5 autonomous vehicle systems, and LLM research, with a focus on taking complex AI ideas into real-world engineering systems.

His work and writing cover AI systems, large language models, AI agents, multimodal systems, autonomous systems, inference optimization, RAG, evaluation, and production AI engineering.