Class Instrumentation.ClosableTelemetryScope
java.lang.Object
com.google.adk.telemetry.Instrumentation.ClosableTelemetryScope
- All Implemented Interfaces:
AutoCloseable
- Direct Known Subclasses:
Instrumentation.AgentInvocation, Instrumentation.ToolExecution
- Enclosing class:
Instrumentation
public abstract static class Instrumentation.ClosableTelemetryScope
extends Object
implements AutoCloseable
Base class for AutoCloseable telemetry tracking scopes.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected @Nullable ThrowableThe error caught during execution, if any.protected final AtomicBooleanWhether this scope has been closed.protected final io.opentelemetry.context.ScopeThe OpenTelemetry scope associated with this span.protected final io.opentelemetry.api.trace.SpanThe OpenTelemetry span associated with this scope.protected final longThe start time of the scope in nanoseconds.protected final Instrumentation.TelemetryContextThe telemetry context for this scope. -
Method Summary
Modifier and TypeMethodDescriptionprotected voidHook for subclasses to run code before span ends.final voidclose()Closes the scope and ends the underlying span, recording any applicable metrics.context()Retrieves the telemetry context associated with this scope.protected abstract voidHook for subclasses to handle metrics recording errors.protected abstract voidrecordMetrics(Duration elapsed, @Nullable Throwable error) Hook for subclasses to record metrics.voidRecords an error on the span and sets its status to error.
-
Field Details
-
startTimeNanos
protected final long startTimeNanosThe start time of the scope in nanoseconds. -
span
protected final io.opentelemetry.api.trace.Span spanThe OpenTelemetry span associated with this scope. -
scope
protected final io.opentelemetry.context.Scope scopeThe OpenTelemetry scope associated with this span. -
telemetryContext
The telemetry context for this scope. -
caughtError
The error caught during execution, if any. -
closed
Whether this scope has been closed.
-
-
Method Details
-
context
Retrieves the telemetry context associated with this scope.- Returns:
- The
Instrumentation.TelemetryContext.
-
setError
Records an error on the span and sets its status to error.- Parameters:
caughtError- The throwable caught during execution.
-
close
public final void close()Closes the scope and ends the underlying span, recording any applicable metrics.- Specified by:
closein interfaceAutoCloseable
-
beforeSpanEnd
protected void beforeSpanEnd()Hook for subclasses to run code before span ends. -
recordMetrics
-
handleMetricsError
Hook for subclasses to handle metrics recording errors.
-