Skip to content

Commit 1e8b82c

Browse files
authored
chore: fix built in client metric data (#3415)
This PR fixes the below issues for client metrics. - Use correct project id instead of defaultProjectId - Sets a default value for directpath_enabled attribute - Use map overload for addAttributes in compositeTracer
1 parent f370394 commit 1e8b82c

File tree

4 files changed

+6
-4
lines changed

4 files changed

+6
-4
lines changed

google-cloud-spanner/src/main/java/com/google/cloud/spanner/BuiltInOpenTelemetryMetricsProvider.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import static com.google.cloud.spanner.BuiltInMetricsConstant.CLIENT_HASH_KEY;
2121
import static com.google.cloud.spanner.BuiltInMetricsConstant.CLIENT_NAME_KEY;
2222
import static com.google.cloud.spanner.BuiltInMetricsConstant.CLIENT_UID_KEY;
23+
import static com.google.cloud.spanner.BuiltInMetricsConstant.DIRECT_PATH_ENABLED_KEY;
2324
import static com.google.cloud.spanner.BuiltInMetricsConstant.INSTANCE_CONFIG_ID_KEY;
2425
import static com.google.cloud.spanner.BuiltInMetricsConstant.LOCATION_ID_KEY;
2526
import static com.google.cloud.spanner.BuiltInMetricsConstant.PROJECT_ID_KEY;
@@ -83,6 +84,7 @@ Map<String, String> createClientAttributes(String projectId, String client_name)
8384
clientAttributes.put(LOCATION_ID_KEY.getKey(), detectClientLocation());
8485
clientAttributes.put(PROJECT_ID_KEY.getKey(), projectId);
8586
// TODO: Replace this with real value.
87+
clientAttributes.put(DIRECT_PATH_ENABLED_KEY.getKey(), "false");
8688
clientAttributes.put(INSTANCE_CONFIG_ID_KEY.getKey(), "unknown");
8789
clientAttributes.put(CLIENT_NAME_KEY.getKey(), client_name);
8890
String clientUid = getDefaultTaskValue();

google-cloud-spanner/src/main/java/com/google/cloud/spanner/CompositeTracer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ public void addAttributes(Map<String, String> attributes) {
184184
for (ApiTracer child : children) {
185185
if (child instanceof MetricsTracer) {
186186
MetricsTracer metricsTracer = (MetricsTracer) child;
187-
attributes.forEach((key, value) -> metricsTracer.addAttributes(key, value));
187+
metricsTracer.addAttributes(attributes);
188188
}
189189
}
190190
}

google-cloud-spanner/src/main/java/com/google/cloud/spanner/SpannerOptions.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1726,14 +1726,13 @@ private ApiTracerFactory getDefaultApiTracerFactory() {
17261726
private ApiTracerFactory createMetricsApiTracerFactory() {
17271727
OpenTelemetry openTelemetry =
17281728
this.builtInOpenTelemetryMetricsProvider.getOrCreateOpenTelemetry(
1729-
getDefaultProjectId(), getCredentials());
1729+
this.getProjectId(), getCredentials());
17301730

17311731
return openTelemetry != null
17321732
? new MetricsTracerFactory(
17331733
new OpenTelemetryMetricsRecorder(openTelemetry, BuiltInMetricsConstant.METER_NAME),
17341734
builtInOpenTelemetryMetricsProvider.createClientAttributes(
1735-
getDefaultProjectId(),
1736-
"spanner-java/" + GaxProperties.getLibraryVersion(getClass())))
1735+
this.getProjectId(), "spanner-java/" + GaxProperties.getLibraryVersion(getClass())))
17371736
: null;
17381737
}
17391738

google-cloud-spanner/src/test/java/com/google/cloud/spanner/OpenTelemetryBuiltInMetricsTracerTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ public static void setup() {
9494
Attributes.builder()
9595
.put(BuiltInMetricsConstant.PROJECT_ID_KEY, "test-project")
9696
.put(BuiltInMetricsConstant.INSTANCE_CONFIG_ID_KEY, "unknown")
97+
.put(BuiltInMetricsConstant.DIRECT_PATH_ENABLED_KEY, "false")
9798
.put(
9899
BuiltInMetricsConstant.LOCATION_ID_KEY,
99100
BuiltInOpenTelemetryMetricsProvider.detectClientLocation())

0 commit comments

Comments
 (0)