Inferensys

Glossary

Span Attributes

Span attributes are key-value pairs attached to a span in distributed tracing that provide descriptive metadata about the operation, such as HTTP method, URL, or custom business data.
Data scientist building training data pipeline on laptop, data preprocessing visible, technical workspace.
DISTRIBUTED TRACE COLLECTION

What are Span Attributes?

Span attributes are the descriptive metadata attached to a span in a distributed trace, providing essential context about the operation it represents.

Span attributes are key-value pairs attached to a span that provide descriptive metadata about the operation it represents, such as HTTP method, URL, database query, or custom business data. They are the primary mechanism for enriching raw timing data with semantic context, transforming a simple duration measurement into a queryable, analyzable record. In standards like OpenTelemetry, attributes are defined with specific data types and are essential for filtering, aggregating, and diagnosing issues within distributed tracing systems.

Attributes are categorized into two primary types: semantic conventions, which are standardized keys for common operations (e.g., http.method, db.system), and custom attributes for application-specific context (e.g., user.id, shopping_cart.total). They enable powerful analytics, such as calculating the p95 latency for all POST requests to a specific endpoint or identifying all traces where a particular error code occurred. Effective use of attributes is critical for achieving observability, allowing engineers to ask arbitrary questions about system behavior without pre-instrumenting specific metrics.

DISTRIBUTED TRACE COLLECTION

Key Characteristics of Span Attributes

Span attributes are key-value pairs attached to a span that provide descriptive metadata about the operation it represents. They are the primary mechanism for enriching traces with contextual, diagnostic, and business data.

01

Semantic Conventions

Semantic Conventions are standardized, pre-defined attribute keys and values established by the OpenTelemetry project to ensure consistency across instrumentation. They define common attributes for well-known operations, such as:

  • http.method: The HTTP request method (e.g., GET, POST).
  • db.system: The database management system (e.g., postgresql, redis).
  • rpc.service: The name of the RPC service being called. Using these conventions ensures traces from different libraries and services can be aggregated and queried uniformly, which is critical for automated analysis and dashboarding.
02

Attribute Value Types

Span attributes support a constrained set of primitive value types to ensure efficient serialization, storage, and querying. The allowed types are:

  • String: For textual data (e.g., user.id="abc123").
  • Integer: For whole numbers (e.g., http.status_code=404).
  • Double: For floating-point numbers (e.g., duration.ms=152.7).
  • Boolean: For true/false values (e.g., error=true).
  • Array of primitives: For lists of uniform values (e.g., http.request.header="["content-type", "authorization"]"). Complex objects must be flattened into key-value pairs or serialized as a string.
03

Cardinality and Cost

Attribute cardinality—the number of unique key-value combinations—directly impacts storage cost and query performance. High-cardinality attributes, like unique user IDs or request IDs, can cause exponential data growth. Best practices include:

  • Using low-cardinality attributes for grouping and filtering (e.g., service.name, deployment.environment).
  • Being judicious with high-cardinality data; consider logging it separately or using span events.
  • Implementing attribute limits in SDKs (e.g., OpenTelemetry's default limit of 128 attributes per span) to prevent accidental data explosions.
04

Enrichment Points

Attributes can be added at multiple stages in a trace's lifecycle, known as enrichment points:

  1. At Span Creation: Core attributes (e.g., http.method) are set by the auto-instrumentation or manual SDK call.
  2. During Processing: Attributes can be added by an OpenTelemetry Collector using processors. For example, the attributes processor can add cloud.region="us-east-1" to all spans.
  3. In the Backend: Tracing backends can enrich spans at ingest time using contextual data (e.g., mapping a service.name to a team owner from a CMDB). This layered approach separates operational instrumentation from business context.
05

Business and Domain Context

Beyond technical metadata, attributes are the primary vector for injecting business context into observability data. This transforms generic traces into actionable, domain-specific insights. Examples include:

  • shopping.cart.id: To trace the performance of cart-related operations.
  • payment.transaction.type: To segment traces by "refund" vs. "purchase".
  • workflow.execution.id: To correlate all spans related to a specific long-running business process. This enables SREs and business analysts to answer questions like "What is the 95th percentile latency for checkout requests from premium users?"
06

Queryability and Analysis

The ultimate value of attributes is realized through queryability. In tracing backends like Jaeger, Tempo, or commercial APMs, attributes become the primary filter dimensions. Effective attribute design enables:

  • Precise Filtering: http.status_code=500 AND deployment.environment="prod"
  • Aggregation and Grouping: Group trace latency by service.version to validate a new release.
  • Statistical Analysis: Calculate error rates for specific customer.tier. Poorly named or inconsistent attributes render traces unsearchable, negating their diagnostic value.
STANDARDIZED METADATA

Common Span Attribute Examples by Category

A reference of typical key-value pairs attached to spans, categorized by their primary use case in observability and debugging.

Attribute CategoryExample KeyExample ValueSemantic Convention Source

HTTP Request

http.method

"GET"

OpenTelemetry

HTTP Request

http.url

OpenTelemetry

HTTP Request

http.status_code

200

OpenTelemetry

Database Operation

db.system

"postgresql"

OpenTelemetry

Database Operation

db.statement

"SELECT * FROM users WHERE id = ?"

OpenTelemetry

Database Operation

db.operation

"find"

OpenTelemetry

Messaging System

messaging.system

"kafka"

OpenTelemetry

Messaging System

messaging.destination

"orders-topic"

OpenTelemetry

Messaging System

messaging.operation

"publish"

OpenTelemetry

Error & Status

error

OpenTelemetry

Error & Status

exception.type

"ValueError"

OpenTelemetry

Error & Status

exception.message

"Invalid user ID provided"

OpenTelemetry

Agentic Context

agent.workflow.id

"wf_order_fulfillment_abc123"

Custom

Agentic Context

agent.decision.step

3

Custom

Agentic Context

agent.tool.called

"sql_query_executor"

Custom

Business Context

user.id

"user_789"

Custom

Business Context

order.id

"order_456"

Custom

Business Context

business.tier

"premium"

Custom

Performance

process.runtime.memory.usage

1542887424

OpenTelemetry

Performance

thread.name

"main"

OpenTelemetry

DISTRIBUTED TRACE COLLECTION

How Span Attributes Work in Practice

Span attributes are the descriptive metadata that transform a raw timing measurement into a rich, queryable record of system behavior.

In practice, span attributes are key-value pairs attached to a span at instrumentation time. Common attributes include http.method, db.system, url.path, and custom business keys like user.id. These attributes are immutable after the span ends, ensuring a consistent historical record. They are the primary data used for filtering, aggregating, and diagnosing issues in trace analysis tools, making them the semantic core of a trace.

Attributes are typically set via the OpenTelemetry API using a span's set_attribute method. For efficiency, they should be added during the span's lifecycle, not after. Auto-instrumentation libraries automatically add standard attributes for common frameworks. In a trace pipeline, attributes can be further enriched or filtered by an OpenTelemetry Collector before being exported to a backend for storage and analysis, enabling centralized governance of telemetry semantics.

SPAN ATTRIBUTES

Frequently Asked Questions

Span attributes are the descriptive metadata that make distributed traces actionable. This FAQ addresses common questions about their purpose, structure, and best practices for SREs and DevOps engineers implementing observability.

Span attributes are key-value pairs of metadata attached to a span that describe the specific operation it represents. They provide the contextual details necessary to understand what happened during the execution of a service, such as the HTTP method (http.method=GET), database query string (db.statement="SELECT * FROM users"), URL endpoint (http.url="/api/v1/orders"), error codes, or custom business data like a user ID or transaction amount. Unlike the structural data of a trace (IDs, timing, parent-child relationships), attributes supply the semantic content, turning a generic timing diagram into a rich, queryable record of system behavior for debugging and analysis.

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.