Class Instrumentation.ToolExecution
java.lang.Object
com.google.adk.telemetry.Instrumentation.ClosableTelemetryScope
com.google.adk.telemetry.Instrumentation.ToolExecution
- All Implemented Interfaces:
AutoCloseable
- Enclosing class:
Instrumentation
public static final class Instrumentation.ToolExecution
extends Instrumentation.ClosableTelemetryScope
AutoCloseable telemetry tracking scope for tool executions.
-
Field Summary
Fields inherited from class Instrumentation.ClosableTelemetryScope
caughtError, closed, scope, span, startTimeNanos, telemetryContextModifier 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. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidTraces the tool execution attributes on the span before it ends.protected voidHandles errors that occur while recording metrics for the tool execution.protected voidrecordMetrics(Duration elapsed, @Nullable Throwable error) Records metrics for the tool execution including duration, request size, and response size.Methods inherited from class Instrumentation.ClosableTelemetryScope
close, context, setError
-
Constructor Details
-
ToolExecution
public ToolExecution(BaseTool tool, BaseAgent agent, Map<String, Object> functionArgs, io.opentelemetry.context.Context parentContext) Constructs a newToolExecutiontelemetry scope.- Parameters:
tool- The tool being executed.agent- The agent invoking the tool.functionArgs- The arguments passed to the tool.parentContext- The OpenTelemetry parent context.
-
-
Method Details
-
beforeSpanEnd
protected void beforeSpanEnd()Traces the tool execution attributes on the span before it ends.- Overrides:
beforeSpanEndin classInstrumentation.ClosableTelemetryScope
-
recordMetrics
Records metrics for the tool execution including duration, request size, and response size.- Specified by:
recordMetricsin classInstrumentation.ClosableTelemetryScope- Parameters:
elapsed- The total execution duration.error- The exception thrown during execution, if any.
-
handleMetricsError
Handles errors that occur while recording metrics for the tool execution.- Specified by:
handleMetricsErrorin classInstrumentation.ClosableTelemetryScope- Parameters:
e- The runtime exception encountered during metrics recording.
-