1717package com .google .cloud .datastore .telemetry ;
1818
1919import com .google .api .core .InternalApi ;
20+ import com .google .api .gax .tracing .OpenTelemetryMetricsRecorder ;
2021import com .google .common .collect .ImmutableSet ;
2122import io .opentelemetry .api .common .AttributeKey ;
2223import java .util .Set ;
@@ -35,6 +36,23 @@ public class TelemetryConstants {
3536 // until this is implemented.
3637 public static final String METRIC_PREFIX = "custom.googleapis.com/internal/client" ;
3738 public static final String DATASTORE_METER_NAME = "java-datastore" ;
39+ public static final String GAX_METER_NAME = OpenTelemetryMetricsRecorder .GAX_METER_NAME ;
40+
41+ // Short names used to build GAX_METRICS and metric full-path constants below.
42+ public static final String METRIC_NAME_SHORT_OPERATION_LATENCY = "operation_latency" ;
43+ public static final String METRIC_NAME_SHORT_ATTEMPT_LATENCY = "attempt_latency" ;
44+ public static final String METRIC_NAME_SHORT_OPERATION_COUNT = "operation_count" ;
45+ public static final String METRIC_NAME_SHORT_ATTEMPT_COUNT = "attempt_count" ;
46+
47+ // Short metric names (without prefix) for the four metrics recorded by the GAX layer.
48+ // Used by DatastoreBuiltInMetricsView to register OTel views that capture and rename
49+ // GAX-emitted metrics for the built-in Cloud Monitoring export pipeline.
50+ public static final Set <String > GAX_METRICS =
51+ ImmutableSet .of (
52+ METRIC_NAME_SHORT_OPERATION_LATENCY ,
53+ METRIC_NAME_SHORT_ATTEMPT_LATENCY ,
54+ METRIC_NAME_SHORT_OPERATION_COUNT ,
55+ METRIC_NAME_SHORT_ATTEMPT_COUNT );
3856
3957 // Monitored resource type for Cloud Monitoring
4058 public static final String DATASTORE_RESOURCE_TYPE = "global" ;
@@ -78,6 +96,7 @@ public class TelemetryConstants {
7896
7997 // Metric attribute keys (used on metric data points)
8098 public static final AttributeKey <String > CLIENT_UID_KEY = AttributeKey .stringKey ("client_uid" );
99+ public static final AttributeKey <String > CLIENT_NAME_KEY = AttributeKey .stringKey ("client_name" );
81100 public static final AttributeKey <String > METHOD_KEY = AttributeKey .stringKey ("method" );
82101 public static final AttributeKey <String > STATUS_KEY = AttributeKey .stringKey ("status" );
83102 public static final AttributeKey <String > SERVICE_KEY = AttributeKey .stringKey ("service" );
@@ -98,6 +117,9 @@ public class TelemetryConstants {
98117 public static final Set <AttributeKey <?>> COMMON_ATTRIBUTES =
99118 ImmutableSet .of (CLIENT_UID_KEY , METHOD_KEY , STATUS_KEY , SERVICE_KEY );
100119
120+ // Environment variable to enable/disable built-in metrics
121+ public static final String ENABLE_METRICS_ENV_VAR = "DATASTORE_ENABLE_METRICS" ;
122+
101123 /** Metric name for the total latency of a transaction. */
102124 public static final String METRIC_NAME_TRANSACTION_LATENCY =
103125 METRIC_PREFIX + "/transaction_latencies" ;
0 commit comments