Skip to content

Commit 8edac53

Browse files
committed
chore: Add transport as an attribute
1 parent 6a981e4 commit 8edac53

File tree

2 files changed

+25
-4
lines changed

2 files changed

+25
-4
lines changed

java-datastore/google-cloud-datastore/src/main/java/com/google/cloud/datastore/DatastoreImpl.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
import com.google.cloud.RetryHelper;
4545
import com.google.cloud.RetryHelper.RetryHelperException;
4646
import com.google.cloud.ServiceOptions;
47+
import com.google.cloud.TransportOptions;
4748
import com.google.cloud.datastore.execution.AggregationQueryExecutor;
4849
import com.google.cloud.datastore.spi.v1.DatastoreRpc;
4950
import com.google.cloud.datastore.telemetry.MetricsRecorder;
@@ -215,7 +216,7 @@ public T call() throws DatastoreException {
215216
}
216217
throw DatastoreException.propagateUserException(ex);
217218
} finally {
218-
recordAttempt(attemptStatus);
219+
recordAttempt(attemptStatus, datastore.getOptions().getTransportOptions());
219220
// If the transaction is active, then commit the rollback. If it was already successfully
220221
// rolled back, the transaction is inactive (prevents rolling back an already rolled back
221222
// transaction).
@@ -233,7 +234,7 @@ public T call() throws DatastoreException {
233234
* Records a single transaction commit attempt with the given status code. This is called once
234235
* per invocation of {@link #call()}, capturing the outcome of each individual commit attempt.
235236
*/
236-
private void recordAttempt(String status) {
237+
private void recordAttempt(String status, TransportOptions transportOptions) {
237238
Map<String, String> attributes = new HashMap<>();
238239
attributes.put(TelemetryConstants.ATTRIBUTES_KEY_STATUS, status);
239240
attributes.put(
@@ -242,6 +243,9 @@ private void recordAttempt(String status) {
242243
TelemetryConstants.ATTRIBUTES_KEY_PROJECT_ID, datastore.getOptions().getProjectId());
243244
attributes.put(
244245
TelemetryConstants.ATTRIBUTES_KEY_DATABASE_ID, datastore.getOptions().getDatabaseId());
246+
attributes.put(
247+
TelemetryConstants.ATTRIBUTES_KEY_TRANSPORT,
248+
TelemetryConstants.getTransportName(transportOptions));
245249
metricsRecorder.recordTransactionAttemptCount(1, attributes);
246250
}
247251
}
@@ -284,6 +288,9 @@ public <T> T runInTransaction(
284288
TelemetryConstants.ATTRIBUTES_KEY_METHOD, TelemetryConstants.METHOD_TRANSACTION_RUN);
285289
attributes.put(TelemetryConstants.ATTRIBUTES_KEY_PROJECT_ID, getOptions().getProjectId());
286290
attributes.put(TelemetryConstants.ATTRIBUTES_KEY_DATABASE_ID, getOptions().getDatabaseId());
291+
attributes.put(
292+
TelemetryConstants.ATTRIBUTES_KEY_TRANSPORT,
293+
TelemetryConstants.getTransportName(getOptions().getTransportOptions()));
287294
metricsRecorder.recordTransactionLatency(latencyMs, attributes);
288295
span.end();
289296
}

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

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
package com.google.cloud.datastore.telemetry;
1818

1919
import com.google.api.core.InternalApi;
20+
import com.google.cloud.TransportOptions;
21+
import com.google.cloud.grpc.GrpcTransportOptions;
2022

2123
/**
2224
* Internal telemetry constants shared between OpenTelemetry tracing and metrics.
@@ -51,13 +53,17 @@ public class TelemetryConstants {
5153
/** Attribute key for the Datastore database ID. */
5254
public static final String ATTRIBUTES_KEY_DATABASE_ID = "database_id";
5355

56+
public static final String ATTRIBUTES_KEY_LIBRARY_VERSION = "library_version";
57+
58+
public static final String ATTRIBUTES_KEY_TRANSPORT = "transport";
59+
5460
/** Metric name for the total latency of a transaction. */
5561
public static final String METRIC_NAME_TRANSACTION_LATENCY =
56-
SERVICE_NAME + "/transaction_latency";
62+
SERVICE_NAME + "/client/transaction_latency";
5763

5864
/** Metric name for the number of attempts a transaction took. */
5965
public static final String METRIC_NAME_TRANSACTION_ATTEMPT_COUNT =
60-
SERVICE_NAME + "/transaction_attempt_count";
66+
SERVICE_NAME + "/client/transaction_attempt_count";
6167

6268
/* TODO(lawrenceqiu): For now, these are a duplicate of method names in TraceUtil. Those will use these eventually */
6369
// Format is not SnakeCase to keep backward compatibility with the existing values TraceUtil spans
@@ -81,4 +87,12 @@ public class TelemetryConstants {
8187
public static final String METHOD_SUBMIT = "submit";
8288

8389
private TelemetryConstants() {}
90+
91+
public static String getTransportName(TransportOptions transportOptions) {
92+
if (transportOptions instanceof GrpcTransportOptions) {
93+
return "grpc";
94+
} else {
95+
return "http";
96+
}
97+
}
8498
}

0 commit comments

Comments
 (0)