Class OpenTelemetryMetricsRecorder (2.48.1)

public class OpenTelemetryMetricsRecorder 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).

Inheritance

java.lang.Object > OpenTelemetryMetricsRecorder

Implements

MetricsRecorder

Constructors

OpenTelemetryMetricsRecorder(OpenTelemetry openTelemetry, String serviceName)

public OpenTelemetryMetricsRecorder(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
Name Description
openTelemetry io.opentelemetry.api.OpenTelemetry

OpenTelemetry instance

serviceName String

Service Name

Methods

recordAttemptCount(long count, Map<String,String> attributes)

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)

Parameters
Name Description
count long

The number of attempts made

attributes Map<String,String>

Map of the attributes to store

recordAttemptLatency(double attemptLatency, Map<String,String> attributes)

public void recordAttemptLatency(double attemptLatency, Map<String,String> attributes)

Record the latency for an individual attempt. Data is stored in a Histogram.

Parameters
Name Description
attemptLatency double

Attempt Latency in ms

attributes Map<String,String>

Map of the attributes to store

recordOperationCount(long count, Map<String,String> attributes)

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.

Parameters
Name Description
count long

The number of operations made

attributes Map<String,String>

Map of the attributes to store

recordOperationLatency(double operationLatency, Map<String,String> attributes)

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

Parameters
Name Description
operationLatency double

Operation Latency in ms

attributes Map<String,String>

Map of the attributes to store