Skip to main content
Standardizing span attributes across various models, frameworks, and vendors When sending traces, you might want to define custom attributes for each span. Semantic conventions are specific attribute keys or values that hold special significance. In Future AGI, certain attribute keys are highlighted more prominently, in addition to showing up in the attributes tab like other keys.

Types of Attributes

  • Span
  • Message
  • Document
  • Reranker
  • Embedding
  • Tool Call
For comprehensive guides to semantic conventions, refer to the following resources:
  • Python: See the Python examples above for implementation details
  • TypeScript: See the TypeScript examples above for implementation details

Attribute Overview

AttributeTypeExampleDescription
document.contentString"This is a sample document content."The content of a retrieved document
document.idString/Integer"1234" or 1Unique identifier for a document
document.metadataJSON String"{'author': 'John Doe', 'date': '2023-09-09'}"Metadata associated with a document
document.scoreFloat0.98Score representing the relevance of a document
embedding.embeddingsList of objects[{"embedding.vector": [...], "embedding.text": "hello"}]List of embedding objects including text and vector data
embedding.model_nameString"BERT-base"Name of the embedding model used
embedding.textString"hello world"The text represented in the embedding
embedding.vectorList of floats[0.123, 0.456, ...]The embedding vector consisting of a list of floats
exception.escapedBooleantrueIndicator if the exception has escaped the span’s scope
exception.messageString"Null value encountered"Detailed message describing the exception
exception.stacktraceString"at app.main(app.java:16)"The stack trace of the exception
exception.typeString"NullPointerException"The type of exception that was thrown
input.mime_typeString"text/plain" or "application/json"MIME type representing the format of input.value
input.valueString"{'query': 'What is the weather today?'}"The input value to an operation
llm.function_callJSON String"{function_name: 'add', args: [1, 2]}"Object recording details of a function call in models or APIs
llm.input_messagesList of objects[{"message.role": "user", "message.content": "hello"}]List of messages sent to the LLM in a chat API request
llm.invocation_parametersJSON string"{'model_name': 'gpt-3', 'temperature': 0.7}"Parameters used during the invocation of an LLM or API
llm.model_nameString"gpt-3.5-turbo"The name of the language model being utilized
llm.output_messagesList of objects[{"message.role": "user", "message.content": "hello"}]List of messages received from the LLM in a chat API request
llm.prompt_template.templateString"Weather forecast for {city} on {date}"Template used to generate prompts as Python f-strings
llm.prompt_template.variablesJSON String"{'context': '<context from retrieval>', 'subject': 'math'}"JSON of key value pairs applied to the prompt template
llm.prompt_template.versionString"v1.0"The version of the prompt template
llm.token_count.completionInteger15The number of tokens in the completion
llm.token_count.promptInteger5The number of tokens in the prompt
llm.token_count.totalInteger20Total number of tokens, including prompt and completion
message.contentString"What's the weather today?"The content of a message in a chat
message.function_call_arguments_jsonJSON String"{'x': 2}"The arguments to the function call in JSON
message.function_call_nameString"multiply" or "subtract"Function call function name
message.roleString"user" or "system"Role of the entity in a message (e.g., user, system)
message.tool_callsList of objects[{"tool_call.function.name": "get_current_weather"}]List of tool calls (e.g. function calls) generated by the LLM
metadataJSON String"{'author': 'John Doe', 'date': '2023-09-09'}"Metadata associated with a span
fi.span.kindString"CHAIN"The kind of span (e.g., CHAIN, LLM, RETRIEVER, RERANKER)
output.mime_typeString"text/plain" or "application/json"MIME type representing the format of output.value
output.valueString"Hello, World!"The output value of an operation
reranker.input_documentsList of objects[{"document.id": "1", "document.score": 0.9, "document.content": "..."}]List of documents as input to the reranker
reranker.model_nameString"cross-encoder/ms-marco-MiniLM-L-12-v2"Model name of the reranker
reranker.output_documentsList of objects[{"document.id": "1", "document.score": 0.9, "document.content": "..."}]List of documents outputted by the reranker
reranker.queryString"How to format timestamp?"Query parameter of the reranker
reranker.top_kInteger3Top K parameter of the reranker
retrieval.documentsList of objects[{"document.id": "1", "document.score": 0.9, "document.content": "..."}]List of retrieved documents
session.idString"26bcd3d2-cad2-443d-a23c-625e47f3324a"Unique identifier for a session
tag.tagsList of strings["shopping", "travel"]List of tags to give the span a category
tool.descriptionString"An API to get weather data."Description of the tool’s purpose and functionality
tool.nameString"WeatherAPI"The name of the tool being utilized
tool.parametersJSON string"{'a': 'int'}"The parameters definition for invoking the tool
tool_call.function.argumentsJSON string"{'city': 'London'}"The arguments for the function being invoked by a tool call
tool_call.function.nameString"get_current_weather"The name of the function being invoked by a tool call
user.idString"9328ae73-7141-4f45-a044-8e06192aa465"Unique identifier for a user

Using Semantic Conventions

Here are examples of how to implement semantic conventions in both Python and TypeScript:

Converting Messages to OpenTelemetry Span Attributes

To export a list of objects as OpenTelemetry span attributes, flatten the list until the attribute values are simple types, such as bool, str, bytes, int, float, or simple lists like List[bool], List[str], List[bytes], List[int], List[float].