Repository navigation
fix(bigquery-jdbc): build programmatic OpenTelemetry SDK with universeDomain, proxy, TrustStore, and cache isolation - #15363
Conversation
…eDomain, proxy, TrustStore, and cache isolation
…K and cache isolation
…tion and fail with checked SQLException
…ed SQLExceptions in BigQueryConnectionTest
There was a problem hiding this comment.
Code Review
This pull request refactors the OpenTelemetry integration by replacing the auto-configured SDK with a programmatic setup. It introduces TelemetryTransportConfig to encapsulate connection-level transport and credential settings, and TelemetrySdkCacheKey to manage caching of SDK instances. Additionally, a shutdown hook is registered to ensure clean cleanup of cached SDKs. A review comment points out a potential issue in TelemetrySdkCacheKey.putFileMetadata where Paths.get is called outside of the try-catch block, which could throw an unchecked InvalidPathException and disrupt connection initialization.
| private static void putFileMetadata(Hasher hasher, String tag, String filePath) { | ||
| Path path = Paths.get(filePath).toAbsolutePath().normalize(); | ||
| putTaggedString(hasher, tag, path.toString()); | ||
| try { | ||
| BasicFileAttributes attrs = Files.readAttributes(path, BasicFileAttributes.class); | ||
| hasher.putBoolean(true); | ||
| hasher.putLong(attrs.lastModifiedTime().toMillis()); | ||
| hasher.putLong(attrs.size()); | ||
| } catch (IOException e) { | ||
| hasher.putBoolean(false); | ||
| } |
There was a problem hiding this comment.
The Paths.get(filePath) call is executed outside of the try-catch block. If the user provides an invalid or malformed file path, this will throw an unchecked InvalidPathException (which extends RuntimeException), causing the connection initialization to fail abruptly. Moving Paths.get inside the try block and catching all exceptions ensures robust handling.
| private static void putFileMetadata(Hasher hasher, String tag, String filePath) { | |
| Path path = Paths.get(filePath).toAbsolutePath().normalize(); | |
| putTaggedString(hasher, tag, path.toString()); | |
| try { | |
| BasicFileAttributes attrs = Files.readAttributes(path, BasicFileAttributes.class); | |
| hasher.putBoolean(true); | |
| hasher.putLong(attrs.lastModifiedTime().toMillis()); | |
| hasher.putLong(attrs.size()); | |
| } catch (IOException e) { | |
| hasher.putBoolean(false); | |
| } | |
| private static void putFileMetadata(Hasher hasher, String tag, String filePath) { | |
| try { | |
| Path path = Paths.get(filePath).toAbsolutePath().normalize(); | |
| putTaggedString(hasher, tag, path.toString()); | |
| BasicFileAttributes attrs = Files.readAttributes(path, BasicFileAttributes.class); | |
| hasher.putBoolean(true); | |
| hasher.putLong(attrs.lastModifiedTime().toMillis()); | |
| hasher.putLong(attrs.size()); | |
| } catch (Exception e) { | |
| hasher.putBoolean(false); | |
| } | |
| } |
Summary
Replaces
AutoConfiguredOpenTelemetrySdkwith a programmaticOpenTelemetrySdk(OtlpGrpcSpanExporter/OtlpHttpSpanExporter) inBigQueryJdbcOpenTelemetry, introducesTelemetryTransportConfigandTelemetrySdkCacheKey, and propagates per-connectionuniverseDomain, proxy, TrustStore, OAuth endpoint overrides, and scoped credentials into driver-managed trace export.Key Decisions
AutoConfiguredOpenTelemetrySdk: Removesopentelemetry-sdk-extension-autoconfigureandopentelemetry-sdk-extension-autoconfigure-spifrompom.xml(thin-JAR consumers should note these transitive dependencies are no longer pulled in). BuildsOtlpGrpcSpanExporter(default) orOtlpHttpSpanExporter(when a proxy is configured orotel.exporter.otlp.protocol/OTEL_EXPORTER_OTLP_PROTOCOLishttp/protobuf) directly againsthttps://telemetry.<universeDomain>:443(or/v1/tracesfor HTTP), applyingProxyOptionsandSslConfig. Eliminates ambientOTEL_*endpoint, header, sampler, and exporter overrides that could redirect exports or leak Google bearer tokens.gcpTelemetryCredentials(or falls back to connection credentials) with thehttps://www.googleapis.com/auth/cloud-platformscope rather than reusing BigQuery/Drive-only scopes. Re-scopes credentials when needed (skipping re-scope ifcloud-platformis already present) and validates credentialuniverseDomainagainst the connection's effective universe before connecting (deferring metadata-server checks for GCE/impersonated credentials to the exporter thread without permanently latching transientIOExceptions).TelemetrySdkCacheKey): Replaces the old fallback""cache key so connections using different principals,universeDomain, protocol, proxy, orSSLTrustStore(including path, type, provider, mtime/size, and hashed password) never share an SDK. KeepsTelemetrySdkCacheKeycompact (~220 LOC) usingCredentials.equals/hashCodeand normalized file/inline/ADC fingerprints.ConcurrentHashMap.compute.ProxyOptionsonly supports unauthenticated proxies. WhenenableGcpTraceExporter=trueis combined withProxyUid/ProxyPwd, connection creation fails fast with a checkedBigQueryJdbcExceptiondirecting callers touseGlobalOpenTelemetry=trueorcustomOpenTelemetryinstead of silently failing exports with HTTP 407.Behavior Changes
universeDomain, unauthenticatedProxyHost/ProxyPort,SSLTrustStore*, and OAuthEndpointOverrides, and request thecloud-platformscope when connection credentials lack it.OTEL_*environment variables and system properties (other thanotel.exporter.otlp.protocol/OTEL_EXPORTER_OTLP_PROTOCOLwhen no proxy is configured) no longer override driver-managed trace export settings; useuseGlobalOpenTelemetry=trueorcustomOpenTelemetryfor external OTel SDK configuration.enableGcpTraceExporter=truenow fail connection creation with a checkedBigQueryJdbcException(SQLException) instead of uncheckedBigQueryJdbcRuntimeExceptionor background export errors.java-bigquery-jdbcdependency graph no longer includesopentelemetry-sdk-extension-autoconfigureoropentelemetry-sdk-extension-autoconfigure-spi.