Span Anatomy
Every OpenInference span includes the following information:| Field | Description | Required |
|---|---|---|
| Name | Human-readable operation name | Yes |
| Parent span ID | Reference to parent span (empty for root spans) | No |
| Start timestamp | When the operation began | Yes |
| End timestamp | When the operation completed | Yes |
| Span context | Contains trace ID and span ID | Yes |
| Attributes | Key-value pairs with operation metadata | Yes |
| Span events | Structured log messages during the span | No |
| Span status | OK, ERROR, or UNSET | Yes |
| Span kind | OpenTelemetry span kind (usually INTERNAL) | Yes |
Example Span
Here’s a complete span representing an LLM call:Timestamps
Spans record precise timing information with nanosecond precision:Timestamps are recorded in ISO 8601 format with timezone information.
Span Context
Span context is an immutable object that uniquely identifies a span within a trace:| Field | Description |
|---|---|
trace_id | Unique identifier for the entire trace |
span_id | Unique identifier for this specific span |
Span context is used for context propagation—ensuring child spans are connected to their parents.
Attributes
Attributes are key-value pairs that contain metadata about the operation:Attribute Rules
Key requirements
Key requirements
- Keys MUST be non-null string values
- Keys SHOULD follow dot-separated namespace conventions
- Keys MUST be unique within a span
Value types
Value types
Values MUST be one of:
- Non-null string
- Boolean
- Floating point value
- Integer
- Array of any of the above types
Semantic conventions
Semantic conventions
OpenInference defines semantic attributes—standardized naming conventions for common metadata. Always use semantic attribute names when available.
Attribute conventions
Learn about semantic conventions and naming patterns
Span Events
A span event is a structured log message (or annotation) on a span, typically used to denote a meaningful, singular point in time during the span’s duration.When to Use Span Events
Consider two scenarios with an LLM:Use a Span
Tracking LLM execution timeA span is best because it’s an operation with a start and an end.
Use a Span Event
Denoting when first token is sentAn event is best because it represents a meaningful, singular point in time.
Event Structure
Span Status
A status is attached to every span to indicate whether the operation succeeded or failed:| Status | Description | When to Use |
|---|---|---|
UNSET | Default status | When no error occurred and no explicit success was set |
OK | Successful operation | When the operation completed successfully |
ERROR | Failed operation | When an exception or error occurred |
When an exception is handled, a span status SHOULD be set to ERROR and include a status message.
Example: Error Status
Nested Spans
Spans can be nested to represent sub-operations:parent_id field establishes the hierarchy. Child spans represent work done as part of the parent operation.
The presence of a parent span ID implies that child spans represent sub-operations. This allows spans to accurately capture the work done in an application.
OpenInference Span Kind
Theopeninference.span.kind attribute is REQUIRED for all OpenInference spans and identifies the type of operation:
LLM- Language model callCHAIN- Orchestration or sequenceAGENT- Autonomous agent reasoningTOOL- External function or API callRETRIEVER- Data retrieval operationRERANKER- Document rerankingEMBEDDING- Embedding generationGUARDRAIL- Content moderationEVALUATOR- Response evaluationPROMPT- Prompt template rendering
Span Kinds
Learn about all available span kinds
Important:
span_kind is an OpenTelemetry concept (usually set to SPAN_KIND_INTERNAL), while openinference.span.kind is an OpenInference-specific attribute that provides AI-aware classification.Common Span Patterns
Root Span
LLM Span
Tool Span
Next Steps
Span Kinds
Explore all OpenInference span kinds
Attributes
Learn attribute naming conventions
Traces
Understand how spans form traces