# Interface DatastoreMetricsRecorder (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 interface DatastoreMetricsRecorder extends MetricsRecorder

Interface to record Datastore-specific and standard RPC metrics.

This interface extends [MetricsRecorder](https://docs.cloud.google.com/java/docs/reference/gax/latest/com.google.api.gax.tracing.MetricsRecorder.html) from the GAX library to provide a unified
recording contract that covers both generic RPC metrics (like latency and attempt counts) and
Datastore-specific operations (like transactions).

**Warning:** This is intended to be an internal API and is not intended for external use.
This is public solely for implementation purposes and does not promise any backwards
compatibility.

## Implements

[MetricsRecorder](https://docs.cloud.google.com/java/docs/reference/gax/latest/com.google.api.gax.tracing.MetricsRecorder.html)

## Static Fields

### logger

    public static final Logger logger

| **Field Value** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/util/logging/Logger.html` |   |

## Static Methods

### getInstance(DatastoreOptions options, OpenTelemetry builtInOtel)

    public static DatastoreMetricsRecorder getInstance(DatastoreOptions options, OpenTelemetry builtInOtel)

Returns a [DatastoreMetricsRecorder](https://docs.cloud.google.com/java/docs/reference/google-cloud-datastore/latest/com.google.cloud.datastore.telemetry.DatastoreMetricsRecorder) instance based on the provided [DatastoreOptions](https://docs.cloud.google.com/java/docs/reference/google-cloud-datastore/latest/com.google.cloud.datastore.DatastoreOptions).

This factory method creates a [CompositeDatastoreMetricsRecorder](https://docs.cloud.google.com/java/docs/reference/google-cloud-datastore/latest/com.google.cloud.datastore.telemetry.CompositeDatastoreMetricsRecorder) that delegates to
multiple backends:

- **Default provider** : Always exports metrics to Google Cloud Monitoring via a privately-constructed io.opentelemetry.sdk.OpenTelemetrySdk with a DatastoreCloudMonitoringExporter, unless explicitly disabled via [DatastoreOpenTelemetryOptions#isExportBuiltinMetricsToGoogleCloudMonitoring()](https://docs.cloud.google.com/java/docs/reference/google-cloud-datastore/latest/com.google.cloud.datastore.DatastoreOpenTelemetryOptions#com_google_cloud_datastore_DatastoreOpenTelemetryOptions_isExportBuiltinMetricsToGoogleCloudMonitoring__).
- **Custom provider** : If the user has enabled metrics and provided an OpenTelemetry instance (or GlobalOpenTelemetry is used as fallback), metrics are also recorded to that backend.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `options` | `https://docs.cloud.google.com/java/docs/reference/google-cloud-datastore/latest/com.google.cloud.datastore.DatastoreOptions` the [DatastoreOptions](https://docs.cloud.google.com/java/docs/reference/google-cloud-datastore/latest/com.google.cloud.datastore.DatastoreOptions) configuring the Datastore client |
| `builtInOtel` | `io.opentelemetry.api.OpenTelemetry` the OpenTelemetry built in Otel object |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-cloud-datastore/latest/com.google.cloud.datastore.telemetry.DatastoreMetricsRecorder` | a [DatastoreMetricsRecorder](https://docs.cloud.google.com/java/docs/reference/google-cloud-datastore/latest/com.google.cloud.datastore.telemetry.DatastoreMetricsRecorder) that fans out to all configured backends |

## Methods

### close()

    public default void close()

Releases any resources held by this recorder.

For built-in recorders that own a private io.opentelemetry.sdk.OpenTelemetrySdk
instance, this will flush and shut down the underlying io.opentelemetry.sdk.metrics.SdkMeterProvider. For recorders backed by a user-provided io.opentelemetry.api.OpenTelemetry instance, this is a no-op since the caller owns that
instance's lifecycle.

This method should be called from com.google.cloud.datastore.DatastoreImpl#close().

### recordTransactionAttemptCount(long count, Map\<String,String\> attributes)

    public abstract void recordTransactionAttemptCount(long count, Map<String,String> attributes)

Records the number of attempts a transaction took.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `count` | `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` |
| `attributes` | `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>` |

### recordTransactionLatency(double latencyMs, Map\<String,String\> attributes)

    public abstract void recordTransactionLatency(double latencyMs, Map<String,String> attributes)

Records the total latency of a transaction in milliseconds.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `latencyMs` | `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` |
| `attributes` | `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>` |