Class OpenTelemetryMetricsRecorder

java.lang.Object
com.google.api.gax.tracing.OpenTelemetryMetricsRecorder
All Implemented Interfaces:
MetricsRecorder

@BetaApi @InternalApi public class OpenTelemetryMetricsRecorder extends Object implements MetricsRecorder
OpenTelemetry implementation of recording metrics. This implementation collections the measurements related to the lifecyle of an RPC.

For the Otel implementation, an attempt is a single RPC invocation and an operation is the collection of all the attempts made before a response is returned (either as a success or an error). A single call (i.e. `EchoClient.echo()`) should have an operation_count of 1 and may have an attempt_count of 1+ (depending on the retry configurations).

  • Constructor Details

    • OpenTelemetryMetricsRecorder

      public OpenTelemetryMetricsRecorder(io.opentelemetry.api.OpenTelemetry openTelemetry, String serviceName)
      Creates the following instruments for the following metrics:
      • Attempt Latency: Histogram
      • Operation Latency: Histogram
      • Attempt Count: Counter
      • Operation Count: Counter
      Parameters:
      openTelemetry - OpenTelemetry instance
      serviceName - Service Name
  • Method Details

    • recordAttemptLatency

      public void recordAttemptLatency(double attemptLatency, Map<String,String> attributes)
      Record the latency for an individual attempt. Data is stored in a Histogram.
      Specified by:
      recordAttemptLatency in interface MetricsRecorder
      Parameters:
      attemptLatency - Attempt Latency in ms
      attributes - Map of the attributes to store
    • recordAttemptCount

      public void recordAttemptCount(long count, Map<String,String> attributes)
      Record an attempt made. The attempt count number is stored in a LongCounter.

      The count should be set as 1 every time this is invoked (each retry attempt)

      Specified by:
      recordAttemptCount in interface MetricsRecorder
      Parameters:
      count - The number of attempts made
      attributes - Map of the attributes to store
    • recordOperationLatency

      public void recordOperationLatency(double operationLatency, Map<String,String> attributes)
      Record the latency for the entire operation. This is the latency for the entire RPC, including all the retry attempts
      Specified by:
      recordOperationLatency in interface MetricsRecorder
      Parameters:
      operationLatency - Operation Latency in ms
      attributes - Map of the attributes to store
    • recordOperationCount

      public void recordOperationCount(long count, Map<String,String> attributes)
      Record an operation made. The operation count number is stored in a LongCounter.

      The operation count should always be 1 and this should be invoked once.

      Specified by:
      recordOperationCount in interface MetricsRecorder
      Parameters:
      count - The number of operations made
      attributes - Map of the attributes to store