Skip to content

Commit ffd8277

Browse files
committed
chore: Add implementation for firestore resource
1 parent c237386 commit ffd8277

File tree

2 files changed

+33
-39
lines changed

2 files changed

+33
-39
lines changed

java-datastore/google-cloud-datastore/src/main/java/com/google/cloud/datastore/telemetry/OpenTelemetryMetricsRecorder.java

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,7 @@ class OpenTelemetryMetricsRecorder implements MetricsRecorder {
5050
* Creates a new recorder with a configurable metric prefix.
5151
*
5252
* @param openTelemetry the OpenTelemetry instance to record metrics to
53-
* @param metricPrefix the prefix for metric names (e.g. "custom.googleapis.com" or
54-
* "datastore.googleapis.com/internal/client")
53+
* @param metricPrefix the prefix for metric names (e.g. "custom.googleapis.com")
5554
*/
5655
OpenTelemetryMetricsRecorder(@Nonnull OpenTelemetry openTelemetry, String metricPrefix) {
5756
this.openTelemetry = openTelemetry;
@@ -60,41 +59,41 @@ class OpenTelemetryMetricsRecorder implements MetricsRecorder {
6059

6160
this.transactionLatency =
6261
meter
63-
.histogramBuilder(metricPrefix + "/client/transaction_latency")
62+
.histogramBuilder(TelemetryConstants.METRIC_NAME_TRANSACTION_LATENCY)
6463
.setDescription("Total latency of transaction operations")
6564
.setUnit("ms")
6665
.build();
6766

6867
this.transactionAttemptCount =
6968
meter
70-
.counterBuilder(metricPrefix + "/client/transaction_attempt_count")
69+
.counterBuilder(TelemetryConstants.METRIC_NAME_TRANSACTION_ATTEMPT_COUNT)
7170
.setDescription("Number of attempts to commit a transaction")
7271
.build();
7372

7473
this.attemptLatency =
7574
meter
76-
.histogramBuilder(metricPrefix + "/attempt_latency")
75+
.histogramBuilder(TelemetryConstants.METRIC_NAME_ATTEMPT_LATENCY)
7776
.setDescription("Latency of a single RPC attempt")
7877
.setUnit("ms")
7978
.build();
8079

8180
this.attemptCount =
8281
meter
83-
.counterBuilder(metricPrefix + "/attempt_count")
82+
.counterBuilder(TelemetryConstants.METRIC_NAME_ATTEMPT_COUNT)
8483
.setDescription("Number of RPC attempts")
8584
.setUnit("1")
8685
.build();
8786

8887
this.operationLatency =
8988
meter
90-
.histogramBuilder(metricPrefix + "/operation_latency")
89+
.histogramBuilder(TelemetryConstants.METRIC_NAME_OPERATION_LATENCY)
9190
.setDescription("Total latency of an operation including retries")
9291
.setUnit("ms")
9392
.build();
9493

9594
this.operationCount =
9695
meter
97-
.counterBuilder(metricPrefix + "/operation_count")
96+
.counterBuilder(TelemetryConstants.METRIC_NAME_OPERATION_COUNT)
9897
.setDescription("Number of operations")
9998
.setUnit("1")
10099
.build();

java-datastore/google-cloud-datastore/src/main/java/com/google/cloud/datastore/telemetry/TelemetryConstants.java

Lines changed: 26 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,11 @@ public class TelemetryConstants {
3636

3737
// TODO(lawrenceqiu): For now, use `custom.googleapis.com` until metrics can be written to
3838
// datastore domain
39-
public static final String SERVICE_NAME = "custom.googleapis.com";
39+
public static final String SERVICE_NAME = "firestore.googleapis.com";
4040
static final String METER_NAME = "com.google.cloud.datastore";
4141

4242
// Built-in metrics constants for Cloud Monitoring export
43-
public static final String METRIC_PREFIX = "datastore.googleapis.com/internal/client";
43+
public static final String METRIC_PREFIX = "firestore.googleapis.com/internal/client";
4444
public static final String GAX_METER_NAME = OpenTelemetryMetricsRecorder.GAX_METER_NAME;
4545
public static final String DATASTORE_METER_NAME = METRIC_PREFIX;
4646

@@ -52,8 +52,7 @@ public class TelemetryConstants {
5252
public static final String RESOURCE_LABEL_DATABASE_ID = "database_id";
5353
public static final String RESOURCE_LABEL_LOCATION = "location";
5454
public static final Set<String> DATASTORE_RESOURCE_LABELS =
55-
ImmutableSet.of(
56-
RESOURCE_LABEL_PROJECT_ID, RESOURCE_LABEL_DATABASE_ID, RESOURCE_LABEL_LOCATION);
55+
ImmutableSet.of(RESOURCE_LABEL_PROJECT_ID, RESOURCE_LABEL_DATABASE_ID, RESOURCE_LABEL_LOCATION);
5756

5857
// Resource attribute keys (used on OTel Resource)
5958
public static final AttributeKey<String> PROJECT_ID_KEY = AttributeKey.stringKey("project_id");
@@ -69,6 +68,9 @@ public class TelemetryConstants {
6968
public static final AttributeKey<String> LIBRARY_VERSION_KEY =
7069
AttributeKey.stringKey("library_version");
7170
public static final AttributeKey<String> TRANSPORT_KEY = AttributeKey.stringKey("transport");
71+
public static final AttributeKey<String> SERVICE_KEY = AttributeKey.stringKey("service");
72+
73+
public static final String SERVICE_VALUE = "datastore.googleapis.com";
7274

7375
// Set of all common metric attributes for view filtering
7476
public static final Set<AttributeKey> COMMON_ATTRIBUTES =
@@ -79,7 +81,8 @@ public class TelemetryConstants {
7981
STATUS_KEY,
8082
DATABASE_KEY,
8183
LIBRARY_VERSION_KEY,
82-
TRANSPORT_KEY);
84+
TRANSPORT_KEY,
85+
SERVICE_KEY);
8386

8487
// Metric names (short names, without prefix)
8588
public static final String METRIC_NAME_SHORT_OPERATION_LATENCY = "operation_latency";
@@ -133,35 +136,27 @@ public class TelemetryConstants {
133136

134137
/** Metric name for the total latency of a transaction. */
135138
public static final String METRIC_NAME_TRANSACTION_LATENCY =
136-
SERVICE_NAME + "/client/transaction_latency";
139+
SERVICE_NAME + "/internal/client/transaction_latency";
137140

138141
/** Metric name for the number of attempts a transaction took. */
139142
public static final String METRIC_NAME_TRANSACTION_ATTEMPT_COUNT =
140-
SERVICE_NAME + "/client/transaction_attempt_count";
141-
142-
/**
143-
* Metric name for the total latency of an operation (one full RPC call including retries). Note:
144-
* This does not have the /client prefix to match Gax's format.
145-
*/
146-
public static final String METRIC_NAME_OPERATION_LATENCY = SERVICE_NAME + "/operation_latency";
147-
148-
/**
149-
* Metric name for the latency of a single RPC attempt. Note: This does not have the /client
150-
* prefix to match Gax's format.
151-
*/
152-
public static final String METRIC_NAME_ATTEMPT_LATENCY = SERVICE_NAME + "/attempt_latency";
153-
154-
/**
155-
* Metric name for the count of operations. Note: This does not have the /client prefix to match
156-
* Gax's format.
157-
*/
158-
public static final String METRIC_NAME_OPERATION_COUNT = SERVICE_NAME + "/operation_count";
159-
160-
/**
161-
* Metric name for the count of RPC attempts. Note: This does not have the /client prefix to match
162-
* Gax's format.
163-
*/
164-
public static final String METRIC_NAME_ATTEMPT_COUNT = SERVICE_NAME + "/attempt_count";
143+
SERVICE_NAME + "/internal/client/transaction_attempt_count";
144+
145+
/** Metric name for the total latency of an operation (one full RPC call including retries). */
146+
public static final String METRIC_NAME_OPERATION_LATENCY =
147+
SERVICE_NAME + "/internal/client/operation_latency";
148+
149+
/** Metric name for the latency of a single RPC attempt. */
150+
public static final String METRIC_NAME_ATTEMPT_LATENCY =
151+
SERVICE_NAME + "/internal/client/attempt_latency";
152+
153+
/** Metric name for the count of operations. */
154+
public static final String METRIC_NAME_OPERATION_COUNT =
155+
SERVICE_NAME + "/internal/client/operation_count";
156+
157+
/** Metric name for the count of RPC attempts. */
158+
public static final String METRIC_NAME_ATTEMPT_COUNT =
159+
SERVICE_NAME + "/internal/client/attempt_count";
165160

166161
// This is intentionally different from the `SERVICE_NAME` constant as it matches Gax's logic for
167162
// method name.

0 commit comments

Comments
 (0)