What Are Attributes?
Attributes contain metadata that you can use to annotate a span to carry information about the operation it is tracking. For example, if a span invokes an LLM, you can capture:- The model name
- The invocation parameters (temperature, max_tokens)
- The token count
- The input messages
- The output messages
Attribute Rules
Attributes have the following requirements: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 (
trueorfalse) - Floating point value (e.g.,
0.95,2.5) - Integer (e.g.,
42,250) - Array of any of the above types
Semantic Conventions
Semantic Attributes are standardized naming conventions for metadata that is typically present in common operations. It’s helpful to use semantic attribute naming wherever possible so that common kinds of metadata are standardized across systems.Always use semantic attribute names when available. This ensures consistency across different AI frameworks and observability platforms.
Attribute Naming Conventions
Attribute names use dot-separated namespaces to organize related attributes:Common Namespaces
| Namespace | Purpose | Example |
|---|---|---|
openinference.* | Core OpenInference attributes | openinference.span.kind |
llm.* | Language model operations | llm.model_name, llm.token_count.prompt |
embedding.* | Embedding generation | embedding.model_name, embedding.embeddings |
tool.* | Tool/function calls | tool.name, tool.description |
retrieval.* | Retrieval operations | retrieval.documents |
reranker.* | Reranking operations | reranker.model_name, reranker.top_k |
message.* | Chat messages | message.role, message.content |
document.* | Retrieved documents | document.id, document.content |
input.* | Operation inputs | input.value, input.mime_type |
output.* | Operation outputs | output.value, output.mime_type |
session.* | Session tracking | session.id |
user.* | User identification | user.id |
Flattened Lists (Indexed Attributes)
When dealing with lists of structured data, OpenInference uses indexed prefixes to create flattened attribute names. This is necessary because OpenTelemetry attributes must be flat key-value pairs.Pattern
<prefix>is the base attribute name (e.g.,llm.input_messages)<index>is a zero-based integer index<suffix>is the nested attribute path
Example: Input Messages
Logical structure (for illustration):All list-based attributes use zero-based indexing in their flattened form.
Common Flattened Attribute Patterns
LLM Input/Output Messages
Tool Calls in Output Messages
Retrieved Documents
Embeddings
Available Tools
Multimodal Content
For messages containing multiple content items (text, images, audio):Nested Flattening Rules
If objects are further nested, flattening continues until values are simple types:boolstrbytesintfloat- Simple lists:
List[bool],List[str],List[bytes],List[int],List[float]
Implementation Examples
Python
JavaScript/TypeScript
Go
Hierarchical Attributes
Some attributes use hierarchical dot notation for related metrics:Token Counts
Cost Tracking
Context Attributes
Context attributes are automatically propagated to all spans in a trace:| Attribute | Type | Description |
|---|---|---|
session.id | String | Unique session identifier |
user.id | String | Unique user identifier |
metadata | JSON String | Key-value metadata |
tag.tags | List of strings | Categorization tags |
Reserved Attributes
The following attributes are reserved and MUST be supported by all OpenInference implementations:openinference.span.kind(REQUIRED)input.valueinput.mime_typeoutput.valueoutput.mime_typellm.systemllm.model_namellm.input_messagesllm.output_messagesllm.token_count.*embedding.model_nameembedding.embeddingstool.nameretrieval.documentsreranker.*
Best Practices
Use semantic conventions
Use semantic conventions
Always use standardized attribute names from the OpenInference specification. This ensures consistency and interoperability.
Be consistent with types
Be consistent with types
Ensure attribute values match their expected types. For example,
llm.token_count.prompt should always be an integer, not a string.Flatten complex structures
Flatten complex structures
When dealing with nested data, flatten it using indexed dot notation. Do not attempt to store nested objects directly.
Include MIME types
Include MIME types
Always include
input.mime_type and output.mime_type when setting input.value and output.value. This helps consumers parse the data correctly.Use descriptive names for custom attributes
Use descriptive names for custom attributes
If you need custom attributes beyond the semantic conventions, use clear, descriptive names with appropriate namespaces.
Next Steps
Semantic Conventions
Complete reference of all standardized attributes
Span Kinds
Learn which attributes are used for each span kind
LLM Spans
Detailed LLM-specific attributes
Embedding Spans
Embedding-specific attributes