OpenTelemetryScope class

Base class for OpenTelemetry tracing scopes.

Subclasses: InvokeAgentScope, ExecuteToolScope, InferenceScope, OutputScope.

Methods

dispose()

Legacy dispose method for compatibility.

getSpanContext()

Gets the span context for this scope.

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

Records multiple attribute key/value pairs.

recordCancellation(string)

Records a cancellation event on the span.

recordError(Error)

Records an error that occurred during the operation.

setEndTime(TimeInput)

Sets a custom end time for the scope. When set, dispose() will pass this value to span.end() instead of using wall-clock time.

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

Makes this span active for the duration of the async callback execution.

[dispose]()

Disposes the scope and finalizes telemetry data collection.

Method Details

dispose()

Legacy dispose method for compatibility.

function dispose()

getSpanContext()

Gets the span context for this scope.

function getSpanContext(): SpanContext

Returns

SpanContext

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

Records multiple attribute key/value pairs.

function recordAttributes(attributes: Iterable<[string, AttributeValue], any, any> | Record<string, AttributeValue> | null | undefined)

Parameters

attributes

Iterable<[string, AttributeValue], any, any> | Record<string, AttributeValue> | null | undefined

recordCancellation(string)

Records a cancellation event on the span.

function recordCancellation(reason?: string)

Parameters

reason

string

recordError(Error)

Records an error that occurred during the operation.

function recordError(error: Error)

Parameters

error

Error

setEndTime(TimeInput)

Sets a custom end time for the scope. When set, dispose() will pass this value to span.end() instead of using wall-clock time.

function setEndTime(endTime: TimeInput)

Parameters

endTime

TimeInput

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

Makes this span active for the duration of the async callback execution.

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

Parameters

callback

() => Promise<T>

Returns

Promise<T>

[dispose]()

Disposes the scope and finalizes telemetry data collection.

function [dispose]()