Class Metrics

java.lang.Object
com.google.adk.telemetry.Metrics

public final class Metrics extends Object
Utility class for recording OpenTelemetry metrics within the ADK.
  • Method Details

    • setMeterForTesting

      public static void setMeterForTesting(io.opentelemetry.api.metrics.Meter meter)
      Sets the OpenTelemetry Meter to be used for metrics. This is for testing purposes only.
    • recordAgentInvocationDuration

      public static void recordAgentInvocationDuration(String agentName, Duration duration, @Nullable Throwable error)
      Records the duration of the agent invocation.
    • recordAgentRequestSize

      public static void recordAgentRequestSize(String agentName, @Nullable com.google.genai.types.Content userContent)
      Records the size of the agent request.
    • recordAgentResponseSize

      public static void recordAgentResponseSize(String agentName, @Nullable List<Event> events)
      Records the size of the agent response by extracting content from events.
    • recordAgentWorkflowSteps

      public static void recordAgentWorkflowSteps(String agentName, List<Event> events)
      Records the number of steps in the agent workflow by counting the number of events.
    • recordToolExecutionDuration

      public static void recordToolExecutionDuration(String toolName, String agentName, Duration duration, @Nullable Throwable error)
      Records the duration of the tool execution.
    • recordToolRequestSize

      public static void recordToolRequestSize(String toolName, String agentName, Map<String,Object> functionArgs)
      Records the size of the tool request.
    • recordToolResponseSize

      public static void recordToolResponseSize(String toolName, String agentName, @Nullable Event responseEvent)
      Records the size of the tool response.