全部產品
Search
文件中心

Application Real-Time Monitoring Service:LLM Trace欄位定義說明

更新時間:Oct 17, 2025

LLM Trace欄位是阿里雲參考OpenTelemetry標準以及大語言模型應用領域概念制定的,通過對Attributes、Resource、Event擴充用於描述LLM應用調用鏈資料的語義,能夠反映LLM的輸入輸出請求、令牌消耗等關鍵操作。它們為Completion、Chat、RAG、Agent、Tool等情境提供了豐富的、語境相關的語義資料,以便於資料跟蹤和上報。此語義欄位將隨著社區的發展而不斷更新和最佳化。

Span一級欄位定義參考OpenTelemetry開源標準,阿里雲Managed Service for OpenTelemetry底層儲存的Trace一級欄位詳細說明,請參見調用鏈分析參數說明

說明

LLM相關的SpanKind是一個Attribute,不同於OpenTelemetry中Trace定義的Span kind

公用部分

Attributes

AttributeKey

描述

類型

樣本值

需求等級

gen_ai.session.id

會話ID

String

ddde34343-f93a-4477-33333-sdfsdaf

有條件時必須

gen_ai.user.id

應用的C端使用者標識

String

u-lK8JddD

有條件時必須

gen_ai.span.kind

操作類型

String

參考LLM Span Kind

必須

gen_ai.framework

使用的架構類型

String

langchain;llama_index

有條件時必須

Resources

ResourceKey

描述

類型

樣本值

需求等級

service.name

應用程式名稱

String

test-easy-rag

必須

Chain

Chain是一種將LLM和其他多個元件連線在一起的工具,以實現複雜的任務,可能包含Retrieval、Embedding、LLM調用、還可以嵌套Chain等。

Attributes

AttributeKey

描述

類型

樣本值

需求等級

gen_ai.span.kind

操作類型,大模型spanKind專用枚舉,Chain中取值必須為 CHAIN

String

CHAIN

必須

gen_ai.operation.name

操作二級類型

String

WORKFLOWTASK

有條件時必須

input.value

輸入內容

String

Who Are You!

推薦

output.value

返回內容

String

I am ChatBot

推薦

gen_ai.user.time_to_first_token

首包延遲,一次提問的整體響應首包耗時,從服務端擷取的使用者請求到首包返回的時間,單位納秒。

Integer

1000000

推薦

Retriever

Retriever一般表示訪問向量儲存或者資料庫擷取資料,一般用於補充上下文內容,以提升LLM的響應準確性以及效率。

Attributes

AttributeKey

描述

類型

樣本值

需求等級

gen_ai.span.kind

操作類型,大模型spanKind專用枚舉,Retriever中取值必須為 RETRIEVER

String

RETRIEVER

必須

retrieval.query

檢索內容短句

String

what is the topic in xxx?

推薦

retrieval.document

召回的文檔列表

JSON數組

[{"document":{"content":"This is a sample document content.","metadata":{"source":"https://aliyun.com/xxx/wiki","title":"How LLM Works"},"score":0.7680862242896571,"id":"7af0e529-2531-42d9-bf3a-d5074a73c184"}}]

必須

Reranker

Reranker針對輸入的多個文檔,結合提問內容判斷相關性進行排序處理,可能返回TopK的文檔作為LLM。

Attributes

AttributeKey

描述

類型

樣本值

需求等級

gen_ai.span.kind

操作類型,大模型spanKind專用枚舉,Reranker中取值必須為 RERANKER

String

RERANKER

必須

reranker.query

Reranker請求的入參

String

How to format timestamp?

可選

reranker.model_name

Reranker所用的模型名

String

cross-encoder/ms-marco-MiniLM-L-12-v2

可選

reranker.top_k

Reranker後的排名

Integer

3

可選

reranker.input_document

輸出文檔相關的中繼資料。重排序輸入文檔、JSON數組結構、metadata為文檔的基本資料,包含路徑,檔案名稱以及來源等。

String

-

必須

reranker.output_document

輸出文檔相關的中繼資料。重排序輸出文檔、JSON數組結構、metadata為文檔的基本資料,包含路徑,檔案名稱以及來源等。

String

-

必須

LLM

LLM標識對大模型的調用,例如基於SDK或OpenAPI請求不同的大模型進行推理或者文本產生等情境。

Attributes

AttributeKey

描述

類型

樣本值

需求等級

gen_ai.span.kind

操作類型,大模型spanKind專用枚舉,LLM中取值必須為 LLM

String

LLM

必須

gen_ai.operation.name

操作二級類型

String

chatcompletion

可選

gen_ai.prompt_template.template

提示詞模板

String

Weather forecast for {city} on {date}

可選

gen_ai.prompt_template.variables

提示詞模板的具體值

String

{ context: "<context from retrieval>", subject: "math" }

可選

gen_ai.prompt_template.version

提示模板的版本號碼

String

1.0

可選

gen_ai.system

大模型的供應商

String

openai

必須

gen_ai.request.parameters

LLM調用的入參

String

{"temperature": 0.7}

可選

gen_ai.model_name

模型名稱

String

gpt-4

可選

gen_ai.conversation.id

會話的唯一ID,當埋點可以比較方便地擷取會話的ID時應該採集。

String

conv_5j66UpCpwteGg4YSxUnt7lPY

有條件時必須

gen_ai.output.type

LLM請求中指定的輸出類型,當可以擷取並且請求指定了類型(如指定了output format)時應該採集。

String

text;json;image;audio

有條件時必須

gen_ai.request.choice.count

LLM請求中希望獲得的候選產生數量

Int

3

有條件且不為1時必須

gen_ai.request.model

LLM請求中指定的模型名

String

gpt-4

必須

gen_ai.request.seed

LLM請求中指定的seed

String

gpt-4

有條件時必須

gen_ai.request.frequency_penalty

LLM請求中設定的頻率懲罰

Float

0.1

推薦

gen_ai.request.max_tokens

LLM請求中指定的最大token數

Integer

100

推薦

gen_ai.request.presence_penalty

LLM請求中設定的存在性懲罰

Float

0.1

推薦

gen_ai.request.temperature

LLM請求中指定的溫度

Float

0.1

推薦

gen_ai.request.top_p

LLM請求中指定的topP

Float

1.0

推薦

gen_ai.request.top_k

LLM請求中指定的topK

Float

1.0

推薦

gen_ai.request.is_stream

是否為流式響應,如果不存在,則代表取值為false。

Boolean

false

推薦

gen_ai.request.stop_sequences

LLM的終止序列

String[]

["stop"]

推薦

gen_ai.request.tool_calls

Tools調用的內容(後續廢棄,替換為gen_ai.tool.definitions

String

[{"tool_call.function.name": "get_current_weather"}]

推薦

gen_ai.response.id

LLM產生的唯一ID

String

gpt-4-0613

推薦

gen_ai.response.model

LLM產生所使用的模型名

String

gpt-4-0613

推薦

gen_ai.response.finish_reason

LLM終止產生的原因

String[]

["stop"]

推薦

gen_ai.response.time_to_first_token

流式響應情境下的大模型自身的首包響應耗時。代表一次提問的整體響應首包耗時,從服務端擷取的使用者請求到首包返回的時間,單位納秒。

Integer

1000000

推薦

gen_ai.response.reasoning_time

推理模型的推理時間,代表響應reasoning過程的持續時間長度,單位毫秒。

Integer

1248

推薦

gen_ai.usage.input_tokens

輸入使用的token數

Integer

100

推薦

gen_ai.usage.output_tokens

輸出使用的token數

Integer

200

推薦

gen_ai.usage.total_tokens

使用的總token數

Integer

300

推薦

gen_ai.input.messages_ref

模型輸入內容連結

String

s3://acme.prod.support_bot.chats.2025/conv_1234/run_42.json

推薦

gen_ai.output.messages_ref

模型輸出內容連結

String

s3://acme.prod.support_bot.chats.2025/conv_1234/run_42.json

推薦

gen_ai.system.instructions_ref

system提示詞的內容連結。用於單獨記錄system提示詞(/system指令)內容的外部連結。如果system提示詞(/system指令)內容可以單獨擷取,則應該用該欄位記錄;如果system提示詞(/system指令)內容是模型調用的一部分,應該記錄在gen_ai.input.messages_ref屬性對應的連結中。

String

s3://acme.prod.support_bot.chats.2025/conv_1234/invocation_42.json

如果能擷取時推薦

gen_ai.input.messages

模型輸入內容,訊息必須按照發送給模型或智能體的順序提供。

預設情況下,不應採集該資訊,除非使用者主動開啟開關。

String

[{"role": "user", "parts": [{"type": "text", "content": "Weather in Paris?"}]}, {"role": "assistant", "parts": [{"type": "tool_call", "id": "call_VSPygqKTWdrhaFErNvMV18Yl", "name":"get_weather", "arguments":{"location":"Paris"}}]}, {"role": "tool", "parts": [{"type": "tool_call_response", "id":" call_VSPygqKTWdrhaFErNvMV18Yl", "result":"rainy, 57°F"}]}]

可選

gen_ai.output.messages

模型輸出內容,訊息必須按照發送給模型或智能體的順序提供。

預設情況下,不應採集該資訊,除非使用者主動開啟開關。

String

[{"role":"assistant","parts":[{"type":"text","content":"The weather in Paris is currently rainy with a temperature of 57°F."}],"finish_reason":"stop"}]

可選

gen_ai.system.instructions

system提示詞的內容。用於單獨記錄system提示詞(/system指令)內容,格式為一個JSON字串。如果system提示詞(/system指令)內容可以單獨擷取,則應該用該欄位記錄;如果system提示詞(/system指令)內容是模型調用的一部分,應該記錄在gen_ai.input.messages屬性中。

預設情況下,不應採集該資訊,除非使用者主動開啟開關。

String

{"role": "system", "message": {"type": "text", "content": "You are a helpful assistant"}}

可選

gen_ai.response.reasoning_content

推理模型的推理內容。代表響應reasoning過程的內容,預設長度限制為1024字元,超出的部分應截斷。

String

Okay, let's tackle this question about xxx.

可選

gen_ai.tool.definitions

工具定義

String

[{"type":"function","name":"get_current_weather","description": "Get the current weather in a given location","parameters":{"type":"object","properties":{"location":{"type":"string","description":"The city and state, e.g. San Francisco, CA"},"unit": {"type":"string","enum":["celsius","fahrenheit"]}},"required":["location","unit"]}}]

推薦

Embedding

Embedding標識一次嵌入處理,例如針對文本嵌入大模型的操作,後續可以根據相似性查詢最佳化問題。

Attributes

AttributeKey

描述

類型

樣本值

需求等級

gen_ai.span.kind

操作類型,大模型spanKind專用枚舉,Embedding中取值必須為 EMBEDDING

String

EMBEDDING

必須

gen_ai.usage.input_tokens

輸入文本的token消耗

Integer

10

可選

gen_ai.usage.total_tokens

Embedding的token總消耗

Integer

10

可選

embedding.model_name

Embedding的模型名稱(後續廢棄,替換為gen_ai.request.model

String

text-embedding-v1

可選

embedding.embedding_output

嵌入結果(後續廢棄)

String

-

可選

gen_ai.operation.name

操作二級類型

String

embeddings

有條件時必須

gen_ai.encoding.formats

編碼格式

String

["base64"]

推薦

gen_ai.embeddings.dimension.count

嵌入維度數

Integer

100

推薦

gen_ai.request.model

Embedding 請求中指定的模型名

String

text-embedding-v1

有條件時必須

Tool

Tool標識對外部工具的調用,例如可能調用計算機或者請求天氣API擷取最新的天氣情況。

Attributes

AttributeKey

描述

類型

樣本值

需求等級

gen_ai.span.kind

操作類型,大模型spanKind專用枚舉,Tool中取值必須為 TOOL

String

TOOL

必須

tool.name

工具名稱(後續廢棄,替換為gen_ai.tool.name

String

WeatherAPI

必須

tool.description

工具描述(後續廢棄,替換為gen_ai.tool.description

String

An API to get weather data.

必須

tool.parameters

工具入參(後續廢棄,替換為gen_ai.tool.call.arguments

String

{'a': 'int' }

必須

gen_ai.operation.name

操作二級類型

String

execute_tool

有條件時必須

gen_ai.tool.call.id

工具 id

String

call_mszuSIzqtI65i1wAUOE8w5H4

推薦

gen_ai.tool.description

工具描述

String

Multiply two numbers

推薦

gen_ai.tool.name

工具名稱

String

get_weather

推薦

gen_ai.tool.type

工具類型

String

function;extension;datastore

推薦

gen_ai.tool.call.arguments

工具調用入參

String

{"location": "San Francisco?","date": "2025-10-01"}

可選

gen_ai.tool.call.result

工具調用傳回值

String

{"temperature_range": {"high": 75,"low": 60},"conditions": "sunny"}

可選

Agent

Agent表示智能體情境,一種更複雜的Chain,需要基於大模型的推理結果決策執行下一步,例如可能涉及到LLM以及Tool的多次調用,一步步決策得出最終答案。

Attributes

AttributeKey

描述

類型

樣本值

需求等級

gen_ai.span.kind

操作類型,大模型spanKind專用枚舉,Agent中取值必須為 AGENT

String

AGENT

必須

input.value

輸入參數,記錄原始輸入。

String

請幫我規劃xxxx

必須

input.mime_type

輸入MimeType

String

text/plainapplication/json

可選

output.value

返回結果,返回最終輸出。

String

規劃結束,請查看結果xxx

必須

output.mime_type

輸出MimeType

String

text/plainapplication/json

可選

gen_ai.response.time_to_first_token

Agent的首包響應耗時。代表一次提問的整體響應首包耗時,從服務端擷取的使用者請求到首包返回的時間,單位納秒。

Integer

1000000

推薦

Task

Task標識一次內部自訂方法,例如可能調用本地的某個Function等應用自訂的邏輯。

Attributes

AttributeKey

描述

類型

樣本值

需求等級

gen_ai.span.kind

操作類型,大模型spanKind專用枚舉,Task中取值必須為 TASK

String

TASK

必須

input.value

輸入參數

String

自訂JSON格式

可選

input.mime_type

輸入MimeType

String

text/plainapplication/json

可選

output.mime_type

輸出MimeType

String

text/plainapplication/json

可選