Trace fields for Large Language Model (LLM) applications are developed by Alibaba Cloud based on the OpenTelemetry standard and characteristics of LLM applications. These fields are used to describe trace data of LLM applications by expanding the attributes, resources, and events in OpenTelemetry. These fields can be used to describe key spans of LLM applications, including input, output, and token usage. Trace fields for LLM applications provide a variety of context-related semantic data for multiple scenarios such as completion, chat, retrieval-augmented generation (RAG), agent, and tool. This facilitates data tracking and reporting. These trace fields will be constantly updated and optimized as the Managed Service for OpenTelemetry community grows.
Span fields
For more information about the level-1 span fields and the underlying level-1 trace fields stored in Managed Service for OpenTelemetry, see Trace Explorer parameters.
Attributes
The fields described in this section are reserved fields used in LLM-related scenarios. If you use Managed Service for OpenTelemetry SDKs to report span data to servers, you must add relevant information as attributes in the form of key-value pairs to spans.
Common attributes
A common attribute can be passed through or added to multiple spans in a trace for an LLM-based conversational search regardless of the span kind.
Attribute | Type | Description | Required | Example |
| String | The session ID. | No |
|
| String | The user ID on the application client. | No |
|
| String | The span kind. For more information, see the Span kinds section of this topic. | Yes |
|
| String | The framework type. | No |
|
Span kinds
Multiple spans are often involved in actual LLM-based interaction scenarios. The following span kinds are defined by Managed Service for OpenTelemetry based on the LLM application paradigm and research and development (R&D) framework. You can expand these span kinds. The attributes vary based on the span kind.
CHAIN: connects LLM and other components to implement complex tasks. A CHAIN span may contain RETRIEVER, EMBEDDING, LLM, and other CHAIN spans.
EMBEDDING: performs embedding operations for LLM applications such as word embedding models to implement similarity-based queries and question optimization.
RETRIEVER: retrieves data from vector storage or databases to supplement the context. This allows LLMs to provide answers in a more accurate and efficient way.
RERANKER: sorts multiple input documents based on the relevance of the question. This span may return top K documents for LLMs.
LLM: invokes LLMs. For example, you can invoke different LLMs to perform model inference or text generation by using Managed Service for OpenTelemetry SDKs or API operations.
TOOL: uses external tools. For example, you can use a calculator or call a weather operation to obtain the latest weather conditions.
AGENT: a complex CHAIN span used in intelligence scenarios. An AGENT span represents the consecutive steps performed based on the inference results of LLMs. For example, multiple LLM spans and TOOL spans may be contained in an AGENT span in sequence to produce final answers.
TASK: specifies internal custom methods, such as calling a local function to apply custom logic.
The LLM-based span kinds defined by Managed Service for OpenTelemetry are different from the span kinds defined by OpenTelemetry.
CHAIN
Attribute | Type | Description | Required | Example |
| String | The span kind. | Yes |
|
| String | The level-2 span kind. | No |
|
| String | The input data. | Yes |
|
| String | The output data. | Yes |
|
EMBEDDING
Attribute | Type | Description | Required | Example |
| String | The span kind. | Yes |
|
| String | The name of the model for embedding. | No |
|
| Integer | The number of tokens used for embedding. | No | 10 |
| Integer | The total number of tokens used for embedding. | No | 10 |
| String | The text data that is converted into embeddings. | No |
|
| Array | The embedding vector that consists of floating-point numbers. | No |
|
| Integer | The vector length. | No |
|
RETRIEVER
Attribute | Type | Description | Required | Example |
| String | The span kind. | Yes |
|
| String | The unique ID of the document. | Yes |
|
| Float | The relevance score of the document. | Yes |
|
| String | The content of the retrieved document. | Yes |
|
| String | The metadata related to the document. | No | {"file_path": "/dev/EasyRAG/data/laws/laws.txt", "file_name": "/dev/EasyRAG/data/laws/laws.txt", "file_type": "text/plain", "file_size": 15618, "creation_date": "2024-03-20", "last_modified_date": "2024-03-20", "last_accessed_date": null} |
RERANKER
Attribute | Type | Description | Required | Example |
| String | The span kind. | Yes |
|
| String | The query of the reranker. | No |
|
| String | The name of the model that the reranker uses. | No |
|
| Integer | The number of results that the reranker returns. | No |
|
| String | The unique ID of the document. | Yes |
|
| Float | The relevance score of the document. | Yes |
|
| String | The content of the retrieved document. | Yes |
|
| String | The metadata related to the document. | No | {"file_path": "/dev/EasyRAG/data/laws/laws.txt", "file_name": "/dev/EasyRAG/data/laws/laws.txt", "file_type": "text/plain", "file_size": 15618, "creation_date": "2024-03-20", "last_modified_date": "2024-03-20","last_accessed_date": null} |
| String | The unique ID of the document. | Yes |
|
| Float | The relevance score of the document. | Yes |
|
| String | The content of the retrieved document. | Yes |
|
| String | The metadata related to the document. | No | {"file_path": "/dev/EasyRAG/data/laws/laws.txt", "file_name": "/dev/EasyRAG/data/laws/laws.txt", "file_type": "text/plain", "file_size": 15618, "creation_date": "2024-03-20", "last_modified_date": "2024-03-20","last_accessed_date": null} |
LLM
Attribute | Type | Description | Required | Example |
| String | The span kind. | Yes |
|
| String | The level-2 span kind. | No |
|
| String | The template that is used to generate prompts as Python f-strings. | No |
|
| String | The key-value pairs in the JSON format that apply to the specified prompt template. | No |
|
| String | The version number of the prompt template. | No |
|
| String | The LLM provider. | Yes |
|
| String | The parameters that are used to invoke the LLM or call the API operation. | Yes |
|
| String | The name of the LLM. | Yes |
|
| String | The name of the LLM to which the request is sent. | Yes |
|
| Integer | The maximum number of tokens that the LLM generates for a request. | No |
|
| Float | The temperature setting for the LLM request. | No |
|
| Float | The top-p sampling setting for the LLM request. | No |
|
| Boolean | Specifies whether the LLM generates a response as a stream. | No |
|
| Array | The string array that the LLM uses as the stop sequence. | No |
|
| Array | The list of tool calls, such as function invocations, generated by the LLM. | No |
|
| String | The name of the LLM that generates the response. | No |
|
| String | The reason why the model stops generating tokens. Each reason corresponds to a generation process. | No |
|
| String | The prompt content. | Yes |
|
| String | The role of the entity in the message, such as user or system. | Yes |
|
| String | The message content in a chat. | Yes |
|
| String | The parameters of the API request. Generally, the value is in the JSON format. | Yes |
|
| String | The full response returned by the LLM. | Yes |
|
| String | The role of the entity in the message during a chat, such as assistant. | Yes |
|
| String | The content of the message in a chat. | Yes |
|
| Array | The list of tool calls, such as function invocations, generated by the LLM in a chat. | No |
|
| String | The complete content returned for the API request. Generally, the value is in the JSON format. You can extract key fields, such as token_usage, from the returned content. | Yes |
|
| Integer | The number of tokens in the prompt. | Yes |
|
| Integer | The number of tokens in the completion. | Yes |
|
| Integer | The total number of tokens, including those in the prompt and completion. | Yes |
|
TOOL
Attribute | Type | Description | Required | Example |
| String | The span kind. | Yes |
|
| String | The tool name. | Yes |
|
| String | The tool description. | Yes |
|
| String | The tool parameters. | Yes |
|
AGENT
Attribute | Type | Description | Required | Example |
| String | The span kind. | Yes |
|
| String | The input data. | Yes |
|
| String | The Multipurpose Internet Mail Extensions (MIME) type of the input data. | No |
|
| String | The output data. | Yes |
|
| String | The MIME type of the output data. | No |
|
TASK
Attribute | Type | Description | Required | Example |
| String | The span kind. | Yes |
|
| String | The input data. | No |
|
| String | The MIME type of the input data. | No |
|
| String | The output data. | No |
|
| String | The MIME type of the output data. | No |
|