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.
  • Constructor Details

    • AgentInvocation

      public AgentInvocation(InvocationContext ctx, BaseAgent agent, io.opentelemetry.context.Context parentContext)
      Constructs a new AgentInvocation telemetry scope.
      Parameters:
      ctx - The invocation context of the agent execution.
      agent - The agent being invoked.
      parentContext - The OpenTelemetry parent context.
  • Method Details

    • getCtx

      public InvocationContext getCtx()
      Retrieves the invocation context associated with this agent invocation.
      Returns:
      The InvocationContext.
    • addEvent

      public void addEvent(Event event)
      Adds an event to the list of events tracked during this agent invocation.
      Parameters:
      event - The Event to add.
    • recordMetrics

      protected void recordMetrics(Duration elapsed, @Nullable Throwable error)
      Records metrics for the agent invocation including duration, request size, response size, and workflow steps.
      Specified by:
      recordMetrics in class Instrumentation.ClosableTelemetryScope
      Parameters:
      elapsed - The total execution duration.
      error - The exception thrown during execution, if any.
    • handleMetricsError

      protected void handleMetricsError(RuntimeException e)
      Handles errors that occur while recording metrics for the agent invocation.
      Specified by:
      handleMetricsError in class Instrumentation.ClosableTelemetryScope
      Parameters:
      e - The runtime exception encountered during metrics recording.