Skip to content

fix(bigquery-jdbc): build programmatic OpenTelemetry SDK with credential scoping and cache isolation - #15371

Open
keshavdandeva wants to merge 5 commits into
mainfrom
fix/jdbc-telemetry-v2-2a-otel-programmatic-sdk
Open

keshavdandeva wants to merge 5 commits into
mainfrom
fix/jdbc-telemetry-v2-2a-otel-programmatic-sdk

Conversation

@keshavdandeva

Copy link
Copy Markdown
Contributor

Summary

Replaces AutoConfiguredOpenTelemetrySdk with a programmatic OpenTelemetrySdk for the driver-owned trace exporter, isolates trace export from ambient OTEL_* configuration, fixes OAuth scoping and SDK cache principal isolation, and manages SDK shutdown through a single JVM shutdown hook.

Key Decisions

  • Programmatic OpenTelemetrySdk over autoconfigure: Removing AutoConfiguredOpenTelemetrySdk (and its opentelemetry-sdk-extension-autoconfigure / opentelemetry-sdk-extension-autoconfigure-spi dependencies) prevents ambient OTEL_EXPORTER_OTLP_ENDPOINT, OTEL_EXPORTER_OTLP_HEADERS, and OTEL_TRACES_EXPORTER settings from hijacking the driver's Google bearer tokens or leaking third-party vendor headers to Google endpoints, while honoring otel.exporter.otlp.protocol / OTEL_EXPORTER_OTLP_PROTOCOL (grpc default, http/protobuf opt-in).
  • Shared TelemetryTransportConfig value object: Centralizes connection-level telemetry credentials, OAuth/override/proxy properties, and HttpTransportFactory resolution so BigQueryConnection passes one immutable config object into BigQueryJdbcOpenTelemetry.
  • Metadata-only TelemetrySdkCacheKey: Keys trace SDKs on project ID, protocol, OAuth2 token URI override, proxy host/port, and hashed driver authentication settings (using file path + mtime/size metadata for key files to detect rotation without reading key bytes on cache hits). Log-only SDKs configure no exporters and key solely on projectId.
  • Single static JVM shutdown hook + lock-free duplicate close: Registers one shared shutdown hook on first driver-managed SDK creation instead of leaking one hook per SDK, and closes duplicate racing SDKs outside ConcurrentHashMap.compute.

Behavior Changes

  • BigQueryJdbcOpenTelemetry constructs OtlpGrpcSpanExporter (https://telemetry.googleapis.com:443) or OtlpHttpSpanExporter (https://telemetry.googleapis.com:443/v1/traces, retaining unauthenticated HTTP ProxyOptions when configured) directly without consulting ambient OTEL_* endpoint/header/exporter properties.
  • Credentials narrowed to BigQuery-only scopes (service account, external account, or impersonated credentials) automatically derive a https://www.googleapis.com/auth/cloud-platform-scoped credential for OTLP trace export without mutating the connection's query credentials.
  • Separate connections without explicit gcpTelemetryCredentials no longer collide on an empty-string cache key and share one principal's SDK.
  • Trace configuration and credential resolution failures during connection setup throw checked BigQueryJdbcException (SQLException) instead of unchecked BigQueryJdbcRuntimeException.
  • Removes unused opentelemetry-sdk-extension-autoconfigure and opentelemetry-sdk-extension-autoconfigure-spi dependencies from pom.xml.

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

@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 in the BigQuery JDBC driver by introducing a dedicated TelemetryTransportConfig and TelemetrySdkCacheKey to improve SDK lifecycle management and configuration isolation. It also adds a shutdown hook for SDKs and enhances credential resolution. The review comments provide valuable suggestions for hardening the code against potential runtime exceptions, such as security manager restrictions, invalid proxy configurations, and file path errors, all of which are actionable and should be addressed.

@keshavdandeva
keshavdandeva force-pushed the fix/jdbc-telemetry-v2-2a-otel-programmatic-sdk branch from bc467ee to 29e17fa Compare December 3, 2026 13:31

This branch has not been deployed

No deployments
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