diff --git a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/SpannerOptions.java b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/SpannerOptions.java index 7c232ddaa1..bc81b42903 100644 --- a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/SpannerOptions.java +++ b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/SpannerOptions.java @@ -83,6 +83,7 @@ import java.util.List; import java.util.Map; import java.util.Map.Entry; +import java.util.Objects; import java.util.Set; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.ScheduledThreadPoolExecutor; @@ -1791,6 +1792,10 @@ public CallCredentialsProvider getCallCredentialsProvider() { return callCredentialsProvider; } + private boolean usesNoCredentials() { + return Objects.equals(getCredentials(), NoCredentials.getInstance()); + } + public String getCompressorName() { return compressorName; } @@ -1838,7 +1843,7 @@ private ApiTracerFactory createApiTracerFactory( // Add Metrics Tracer factory if built in metrics are enabled and if the client is data client // and if emulator is not enabled. - if (isEnableBuiltInMetrics() && !isAdminClient && !isEmulatorEnabled) { + if (isEnableBuiltInMetrics() && !isAdminClient && !isEmulatorEnabled && !usesNoCredentials()) { ApiTracerFactory metricsTracerFactory = createMetricsApiTracerFactory(); if (metricsTracerFactory != null) { apiTracerFactories.add(metricsTracerFactory); diff --git a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/SpannerOptionsTest.java b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/SpannerOptionsTest.java index cdab8e1df8..70482c0ffd 100644 --- a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/SpannerOptionsTest.java +++ b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/SpannerOptionsTest.java @@ -738,7 +738,7 @@ public void testLeaderAwareRoutingEnablement() { @Test public void testEndToEndTracingEnablement() { - // Test that end to end tracing is disabled by default. + // Test that end-to-end tracing is disabled by default. assertFalse(SpannerOptions.newBuilder().setProjectId("p").build().isEndToEndTracingEnabled()); assertTrue( SpannerOptions.newBuilder() @@ -755,7 +755,7 @@ public void testEndToEndTracingEnablement() { } @Test - public void testmonitoringHost() { + public void testMonitoringHost() { String metricsEndpoint = "test-endpoint:443"; assertNull(SpannerOptions.newBuilder().setProjectId("p").build().getMonitoringHost()); assertThat(