OutputScope class

提供 OpenTelemetry 跟踪范围,以便通过父范围链接输出消息跟踪。

扩展

方法

recordOutputMessages(ResponseMessagesParam)

记录遥测跟踪的输出消息。 覆盖跨度上任何以前记录的输出消息。 接受单个字符串、字符串数组(自动包装为 一个输出消息)、一个版本控制 OutputMessages 包装器或原始听写(被视为每个 ANTS 规范的工具调用结果,直接序列化)。

start(Request, OutputResponse, AgentDetails, UserDetails, SpanDetails)

创建并启动输出消息跟踪的新范围。

继承的方法

dispose()

用于兼容性的旧释放方法

getSpanContext()

获取此范围的范围上下文。 这可用于为跨异步边界的显式父子链接创建 ParentSpanRef。

recordAttributes(undefined | null | Iterable<[string, AttributeValue]> | Record<string, AttributeValue>)

记录多个用于遥测跟踪的属性键/值对。

recordCancellation(string)

记录跨度上的取消事件。 使用取消原因将范围状态设置为 ERROR,并将错误类型标记为“TaskCanceledException”。

recordError(Error)

记录作期间发生的错误

setEndTime(TimeInput)

设置范围的自定义结束时间。 设置后, 释放 会将此值 span.end() 传递给而不是使用当前的时钟时间。 当在释放作用域之前已知操作的实际结束时间时,这非常有用。

withActiveSpanAsync<T>(() => Promise<T>)

使此范围在异步回调执行期间处于活动状态

方法详细信息

recordOutputMessages(ResponseMessagesParam)

记录遥测跟踪的输出消息。 覆盖跨度上任何以前记录的输出消息。 接受单个字符串、字符串数组(自动包装为 一个输出消息)、一个版本控制 OutputMessages 包装器或原始听写(被视为每个 ANTS 规范的工具调用结果,直接序列化)。

function recordOutputMessages(messages: ResponseMessagesParam)

参数

messages
ResponseMessagesParam

字符串、字符串数组、OutputMessages 包装器或听写。

start(Request, OutputResponse, AgentDetails, UserDetails, SpanDetails)

创建并启动输出消息跟踪的新范围。

static function start(request: Request, response: OutputResponse, agentDetails: AgentDetails, userDetails?: UserDetails, spanDetails?: SpanDetails): OutputScope

参数

request
Request

请求有效负载(通道、conversationId、内容、sessionId)。

response
OutputResponse

包含初始输出消息的响应。

agentDetails
AgentDetails

生成输出的代理。 租户 ID 派生自 agentDetails.tenantId.

userDetails
UserDetails

可选的人工调用方标识详细信息。

spanDetails
SpanDetails

可选范围配置(parentContext、startTime、endTime、spanLinks)。

返回

新的 OutputScope 实例。

继承的方法详细信息

dispose()

用于兼容性的旧释放方法

function dispose()

继承自OpenTelemetryScope.dispose

getSpanContext()

获取此范围的范围上下文。 这可用于为跨异步边界的显式父子链接创建 ParentSpanRef。

function getSpanContext(): SpanContext

返回

SpanContext

包含 traceId 和 spanId 的 SpanContext

继承自OpenTelemetryScope.getSpanContext

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>

属性键/值对的集合(数组或可迭代 [键,值] 或对象映射)。

继承自OpenTelemetryScope.recordAttributes

recordCancellation(string)

记录跨度上的取消事件。 使用取消原因将范围状态设置为 ERROR,并将错误类型标记为“TaskCanceledException”。

function recordCancellation(reason?: string)

参数

reason

string

可选的取消原因。 默认为“任务已取消”。

继承自OpenTelemetryScope.recordCancellation

recordError(Error)

记录作期间发生的错误

function recordError(error: Error)

参数

error

Error

发生的错误

继承自OpenTelemetryScope.recordError

setEndTime(TimeInput)

设置范围的自定义结束时间。 设置后, 释放 会将此值 span.end() 传递给而不是使用当前的时钟时间。 当在释放作用域之前已知操作的实际结束时间时,这非常有用。

function setEndTime(endTime: TimeInput)

参数

endTime

TimeInput

自纪元、日期或 HrTime 元组以来的结束时间(以毫秒为单位)。

继承自OpenTelemetryScope.setEndTime

withActiveSpanAsync<T>(() => Promise<T>)

使此范围在异步回调执行期间处于活动状态

function withActiveSpanAsync<T>(callback: () => Promise<T>): Promise<T>

参数

callback

() => Promise<T>

返回

Promise<T>

继承自OpenTelemetryScope.withActiveSpanAsync