通过


OpenTelemetryScope class

OpenTelemetry 跟踪范围的基类

方法

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>)

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

方法详细信息

dispose()

用于兼容性的旧释放方法

function 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)

记录跨度上的取消事件。 使用取消原因将范围状态设置为 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>