Class Instrumentation.AgentInvocation
java.lang.Object
com.google.adk.telemetry.Instrumentation.ClosableTelemetryScope
com.google.adk.telemetry.Instrumentation.AgentInvocation
- All Implemented Interfaces:
AutoCloseable
- Enclosing class:
Instrumentation
public static final class Instrumentation.AgentInvocation
extends Instrumentation.ClosableTelemetryScope
AutoCloseable telemetry tracking scope for agent invocations.
-
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
ConstructorsConstructorDescriptionAgentInvocation(InvocationContext ctx, BaseAgent agent, io.opentelemetry.context.Context parentContext) Constructs a newAgentInvocationtelemetry scope. -
Method Summary
Modifier and TypeMethodDescriptionvoidAdds an event to the list of events tracked during this agent invocation.getCtx()Retrieves the invocation context associated with this agent invocation.protected voidHandles errors that occur while recording metrics for the agent invocation.protected voidrecordMetrics(Duration elapsed, @Nullable Throwable error) Records metrics for the agent invocation including duration, request size, response size, and workflow steps.Methods inherited from class Instrumentation.ClosableTelemetryScope
beforeSpanEnd, close, context, setErrorModifier 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.voidRecords an error on the span and sets its status to error.
-
Constructor Details
-
AgentInvocation
public AgentInvocation(InvocationContext ctx, BaseAgent agent, io.opentelemetry.context.Context parentContext) Constructs a newAgentInvocationtelemetry scope.- Parameters:
ctx- The invocation context of the agent execution.agent- The agent being invoked.parentContext- The OpenTelemetry parent context.
-
-
Method Details
-
getCtx
Retrieves the invocation context associated with this agent invocation.- Returns:
- The
InvocationContext.
-
addEvent
-
recordMetrics
Records metrics for the agent invocation including duration, request size, response size, and workflow steps.- 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 agent invocation.- Specified by:
handleMetricsErrorin classInstrumentation.ClosableTelemetryScope- Parameters:
e- The runtime exception encountered during metrics recording.
-