Required Attributes
All LLM spans MUST include:openinference.span.kind: Set to"LLM"llm.system: The AI system/product (e.g., “openai”, “anthropic”)
Common Attributes
LLM spans typically include:| Attribute | Description |
|---|---|
llm.model_name | The specific model used (e.g., “gpt-4-0613”) |
llm.invocation_parameters | JSON string of parameters sent to the model |
input.value | The raw input as a JSON string |
input.mime_type | Usually “application/json” |
output.value | The raw output as a JSON string |
output.mime_type | Usually “application/json” |
llm.input_messages | Flattened list of input messages |
llm.output_messages | Flattened list of output messages |
llm.token_count.* | Token usage metrics |
Context Attributes
All LLM spans automatically inherit context attributes when they are set via the instrumentation context API. These attributes are propagated to every span in the trace without needing to be explicitly set on each span:| Attribute | Description |
|---|---|
session.id | Unique identifier for the session |
user.id | Unique identifier for the user |
metadata | JSON string of key-value metadata associated with the trace |
tag.tags | List of string tags for categorizing the span |
llm.prompt_template.template | The prompt template used to generate the LLM input |
llm.prompt_template.variables | JSON of key-value pairs applied to the prompt template |
llm.prompt_template.version | Version identifier for the prompt template |
See Configuration for details on how to set these context attributes.
Attribute Flattening
While the examples below show attributes in a nested JSON format for readability, in actual OpenTelemetry spans, these attributes are flattened using indexed dot notation:
llm.input_messages.0.message.roleinstead ofllm.input_messages[0].message.rolellm.output_messages.0.message.tool_calls.0.tool_call.function.namefor nested tool callsllm.tools.0.tool.json_schemafor tool definitions
Tool Role Messages
When a message withmessage.role set to "tool" represents the result of a function call, the message.name attribute MAY be set to identify which function produced the result. This complements message.tool_call_id, which links the result back to the original tool call request. For example:
See Tool Calling for the complete tool calling flow.