From a6a224c22a4a75a0dd8f1c3a46d8fa1bd14650b4 Mon Sep 17 00:00:00 2001 From: Keshav Dandeva Date: Wed, 22 Jul 2026 20:29:30 +0000 Subject: [PATCH 1/6] test: testing presubmits --- .../google/cloud/bigquery/jdbc/it/suites/ITPresubmitTests.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/java-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/it/suites/ITPresubmitTests.java b/java-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/it/suites/ITPresubmitTests.java index 44e37f6888e2..3ca7a471fdb2 100644 --- a/java-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/it/suites/ITPresubmitTests.java +++ b/java-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/it/suites/ITPresubmitTests.java @@ -24,6 +24,7 @@ import com.google.cloud.bigquery.jdbc.it.ITDatabaseMetadataTest; import com.google.cloud.bigquery.jdbc.it.ITDriverTest; import com.google.cloud.bigquery.jdbc.it.ITLocalSslValidationTest; +import com.google.cloud.bigquery.jdbc.it.ITOpenTelemetryTest; import com.google.cloud.bigquery.jdbc.it.ITResultSetMetadataTest; import com.google.cloud.bigquery.jdbc.it.ITStatementTest; import org.junit.platform.suite.api.SelectClasses; @@ -39,6 +40,7 @@ ITDatabaseMetadataTest.class, ITDriverTest.class, ITLocalSslValidationTest.class, + ITOpenTelemetryTest.class, ITResultSetMetadataTest.class, ITStatementTest.class }) From 359ce44b8a27e2a218ccf548dbba4d202ac91d8c Mon Sep 17 00:00:00 2001 From: Keshav Dandeva Date: Wed, 22 Jul 2026 21:04:51 +0000 Subject: [PATCH 2/6] increase maxAttempts to wait around ~60 seconds --- .../com/google/cloud/bigquery/jdbc/it/ITOpenTelemetryTest.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/java-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/it/ITOpenTelemetryTest.java b/java-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/it/ITOpenTelemetryTest.java index 792ae5071841..c6ca78771a5c 100644 --- a/java-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/it/ITOpenTelemetryTest.java +++ b/java-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/it/ITOpenTelemetryTest.java @@ -306,7 +306,7 @@ private Trace verifyAndFetchTrace(String traceId) throws Exception { private T pollWithRetry(java.util.concurrent.Callable task) throws InterruptedException { int attempts = 0; - int maxAttempts = 30; // 30 attempts * 500ms = 15 seconds max delay + int maxAttempts = 120; // 120 attempts * 500ms = 60 seconds max delay long delayMs = 500; // 500ms linear polling while (attempts < maxAttempts) { @@ -321,6 +321,7 @@ private T pollWithRetry(java.util.concurrent.Callable task) throws Interr throw new RuntimeException("Test execution interrupted", e); } catch (Exception e) { // Ignore exceptions during remote lookup and retry + e.printStackTrace(); } if (attempts < maxAttempts) { Thread.sleep(delayMs); From bcdee0212f05ff4d9ab612b97ae74fb4bc9f0991 Mon Sep 17 00:00:00 2001 From: Keshav Dandeva Date: Wed, 22 Jul 2026 22:00:13 +0000 Subject: [PATCH 3/6] chore: fix issues as per feedback --- .../bigquery/jdbc/BigQueryConnection.java | 19 +- .../jdbc/BigQueryJdbcOpenTelemetry.java | 193 +++++++++++------- .../bigquery/jdbc/it/ITOpenTelemetryTest.java | 4 +- .../jdbc/it/suites/ITPresubmitTests.java | 2 - 4 files changed, 130 insertions(+), 88 deletions(-) diff --git a/java-bigquery-jdbc/src/main/java/com/google/cloud/bigquery/jdbc/BigQueryConnection.java b/java-bigquery-jdbc/src/main/java/com/google/cloud/bigquery/jdbc/BigQueryConnection.java index 8419f49e1290..2acadeb283cf 100644 --- a/java-bigquery-jdbc/src/main/java/com/google/cloud/bigquery/jdbc/BigQueryConnection.java +++ b/java-bigquery-jdbc/src/main/java/com/google/cloud/bigquery/jdbc/BigQueryConnection.java @@ -1101,6 +1101,7 @@ private void closeImpl() throws SQLException { BigQueryJdbcMdc.clear(); BigQueryJdbcRootLogger.closeConnectionHandler(this.connectionId); BigQueryJdbcOpenTelemetry.unregisterConnection(this.connectionId); + BigQueryJdbcOpenTelemetry.releaseSdk(this.openTelemetry); } if (exceptionToThrow != null) { throw exceptionToThrow; @@ -1211,13 +1212,21 @@ private OpenTelemetry getOpenTelemetryInstance() { } private String resolveEffectiveCredentials() { - String creds = this.gcpTelemetryCredentials; + if (this.gcpTelemetryCredentials != null) { + return this.gcpTelemetryCredentials; + } + String authTypeStr = this.authProperties.get(BigQueryJdbcUrlUtility.OAUTH_TYPE_PROPERTY_NAME); - if (creds == null - && BigQueryJdbcOAuthUtility.AuthType.GOOGLE_SERVICE_ACCOUNT.name().equals(authTypeStr)) { - return this.authProperties.get(BigQueryJdbcUrlUtility.OAUTH_PVT_KEY_PROPERTY_NAME); + if (!BigQueryJdbcOAuthUtility.AuthType.GOOGLE_SERVICE_ACCOUNT.name().equals(authTypeStr)) { + return null; } - return creds; + + String pvtKey = this.authProperties.get(BigQueryJdbcUrlUtility.OAUTH_PVT_KEY_PROPERTY_NAME); + if (pvtKey != null) { + return pvtKey; + } + + return this.authProperties.get(BigQueryJdbcUrlUtility.OAUTH_PVT_KEY_PATH_PROPERTY_NAME); } private void validateTraceConfiguration(boolean isTraceEnabled, String effectiveCredentials) { diff --git a/java-bigquery-jdbc/src/main/java/com/google/cloud/bigquery/jdbc/BigQueryJdbcOpenTelemetry.java b/java-bigquery-jdbc/src/main/java/com/google/cloud/bigquery/jdbc/BigQueryJdbcOpenTelemetry.java index 8544946af550..2127b2ca3b2a 100644 --- a/java-bigquery-jdbc/src/main/java/com/google/cloud/bigquery/jdbc/BigQueryJdbcOpenTelemetry.java +++ b/java-bigquery-jdbc/src/main/java/com/google/cloud/bigquery/jdbc/BigQueryJdbcOpenTelemetry.java @@ -44,6 +44,7 @@ import java.util.Objects; import java.util.concurrent.Callable; import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.atomic.AtomicInteger; import java.util.logging.Handler; import java.util.logging.Logger; @@ -104,7 +105,16 @@ public int hashCode() { } } - private static final ConcurrentHashMap sdkCache = + private static final class CachedSdk { + final OpenTelemetrySdk sdk; + final AtomicInteger refCount = new AtomicInteger(0); + + CachedSdk(OpenTelemetrySdk sdk) { + this.sdk = sdk; + } + } + + private static final ConcurrentHashMap sdkCache = new ConcurrentHashMap<>(); static class TelemetryConfig { @@ -127,20 +137,6 @@ private BigQueryJdbcOpenTelemetry() {} static { ensureGlobalHandlerAttached(); - Runtime.getRuntime() - .addShutdownHook( - new Thread( - () -> { - for (OpenTelemetrySdk sdk : sdkCache.values()) { - try { - sdk.close(); - } catch (Exception e) { - // Ignore failures during shutdown to ensure all SDKs are attempted to be - // closed. Logging is avoided here because the logging system might have - // already been shut down by the JVM. - } - } - })); } public static synchronized void ensureGlobalHandlerAttached() { @@ -207,6 +203,33 @@ public static Logging createLoggingClient( } } + public static void releaseSdk(OpenTelemetry openTelemetry) { + if (openTelemetry == null + || openTelemetry == GlobalOpenTelemetry.get() + || openTelemetry == OpenTelemetry.noop()) { + return; + } + + for (Map.Entry entry : sdkCache.entrySet()) { + if (entry.getValue().sdk == openTelemetry) { + sdkCache.computeIfPresent( + entry.getKey(), + (k, cachedSdk) -> { + if (cachedSdk.refCount.decrementAndGet() <= 0) { + try { + cachedSdk.sdk.close(); + } catch (Exception e) { + LOG.warning("Failed to close OpenTelemetry SDK: %s", e.getMessage()); + } + return null; + } + return cachedSdk; + }); + break; + } + } + } + private static Credentials resolveCredentialsFromString(String credsString) { Map authProperties = new java.util.HashMap<>(); authProperties.put( @@ -295,70 +318,82 @@ public static OpenTelemetry getOpenTelemetry( gcpTelemetryProjectId, getCredentialsIdentifier(gcpTelemetryCredentials), enableGcpTraceExporter); - return sdkCache.computeIfAbsent( - key, - k -> { - Map props = new HashMap<>(); - - if (enableGcpTraceExporter) { - props.put(OTEL_TRACES_EXPORTER, EXPORTER_OTLP); - props.put(OTEL_EXPORTER_OTLP_ENDPOINT, OTLP_ENDPOINT_VALUE); - } else { - props.put(OTEL_TRACES_EXPORTER, EXPORTER_NONE); - } - - // Logs are handled directly via GCP logging - props.put(OTEL_LOGS_EXPORTER, EXPORTER_NONE); - // Metrics are deferred to a future phase - props.put(OTEL_METRICS_EXPORTER, EXPORTER_NONE); - - if (gcpTelemetryProjectId != null) { - props.put(GOOGLE_CLOUD_PROJECT, gcpTelemetryProjectId); - } - - // Set safe, generous default limits on attribute value lengths (32KB) to protect - // customers from GCP Cloud Trace 64KB span ingestion failures when logging massive - // exception stack traces or database schema metadata. - // Respect any existing user configuration overrides. - if (!props.containsKey(OTEL_SPAN_ATTRIBUTE_VALUE_LENGTH_LIMIT)) { - props.put(OTEL_SPAN_ATTRIBUTE_VALUE_LENGTH_LIMIT, DEFAULT_ATTRIBUTE_LENGTH_LIMIT); - } - if (!props.containsKey(OTEL_ATTRIBUTE_VALUE_LENGTH_LIMIT)) { - props.put(OTEL_ATTRIBUTE_VALUE_LENGTH_LIMIT, DEFAULT_ATTRIBUTE_LENGTH_LIMIT); - } - - AutoConfiguredOpenTelemetrySdk autoConfigured = - AutoConfiguredOpenTelemetrySdk.builder() - .addPropertiesSupplier(() -> props) - .addSpanExporterCustomizer( - (spanExporter, configProperties) -> { - if (gcpTelemetryCredentials == null) { - return spanExporter; - } - try { - Credentials credentials = - resolveCredentialsFromString(gcpTelemetryCredentials); - if (spanExporter instanceof OtlpHttpSpanExporter) { - return ((OtlpHttpSpanExporter) spanExporter) - .toBuilder().setHeaders(() -> getAuthHeaders(credentials)).build(); - } - if (spanExporter instanceof OtlpGrpcSpanExporter) { - return ((OtlpGrpcSpanExporter) spanExporter) - .toBuilder().setHeaders(() -> getAuthHeaders(credentials)).build(); - } - } catch (Exception e) { - LOG.warning( - e, - "Failed to resolve telemetry credentials. Telemetry will be exported using default OpenTelemetry configuration (custom authentication headers will not be injected)."); - } - return spanExporter; - }) - .build(); - - OpenTelemetrySdk sdk = autoConfigured.getOpenTelemetrySdk(); - - return sdk; - }); + return sdkCache.compute( + key, + (k, cachedSdk) -> { + if (cachedSdk != null) { + cachedSdk.refCount.incrementAndGet(); + return cachedSdk; + } + + Map props = new HashMap<>(); + + if (enableGcpTraceExporter) { + props.put(OTEL_TRACES_EXPORTER, EXPORTER_OTLP); + props.put(OTEL_EXPORTER_OTLP_ENDPOINT, OTLP_ENDPOINT_VALUE); + } else { + props.put(OTEL_TRACES_EXPORTER, EXPORTER_NONE); + } + + // Logs are handled directly via GCP logging + props.put(OTEL_LOGS_EXPORTER, EXPORTER_NONE); + // Metrics are deferred to a future phase + props.put(OTEL_METRICS_EXPORTER, EXPORTER_NONE); + + if (gcpTelemetryProjectId != null) { + props.put(GOOGLE_CLOUD_PROJECT, gcpTelemetryProjectId); + } + + // Set safe, generous default limits on attribute value lengths (32KB) to protect + // customers from GCP Cloud Trace 64KB span ingestion failures when logging massive + // exception stack traces or database schema metadata. + // Respect any existing user configuration overrides. + if (!props.containsKey(OTEL_SPAN_ATTRIBUTE_VALUE_LENGTH_LIMIT)) { + props.put(OTEL_SPAN_ATTRIBUTE_VALUE_LENGTH_LIMIT, DEFAULT_ATTRIBUTE_LENGTH_LIMIT); + } + if (!props.containsKey(OTEL_ATTRIBUTE_VALUE_LENGTH_LIMIT)) { + props.put(OTEL_ATTRIBUTE_VALUE_LENGTH_LIMIT, DEFAULT_ATTRIBUTE_LENGTH_LIMIT); + } + + AutoConfiguredOpenTelemetrySdk autoConfigured = + AutoConfiguredOpenTelemetrySdk.builder() + .addPropertiesSupplier(() -> props) + .addSpanExporterCustomizer( + (spanExporter, configProperties) -> { + if (gcpTelemetryCredentials == null) { + return spanExporter; + } + try { + Credentials credentials = + resolveCredentialsFromString(gcpTelemetryCredentials); + if (spanExporter instanceof OtlpHttpSpanExporter) { + return ((OtlpHttpSpanExporter) spanExporter) + .toBuilder() + .setHeaders(() -> getAuthHeaders(credentials)) + .build(); + } + if (spanExporter instanceof OtlpGrpcSpanExporter) { + return ((OtlpGrpcSpanExporter) spanExporter) + .toBuilder() + .setHeaders(() -> getAuthHeaders(credentials)) + .build(); + } + } catch (Exception e) { + LOG.warning( + e, + "Failed to resolve telemetry credentials. Telemetry will be exported using default OpenTelemetry configuration (custom authentication headers will not be injected)."); + } + return spanExporter; + }) + .build(); + + OpenTelemetrySdk sdk = autoConfigured.getOpenTelemetrySdk(); + + CachedSdk newCachedSdk = new CachedSdk(sdk); + newCachedSdk.refCount.incrementAndGet(); + return newCachedSdk; + }) + .sdk; } /** Gets a Tracer for the JDBC driver instrumentation scope. */ diff --git a/java-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/it/ITOpenTelemetryTest.java b/java-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/it/ITOpenTelemetryTest.java index c6ca78771a5c..9baf187b4d38 100644 --- a/java-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/it/ITOpenTelemetryTest.java +++ b/java-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/it/ITOpenTelemetryTest.java @@ -306,8 +306,8 @@ private Trace verifyAndFetchTrace(String traceId) throws Exception { private T pollWithRetry(java.util.concurrent.Callable task) throws InterruptedException { int attempts = 0; - int maxAttempts = 120; // 120 attempts * 500ms = 60 seconds max delay - long delayMs = 500; // 500ms linear polling + int maxAttempts = 20; // 20 attempts * 3000ms = 60 seconds max delay + long delayMs = 3000; // 3000ms linear polling while (attempts < maxAttempts) { attempts++; diff --git a/java-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/it/suites/ITPresubmitTests.java b/java-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/it/suites/ITPresubmitTests.java index 3ca7a471fdb2..44e37f6888e2 100644 --- a/java-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/it/suites/ITPresubmitTests.java +++ b/java-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/it/suites/ITPresubmitTests.java @@ -24,7 +24,6 @@ import com.google.cloud.bigquery.jdbc.it.ITDatabaseMetadataTest; import com.google.cloud.bigquery.jdbc.it.ITDriverTest; import com.google.cloud.bigquery.jdbc.it.ITLocalSslValidationTest; -import com.google.cloud.bigquery.jdbc.it.ITOpenTelemetryTest; import com.google.cloud.bigquery.jdbc.it.ITResultSetMetadataTest; import com.google.cloud.bigquery.jdbc.it.ITStatementTest; import org.junit.platform.suite.api.SelectClasses; @@ -40,7 +39,6 @@ ITDatabaseMetadataTest.class, ITDriverTest.class, ITLocalSslValidationTest.class, - ITOpenTelemetryTest.class, ITResultSetMetadataTest.class, ITStatementTest.class }) From 1a21a66384c4af614f052ee3146b77fe11131ccb Mon Sep 17 00:00:00 2001 From: Keshav Dandeva Date: Wed, 22 Jul 2026 22:09:46 +0000 Subject: [PATCH 4/6] address pr feedback --- .../cloud/bigquery/jdbc/BigQueryJdbcOpenTelemetry.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/java-bigquery-jdbc/src/main/java/com/google/cloud/bigquery/jdbc/BigQueryJdbcOpenTelemetry.java b/java-bigquery-jdbc/src/main/java/com/google/cloud/bigquery/jdbc/BigQueryJdbcOpenTelemetry.java index 2127b2ca3b2a..27add71992ab 100644 --- a/java-bigquery-jdbc/src/main/java/com/google/cloud/bigquery/jdbc/BigQueryJdbcOpenTelemetry.java +++ b/java-bigquery-jdbc/src/main/java/com/google/cloud/bigquery/jdbc/BigQueryJdbcOpenTelemetry.java @@ -215,10 +215,16 @@ public static void releaseSdk(OpenTelemetry openTelemetry) { sdkCache.computeIfPresent( entry.getKey(), (k, cachedSdk) -> { + if (cachedSdk.sdk != openTelemetry) { + return cachedSdk; + } if (cachedSdk.refCount.decrementAndGet() <= 0) { try { cachedSdk.sdk.close(); } catch (Exception e) { + // Swallow exceptions so that telemetry shutdown failures (e.g. flush timeouts) + // do not propagate and disrupt the core BigQueryConnection.close() logic. + // Throwing here could prevent the core connection from cleaning up correctly. LOG.warning("Failed to close OpenTelemetry SDK: %s", e.getMessage()); } return null; From 11d061442ed810032b0c7faa06035e3e18b624ee Mon Sep 17 00:00:00 2001 From: Keshav Dandeva Date: Wed, 22 Jul 2026 22:29:43 +0000 Subject: [PATCH 5/6] address feedback nits --- .../bigquery/jdbc/BigQueryConnection.java | 1 + .../jdbc/BigQueryJdbcOpenTelemetry.java | 28 +++++++++++-------- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/java-bigquery-jdbc/src/main/java/com/google/cloud/bigquery/jdbc/BigQueryConnection.java b/java-bigquery-jdbc/src/main/java/com/google/cloud/bigquery/jdbc/BigQueryConnection.java index 2acadeb283cf..a8b00689906e 100644 --- a/java-bigquery-jdbc/src/main/java/com/google/cloud/bigquery/jdbc/BigQueryConnection.java +++ b/java-bigquery-jdbc/src/main/java/com/google/cloud/bigquery/jdbc/BigQueryConnection.java @@ -1102,6 +1102,7 @@ private void closeImpl() throws SQLException { BigQueryJdbcRootLogger.closeConnectionHandler(this.connectionId); BigQueryJdbcOpenTelemetry.unregisterConnection(this.connectionId); BigQueryJdbcOpenTelemetry.releaseSdk(this.openTelemetry); + this.openTelemetry = null; } if (exceptionToThrow != null) { throw exceptionToThrow; diff --git a/java-bigquery-jdbc/src/main/java/com/google/cloud/bigquery/jdbc/BigQueryJdbcOpenTelemetry.java b/java-bigquery-jdbc/src/main/java/com/google/cloud/bigquery/jdbc/BigQueryJdbcOpenTelemetry.java index 27add71992ab..806c7c5f6d6f 100644 --- a/java-bigquery-jdbc/src/main/java/com/google/cloud/bigquery/jdbc/BigQueryJdbcOpenTelemetry.java +++ b/java-bigquery-jdbc/src/main/java/com/google/cloud/bigquery/jdbc/BigQueryJdbcOpenTelemetry.java @@ -44,6 +44,7 @@ import java.util.Objects; import java.util.concurrent.Callable; import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicInteger; import java.util.logging.Handler; import java.util.logging.Logger; @@ -107,7 +108,7 @@ public int hashCode() { private static final class CachedSdk { final OpenTelemetrySdk sdk; - final AtomicInteger refCount = new AtomicInteger(0); + final AtomicInteger refCount = new AtomicInteger(1); CachedSdk(OpenTelemetrySdk sdk) { this.sdk = sdk; @@ -210,6 +211,7 @@ public static void releaseSdk(OpenTelemetry openTelemetry) { return; } + AtomicBoolean shouldClose = new AtomicBoolean(false); for (Map.Entry entry : sdkCache.entrySet()) { if (entry.getValue().sdk == openTelemetry) { sdkCache.computeIfPresent( @@ -219,14 +221,7 @@ public static void releaseSdk(OpenTelemetry openTelemetry) { return cachedSdk; } if (cachedSdk.refCount.decrementAndGet() <= 0) { - try { - cachedSdk.sdk.close(); - } catch (Exception e) { - // Swallow exceptions so that telemetry shutdown failures (e.g. flush timeouts) - // do not propagate and disrupt the core BigQueryConnection.close() logic. - // Throwing here could prevent the core connection from cleaning up correctly. - LOG.warning("Failed to close OpenTelemetry SDK: %s", e.getMessage()); - } + shouldClose.set(true); return null; } return cachedSdk; @@ -234,6 +229,17 @@ public static void releaseSdk(OpenTelemetry openTelemetry) { break; } } + + if (shouldClose.get() && openTelemetry instanceof OpenTelemetrySdk) { + try { + ((OpenTelemetrySdk) openTelemetry).close(); + } catch (Exception e) { + // Swallow exceptions so that telemetry shutdown failures (e.g. flush timeouts) + // do not propagate and disrupt the core BigQueryConnection.close() logic. + // Throwing here could prevent the core connection from cleaning up correctly. + LOG.warning("Failed to close OpenTelemetry SDK: %s", e.getMessage()); + } + } } private static Credentials resolveCredentialsFromString(String credsString) { @@ -395,9 +401,7 @@ public static OpenTelemetry getOpenTelemetry( OpenTelemetrySdk sdk = autoConfigured.getOpenTelemetrySdk(); - CachedSdk newCachedSdk = new CachedSdk(sdk); - newCachedSdk.refCount.incrementAndGet(); - return newCachedSdk; + return new CachedSdk(sdk); }) .sdk; } From 0f42545b12f1f5f026c36e0002ae0c7aa337c6a6 Mon Sep 17 00:00:00 2001 From: Keshav Dandeva Date: Thu, 23 Jul 2026 14:45:59 +0000 Subject: [PATCH 6/6] fix ADC support --- .../bigquery/jdbc/BigQueryJdbcOpenTelemetry.java | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/java-bigquery-jdbc/src/main/java/com/google/cloud/bigquery/jdbc/BigQueryJdbcOpenTelemetry.java b/java-bigquery-jdbc/src/main/java/com/google/cloud/bigquery/jdbc/BigQueryJdbcOpenTelemetry.java index 806c7c5f6d6f..cee8fcb5b654 100644 --- a/java-bigquery-jdbc/src/main/java/com/google/cloud/bigquery/jdbc/BigQueryJdbcOpenTelemetry.java +++ b/java-bigquery-jdbc/src/main/java/com/google/cloud/bigquery/jdbc/BigQueryJdbcOpenTelemetry.java @@ -17,6 +17,7 @@ package com.google.cloud.bigquery.jdbc; import com.google.auth.Credentials; +import com.google.auth.oauth2.GoogleCredentials; import com.google.cloud.bigquery.exception.BigQueryJdbcRuntimeException; import com.google.cloud.logging.Logging; import com.google.cloud.logging.LoggingOptions; @@ -372,12 +373,13 @@ public static OpenTelemetry getOpenTelemetry( .addPropertiesSupplier(() -> props) .addSpanExporterCustomizer( (spanExporter, configProperties) -> { - if (gcpTelemetryCredentials == null) { - return spanExporter; - } try { - Credentials credentials = - resolveCredentialsFromString(gcpTelemetryCredentials); + Credentials credentials; + if (gcpTelemetryCredentials != null) { + credentials = resolveCredentialsFromString(gcpTelemetryCredentials); + } else { + credentials = GoogleCredentials.getApplicationDefault(); + } if (spanExporter instanceof OtlpHttpSpanExporter) { return ((OtlpHttpSpanExporter) spanExporter) .toBuilder()