OpenTelemetryScope class
Base class for OpenTelemetry tracing scopes
Methods
| dispose() | Legacy dispose method for compatibility |
| get |
Gets the span context for this scope. This can be used to create a ParentSpanRef for explicit parent-child linking across async boundaries. |
| record |
Records multiple attribute key/value pairs for telemetry tracking. |
| record |
Records a cancellation event on the span. Sets the span status to ERROR with the cancellation reason and marks the error type as 'TaskCanceledException'. |
| record |
Records an error that occurred during the operation |
| set |
Sets a custom end time for the scope.
When set, dispose will pass this value to |
| 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. This can be used to create a ParentSpanRef for explicit parent-child linking across async boundaries.
function getSpanContext(): SpanContext
Returns
SpanContext
The SpanContext containing traceId and spanId
recordAttributes(undefined | null | Iterable<[string, AttributeValue]> | Record<string, AttributeValue>)
Records multiple attribute key/value pairs for telemetry tracking.
function recordAttributes(attributes: undefined | null | Iterable<[string, AttributeValue]> | Record<string, AttributeValue>)
Parameters
- attributes
-
undefined | null | Iterable<[string, AttributeValue]> | Record<string, AttributeValue>
Collection of attribute key/value pairs (array or iterable of [key, value] or object map).
recordCancellation(string)
Records a cancellation event on the span. Sets the span status to ERROR with the cancellation reason and marks the error type as 'TaskCanceledException'.
function recordCancellation(reason?: string)
Parameters
- reason
-
string
Optional cancellation reason. Defaults to 'Task was cancelled'.
recordError(Error)
Records an error that occurred during the operation
function recordError(error: Error)
Parameters
- error
-
Error
The error that occurred
setEndTime(TimeInput)
Sets a custom end time for the scope.
When set, dispose will pass this value to span.end() instead of using the current wall-clock time.
This is useful when the actual end time of the operation is known before the scope is disposed.
function setEndTime(endTime: TimeInput)
Parameters
- endTime
-
TimeInput
The end time as milliseconds since epoch, a Date, or an HrTime tuple.
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>