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 Details

    • startTimeNanos

      protected final long startTimeNanos
      The start time of the scope in nanoseconds.
    • span

      protected final io.opentelemetry.api.trace.Span span
      The OpenTelemetry span associated with this scope.
    • scope

      protected final io.opentelemetry.context.Scope scope
      The OpenTelemetry scope associated with this span.
    • telemetryContext

      protected final Instrumentation.TelemetryContext telemetryContext
      The telemetry context for this scope.
    • caughtError

      protected @Nullable Throwable caughtError
      The error caught during execution, if any.
    • closed

      protected final AtomicBoolean closed
      Whether this scope has been closed.
  • Method Details

    • context

      Retrieves the telemetry context associated with this scope.
      Returns:
      The Instrumentation.TelemetryContext.
    • setError

      public void setError(Throwable caughtError)
      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:
      close in interface AutoCloseable
    • beforeSpanEnd

      protected void beforeSpanEnd()
      Hook for subclasses to run code before span ends.
    • recordMetrics

      protected abstract void recordMetrics(Duration elapsed, @Nullable Throwable error)
      Hook for subclasses to record metrics.
    • handleMetricsError

      protected abstract void handleMetricsError(RuntimeException e)
      Hook for subclasses to handle metrics recording errors.