Skip to content

fix(bigquery-jdbc): build programmatic OpenTelemetry SDK with universeDomain, proxy, TrustStore, and cache isolation - #15363

Closed
keshavdandeva wants to merge 4 commits into
fix/jdbc-telemetry-v2-1-proxy-ssl-utilsfrom
fix/jdbc-telemetry-v2-2-otel-programmatic-universe
Closed

keshavdandeva wants to merge 4 commits into
fix/jdbc-telemetry-v2-1-proxy-ssl-utilsfrom
fix/jdbc-telemetry-v2-2-otel-programmatic-universe

Conversation

@keshavdandeva

@keshavdandeva keshavdandeva commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Replaces AutoConfiguredOpenTelemetrySdk with a programmatic OpenTelemetrySdk (OtlpGrpcSpanExporter / OtlpHttpSpanExporter) in BigQueryJdbcOpenTelemetry, introduces TelemetryTransportConfig and TelemetrySdkCacheKey, and propagates per-connection universeDomain, proxy, TrustStore, OAuth endpoint overrides, and scoped credentials into driver-managed trace export.

Key Decisions

  • Programmatic OTel SDK instead of AutoConfiguredOpenTelemetrySdk: Removes opentelemetry-sdk-extension-autoconfigure and opentelemetry-sdk-extension-autoconfigure-spi from pom.xml (thin-JAR consumers should note these transitive dependencies are no longer pulled in). Builds OtlpGrpcSpanExporter (default) or OtlpHttpSpanExporter (when a proxy is configured or otel.exporter.otlp.protocol / OTEL_EXPORTER_OTLP_PROTOCOL is http/protobuf) directly against https://telemetry.<universeDomain>:443 (or /v1/traces for HTTP), applying ProxyOptions and SslConfig. Eliminates ambient OTEL_* endpoint, header, sampler, and exporter overrides that could redirect exports or leak Google bearer tokens.
  • Scoped telemetry credentials with fail-closed universe validation: Resolves gcpTelemetryCredentials (or falls back to connection credentials) with the https://www.googleapis.com/auth/cloud-platform scope rather than reusing BigQuery/Drive-only scopes. Re-scopes credentials when needed (skipping re-scope if cloud-platform is already present) and validates credential universeDomain against the connection's effective universe before connecting (deferring metadata-server checks for GCE/impersonated credentials to the exporter thread without permanently latching transient IOExceptions).
  • Content- and transport-aware SDK caching (TelemetrySdkCacheKey): Replaces the old fallback "" cache key so connections using different principals, universeDomain, protocol, proxy, or SSLTrustStore (including path, type, provider, mtime/size, and hashed password) never share an SDK. Keeps TelemetrySdkCacheKey compact (~220 LOC) using Credentials.equals/hashCode and normalized file/inline/ADC fingerprints.
  • Single JVM shutdown hook & safe duplicate close: Registers one static JVM shutdown hook for all cached SDKs instead of leaking one hook per built SDK, and closes duplicate SDKs outside ConcurrentHashMap.compute.
  • Fail fast on authenticated HTTP proxy with driver-managed traces: OpenTelemetry ProxyOptions only supports unauthenticated proxies. When enableGcpTraceExporter=true is combined with ProxyUid/ProxyPwd, connection creation fails fast with a checked BigQueryJdbcException directing callers to useGlobalOpenTelemetry=true or customOpenTelemetry instead of silently failing exports with HTTP 407.

Behavior Changes

  • Driver-managed trace exports now honor per-connection universeDomain, unauthenticated ProxyHost/ProxyPort, SSLTrustStore*, and OAuth EndpointOverrides, and request the cloud-platform scope when connection credentials lack it.
  • Ambient OTEL_* environment variables and system properties (other than otel.exporter.otlp.protocol / OTEL_EXPORTER_OTLP_PROTOCOL when no proxy is configured) no longer override driver-managed trace export settings; use useGlobalOpenTelemetry=true or customOpenTelemetry for external OTel SDK configuration.
  • Invalid trace configuration, credential universe mismatch, and authenticated HTTP proxies with enableGcpTraceExporter=true now fail connection creation with a checked BigQueryJdbcException (SQLException) instead of unchecked BigQueryJdbcRuntimeException or background export errors.
  • Direct-API java-bigquery-jdbc dependency graph no longer includes opentelemetry-sdk-extension-autoconfigure or opentelemetry-sdk-extension-autoconfigure-spi.

@keshavdandeva
keshavdandeva requested review from a team as code owners December 1, 2026 23:09

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +161 to +171
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);
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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.

Suggested change
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);
}
}

@keshavdandeva

Copy link
Copy Markdown
Contributor Author

Superseded by #15371 (programmatic OpenTelemetry SDK, credential scoping, and cache isolation) and #15372 (universeDomain, proxy, and SSLTrustStore* propagation) to split this PR into smaller, independently reviewable changes.

@keshavdandeva
keshavdandeva deleted the fix/jdbc-telemetry-v2-2-otel-programmatic-universe branch December 2, 2026 00:26
@keshavdandeva
keshavdandeva removed this pull request from stack #15369 December 2, 2026 00:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant