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 | 描述 | 類型 | 樣本值 | 需求等級 |
| 會話ID | String |
| 有條件時必須 |
| 應用的C端使用者標識 | String |
| 有條件時必須 |
| 操作類型 | String | 參考LLM Span Kind | 必須 |
| 使用的架構類型 | String |
| 有條件時必須 |
Resources
ResourceKey | 描述 | 類型 | 樣本值 | 需求等級 |
| 應用程式名稱 | String |
| 必須 |
Chain
Chain是一種將LLM和其他多個元件連線在一起的工具,以實現複雜的任務,可能包含Retrieval、Embedding、LLM調用、還可以嵌套Chain等。
Attributes
AttributeKey | 描述 | 類型 | 樣本值 | 需求等級 |
| 操作類型,大模型spanKind專用枚舉,Chain中取值必須為 | String |
| 必須 |
| 操作二級類型 | String |
| 有條件時必須 |
| 輸入內容 | String |
| 推薦 |
| 返回內容 | String |
| 推薦 |
| 首包延遲,一次提問的整體響應首包耗時,從服務端擷取的使用者請求到首包返回的時間,單位納秒。 | Integer | 1000000 | 推薦 |
Retriever
Retriever一般表示訪問向量儲存或者資料庫擷取資料,一般用於補充上下文內容,以提升LLM的響應準確性以及效率。
Attributes
AttributeKey | 描述 | 類型 | 樣本值 | 需求等級 |
| 操作類型,大模型spanKind專用枚舉,Retriever中取值必須為 | String |
| 必須 |
| 檢索內容短句 | String |
| 推薦 |
| 召回的文檔列表 | JSON數組 |
| 必須 |
Reranker
Reranker針對輸入的多個文檔,結合提問內容判斷相關性進行排序處理,可能返回TopK的文檔作為LLM。
Attributes
AttributeKey | 描述 | 類型 | 樣本值 | 需求等級 |
| 操作類型,大模型spanKind專用枚舉,Reranker中取值必須為 | String |
| 必須 |
| Reranker請求的入參 | String |
| 可選 |
| Reranker所用的模型名 | String |
| 可選 |
| Reranker後的排名 | Integer |
| 可選 |
| 輸出文檔相關的中繼資料。重排序輸入文檔、JSON數組結構、metadata為文檔的基本資料,包含路徑,檔案名稱以及來源等。 | String | - | 必須 |
| 輸出文檔相關的中繼資料。重排序輸出文檔、JSON數組結構、metadata為文檔的基本資料,包含路徑,檔案名稱以及來源等。 | String | - | 必須 |
LLM
LLM標識對大模型的調用,例如基於SDK或OpenAPI請求不同的大模型進行推理或者文本產生等情境。
Attributes
AttributeKey | 描述 | 類型 | 樣本值 | 需求等級 |
| 操作類型,大模型spanKind專用枚舉,LLM中取值必須為 | String |
| 必須 |
| 操作二級類型 | String |
| 可選 |
| 提示詞模板 | String |
| 可選 |
| 提示詞模板的具體值 | String |
| 可選 |
| 提示模板的版本號碼 | String |
| 可選 |
| 大模型的供應商 | String |
| 必須 |
| LLM調用的入參 | String |
| 可選 |
| 模型名稱 | String |
| 可選 |
| 會話的唯一ID,當埋點可以比較方便地擷取會話的ID時應該採集。 | String |
| 有條件時必須 |
| LLM請求中指定的輸出類型,當可以擷取並且請求指定了類型(如指定了output format)時應該採集。 | String |
| 有條件時必須 |
| LLM請求中希望獲得的候選產生數量 | Int |
| 有條件且不為1時必須 |
| LLM請求中指定的模型名 | String |
| 必須 |
| LLM請求中指定的seed | String |
| 有條件時必須 |
| LLM請求中設定的頻率懲罰 | Float |
| 推薦 |
| LLM請求中指定的最大token數 | Integer |
| 推薦 |
| LLM請求中設定的存在性懲罰 | Float |
| 推薦 |
| LLM請求中指定的溫度 | Float |
| 推薦 |
| LLM請求中指定的topP | Float |
| 推薦 |
| LLM請求中指定的topK | Float |
| 推薦 |
| 是否為流式響應,如果不存在,則代表取值為false。 | Boolean |
| 推薦 |
| LLM的終止序列 | String[] |
| 推薦 |
| Tools調用的內容(後續廢棄,替換為 | String |
| 推薦 |
| LLM產生的唯一ID | String |
| 推薦 |
| LLM產生所使用的模型名 | String |
| 推薦 |
| LLM終止產生的原因 | String[] |
| 推薦 |
| 流式響應情境下的大模型自身的首包響應耗時。代表一次提問的整體響應首包耗時,從服務端擷取的使用者請求到首包返回的時間,單位納秒。 | Integer |
| 推薦 |
| 推理模型的推理時間,代表響應reasoning過程的持續時間長度,單位毫秒。 | Integer |
| 推薦 |
| 輸入使用的token數 | Integer |
| 推薦 |
| 輸出使用的token數 | Integer |
| 推薦 |
| 使用的總token數 | Integer |
| 推薦 |
| 模型輸入內容連結 | String |
| 推薦 |
| 模型輸出內容連結 | String |
| 推薦 |
| system提示詞的內容連結。用於單獨記錄system提示詞(/system指令)內容的外部連結。如果system提示詞(/system指令)內容可以單獨擷取,則應該用該欄位記錄;如果system提示詞(/system指令)內容是模型調用的一部分,應該記錄在 | String |
| 如果能擷取時推薦 |
| 模型輸入內容,訊息必須按照發送給模型或智能體的順序提供。 預設情況下,不應採集該資訊,除非使用者主動開啟開關。 | String |
| 可選 |
| 模型輸出內容,訊息必須按照發送給模型或智能體的順序提供。 預設情況下,不應採集該資訊,除非使用者主動開啟開關。 | String |
| 可選 |
| system提示詞的內容。用於單獨記錄system提示詞(/system指令)內容,格式為一個JSON字串。如果system提示詞(/system指令)內容可以單獨擷取,則應該用該欄位記錄;如果system提示詞(/system指令)內容是模型調用的一部分,應該記錄在 預設情況下,不應採集該資訊,除非使用者主動開啟開關。 | String |
| 可選 |
| 推理模型的推理內容。代表響應reasoning過程的內容,預設長度限制為1024字元,超出的部分應截斷。 | String |
| 可選 |
| 工具定義 | String |
| 推薦 |
Embedding
Embedding標識一次嵌入處理,例如針對文本嵌入大模型的操作,後續可以根據相似性查詢最佳化問題。
Attributes
AttributeKey | 描述 | 類型 | 樣本值 | 需求等級 |
| 操作類型,大模型spanKind專用枚舉,Embedding中取值必須為 | String |
| 必須 |
| 輸入文本的token消耗 | Integer |
| 可選 |
| Embedding的token總消耗 | Integer |
| 可選 |
| Embedding的模型名稱(後續廢棄,替換為 | String |
| 可選 |
| 嵌入結果(後續廢棄) | String | - | 可選 |
| 操作二級類型 | String |
| 有條件時必須 |
| 編碼格式 | String | ["base64"] | 推薦 |
| 嵌入維度數 | Integer | 100 | 推薦 |
| Embedding 請求中指定的模型名 | String |
| 有條件時必須 |
Tool
Tool標識對外部工具的調用,例如可能調用計算機或者請求天氣API擷取最新的天氣情況。
Attributes
AttributeKey | 描述 | 類型 | 樣本值 | 需求等級 |
| 操作類型,大模型spanKind專用枚舉,Tool中取值必須為 | String |
| 必須 |
| 工具名稱(後續廢棄,替換為 | String |
| 必須 |
| 工具描述(後續廢棄,替換為 | String |
| 必須 |
| 工具入參(後續廢棄,替換為 | String |
| 必須 |
| 操作二級類型 | String |
| 有條件時必須 |
| 工具 id | String |
| 推薦 |
| 工具描述 | String |
| 推薦 |
| 工具名稱 | String |
| 推薦 |
| 工具類型 | String |
| 推薦 |
| 工具調用入參 | String |
| 可選 |
| 工具調用傳回值 | String |
| 可選 |
Agent
Agent表示智能體情境,一種更複雜的Chain,需要基於大模型的推理結果決策執行下一步,例如可能涉及到LLM以及Tool的多次調用,一步步決策得出最終答案。
Attributes
AttributeKey | 描述 | 類型 | 樣本值 | 需求等級 |
| 操作類型,大模型spanKind專用枚舉,Agent中取值必須為 | String |
| 必須 |
| 輸入參數,記錄原始輸入。 | String |
| 必須 |
| 輸入MimeType | String |
| 可選 |
| 返回結果,返回最終輸出。 | String |
| 必須 |
| 輸出MimeType | String |
| 可選 |
| Agent的首包響應耗時。代表一次提問的整體響應首包耗時,從服務端擷取的使用者請求到首包返回的時間,單位納秒。 | Integer |
| 推薦 |
Task
Task標識一次內部自訂方法,例如可能調用本地的某個Function等應用自訂的邏輯。
Attributes
AttributeKey | 描述 | 類型 | 樣本值 | 需求等級 |
| 操作類型,大模型spanKind專用枚舉,Task中取值必須為 | String |
| 必須 |
| 輸入參數 | String | 自訂JSON格式 | 可選 |
| 輸入MimeType | String |
| 可選 |
| 輸出MimeType | String |
| 可選 |