# Class TelemetryUtils (3.1.0)

3.1.0 (latest) 2.40.0 2.37.0 2.36.0 2.34.0 2.33.3 2.32.3 2.31.4 2.30.0 2.29.1 2.28.2 2.27.1 2.26.4 2.25.2 2.24.3 2.23.0 2.22.0 2.21.3 2.20.2 2.19.2 2.18.5 2.17.6

    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](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html) \> TelemetryUtils

## Inherited Members

[Object.clone()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#clone--) [Object.equals(Object)](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#equals-java.lang.Object-) [Object.finalize()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#finalize--) [Object.getClass()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#getClass--) [Object.hashCode()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#hashCode--) [Object.notify()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#notify--) [Object.notifyAll()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#notifyAll--) [Object.toString()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#toString--) [Object.wait()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#wait--) [Object.wait(long)](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#wait-long-) [Object.wait(long,int)](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#wait-long-int-)

## 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` | `https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/Callable.html<T>` The original callable to execute. |
| `metricsRecorder` | `https://docs.cloud.google.com/java/docs/reference/google-cloud-datastore/latest/com.google.cloud.datastore.telemetry.DatastoreMetricsRecorder` The metrics recorder. |
| `methodName` | `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` The name of the API method. |
| `databaseId` | `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/Callable.html<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` | `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` The name of the API method. |
| `status` | `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` The status of the operation or attempt. |
| `databaseId` | `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/util/Map.html<https://docs.oracle.com/javase/8/docs/api/java/lang/String.html,https://docs.oracle.com/javase/8/docs/api/java/lang/String.html>` | 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` | `https://docs.cloud.google.com/java/docs/reference/google-cloud-datastore/latest/com.google.cloud.datastore.telemetry.DatastoreMetricsRecorder` The metrics recorder. |
| `operationStopwatch` | `com.google.common.base.Stopwatch` The stopwatch tracking the duration of the entire operation. |
| `methodName` | `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` The name of the API method. |
| `status` | `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` The final status of the operation after all retries. |
| `databaseId` | `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` |