Interface DatastoreMetricsRecorder (3.1.0)

public interface DatastoreMetricsRecorder extends MetricsRecorder

Interface to record Datastore-specific and standard RPC metrics.

This interface extends MetricsRecorder 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

Static Fields

logger

public static final Logger logger
Field Value
Type Description
Logger

Static Methods

getInstance(DatastoreOptions options, OpenTelemetry builtInOtel)

public static DatastoreMetricsRecorder getInstance(DatastoreOptions options, OpenTelemetry builtInOtel)

Returns a DatastoreMetricsRecorder instance based on the provided DatastoreOptions.

This factory method creates a 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().
  • 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 DatastoreOptions

the DatastoreOptions configuring the Datastore client

builtInOtel io.opentelemetry.api.OpenTelemetry

the OpenTelemetry built in Otel object

Returns
Type Description
DatastoreMetricsRecorder

a 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 long
attributes Map<String,String>

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 double
attributes Map<String,String>