Class OpenTelemetryMetricsRecorder (2.47.0)

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
NameDescription
openTelemetryio.opentelemetry.api.OpenTelemetry

OpenTelemetry instance

serviceNameString

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
NameDescription
countlong

The number of attempts made

attributesMap<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
NameDescription
attemptLatencydouble

Attempt Latency in ms

attributesMap<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
NameDescription
countlong

The number of operations made

attributesMap<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
NameDescription
operationLatencydouble

Operation Latency in ms

attributesMap<String,String>

Map of the attributes to store