Class TelemetryUtils (3.1.0)

public final class TelemetryUtils

Utility class for common telemetry operations in Datastore.

WARNING: This class is intended for internal use only.

Inheritance

java.lang.Object > TelemetryUtils

Static Methods

<T>attemptMetricsCallable(Callable<T> callable, DatastoreMetricsRecorder metricsRecorder, String methodName, String databaseId)

public static Callable<T> <T>attemptMetricsCallable(Callable<T> callable, DatastoreMetricsRecorder metricsRecorder, String methodName, String databaseId)

Wraps a callable with logic to record attempt-level metrics. Attempt metrics are recorded for each individual execution of the callable, regardless of whether it succeeds or fails.

Metrics are recorded for both transport types (gRPC and HTTP).

Parameters
Name Description
callable Callable<T>

The original callable to execute.

metricsRecorder DatastoreMetricsRecorder

The metrics recorder.

methodName String

The name of the API method.

databaseId String
Returns
Type Description
Callable<T>

A wrapped callable that includes attempt-level metrics recording.

buildMetricAttributes(String methodName, String status, String databaseId)

public static Map<String,String> buildMetricAttributes(String methodName, String status, String databaseId)

Method to build a map of attributes to be used across both operation and attempt level metrics.

Parameters
Name Description
methodName String

The name of the API method.

status String

The status of the operation or attempt.

databaseId String
Returns
Type Description
Map<String,String>

The map of attributes.

recordOperationMetrics(DatastoreMetricsRecorder metricsRecorder, Stopwatch operationStopwatch, String methodName, String status, String databaseId)

public static void recordOperationMetrics(DatastoreMetricsRecorder metricsRecorder, Stopwatch operationStopwatch, String methodName, String status, String databaseId)

Records operation-level metrics. This method should be called after the entire operation across all retry attempts has completed.

Metrics are recorded for both transport types (gRPC and HTTP).

Parameters
Name Description
metricsRecorder DatastoreMetricsRecorder

The metrics recorder.

operationStopwatch com.google.common.base.Stopwatch

The stopwatch tracking the duration of the entire operation.

methodName String

The name of the API method.

status String

The final status of the operation after all retries.

databaseId String