OpenTelemetryScope class
Base class for OpenTelemetry tracing scopes.
Subclasses: InvokeAgentScope, ExecuteToolScope, InferenceScope, OutputScope.
Methods
| dispose() | Legacy dispose method for compatibility. |
| get |
Gets the span context for this scope. |
| record |
Records multiple attribute key/value pairs. |
| record |
Records a cancellation event on the span. |
| record |
Records an error that occurred during the operation. |
| set |
Sets a custom end time for the scope.
When set, |
| with |
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>