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(undefined | null | Iterable<[string, AttributeValue]> | Record<string, AttributeValue>)

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.

Method Details

dispose()

Legacy dispose method for compatibility.

function dispose()

getSpanContext()

Gets the span context for this scope.

function getSpanContext(): SpanContext

Returns

SpanContext

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

Records multiple attribute key/value pairs.

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

Parameters

attributes

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

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>