ExecuteToolScope class
提供 OpenTelemetry 追蹤範圍,用於 AI 工具執行操作。
- Extends
方法
| record |
記錄回應資訊以進行遙測追蹤。 |
| start(Request, Tool |
建立並啟動一個新的工具執行追蹤範圍。 |
繼承的方法
| dispose() | 相容性遺留處理方法 |
| get |
了解這個範圍的跨度上下文。 這可以用來建立一個 ParentSpanRef,用於跨非同步邊界的明確父子連結。 |
| record |
記錄多個屬性鍵值對以進行遙測追蹤。 |
| record |
記錄橋樑上的取消事件。 將 span 狀態設為 ERROR,並以取消理由標示錯誤類型為「TaskCanceledException」。 |
| record |
記錄操作過程中發生的錯誤 |
| set |
為望遠鏡設定自訂結束時間。
設定後, 處置 會將此值傳遞給 , |
| with |
使此區間在非同步回調執行期間保持活躍 |
方法詳細資料
recordResponse(string | Record<string, unknown>)
記錄回應資訊以進行遙測追蹤。
function recordResponse(response: string | Record<string, unknown>)
參數
- response
-
string | Record<string, unknown>
工具執行反應。 物件會自動序列化成 JSON。
start(Request, ToolCallDetails, AgentDetails, UserDetails, SpanDetails)
建立並啟動一個新的工具執行追蹤範圍。
static function start(request: Request, details: ToolCallDetails, agentDetails: AgentDetails, userDetails?: UserDetails, spanDetails?: SpanDetails): ExecuteToolScope
參數
- request
- Request
請求有效載荷(channel、conversationId、內容、sessionId)。
- details
- ToolCallDetails
工具呼叫細節(名稱、類型、args、呼叫碼等)。
- agentDetails
- AgentDetails
執行工具的代理人。 租戶識別碼源自 agentDetails.tenantId。
- userDetails
- UserDetails
可選的人類來電者身份。
- spanDetails
- SpanDetails
可選的span設定(parentContext、startTime、endTime、spanLinks、spanKind)。 預設為 SpanKind.INTERNAL。
傳回
一個新的 ExecuteToolScope 實例。
繼承的方法的詳細資料
dispose()
getSpanContext()
了解這個範圍的跨度上下文。 這可以用來建立一個 ParentSpanRef,用於跨非同步邊界的明確父子連結。
function getSpanContext(): SpanContext
傳回
SpanContext
包含 traceId 與 spanId的 SpanContext
recordAttributes(undefined | null | Iterable<[string, AttributeValue]> | Record<string, AttributeValue>)
記錄多個屬性鍵值對以進行遙測追蹤。
function recordAttributes(attributes: undefined | null | Iterable<[string, AttributeValue]> | Record<string, AttributeValue>)
參數
- attributes
-
undefined | null | Iterable<[string, AttributeValue]> | Record<string, AttributeValue>
屬性鍵值對的集合(陣列或[鍵、值]或物件映射的迭代)。
recordCancellation(string)
記錄橋樑上的取消事件。 將 span 狀態設為 ERROR,並以取消理由標示錯誤類型為「TaskCanceledException」。
function recordCancellation(reason?: string)
參數
- reason
-
string
可選的取消原因。 預設為「任務已取消」。
recordError(Error)
記錄操作過程中發生的錯誤
function recordError(error: Error)
參數
- error
-
Error
發生的錯誤
setEndTime(TimeInput)
為望遠鏡設定自訂結束時間。
設定後, 處置 會將此值傳遞給 , span.end() 而非使用當前的壁鐘時間。
當操作的實際結束時間在示波器被處理前已知時,這非常有用。
function setEndTime(endTime: TimeInput)
參數
- endTime
-
TimeInput
結束時間以毫秒表示,從紀元、日期或 HrTime 元組開始。
withActiveSpanAsync<T>(() => Promise<T>)
使此區間在非同步回調執行期間保持活躍
function withActiveSpanAsync<T>(callback: () => Promise<T>): Promise<T>
參數
- callback
-
() => Promise<T>
傳回
Promise<T>