Skip to content

fix(bigquery-jdbc): isolate OpenTelemetry SDK cache keys and shutdown lifecycle - #15347

Open
keshavdandeva wants to merge 4 commits into
fix/jdbc-telemetry-4-gapic-cloud-loggingfrom
fix/jdbc-telemetry-5-sdk-cache-lifecycle
Open

keshavdandeva wants to merge 4 commits into
fix/jdbc-telemetry-4-gapic-cloud-loggingfrom
fix/jdbc-telemetry-5-sdk-cache-lifecycle

Conversation

@keshavdandeva

Copy link
Copy Markdown
Contributor

Summary

Extracts TelemetrySdkCacheKey to segregate driver-managed OpenTelemetrySdk instances across universeDomain, credentials, proxy, TrustStore, and OAuth overrides without storing plaintext secrets, and replaces per-SDK JVM shutdown hooks with a single concurrent shutdown hook.

Key Decisions

  • Log-only vs. trace-exporting cache keys: Log-only SDKs (enableGcpTraceExporter=false) configure no exporters and now key solely on projectId to avoid unnecessary SDK duplication across differing transport configs.
  • SHA-256 credential identity without plaintext secrets: For trace-exporting SDKs, TelemetrySdkCacheKey hashes immutable credential fields via SHA-256 (gcpTelemetryCredentials bytes/content, ServiceAccountCredentials, refresh-token UserCredentials, ComputeEngineCredentials, ImpersonatedCredentials via toBuilder() including ordered delegates, scopes, lifetime, iamEndpointOverride, and nested sources, and ADC ExternalAccountCredentials via a single boolean applicationDefaultCredentials flag on TelemetryTransportConfig). Custom Credentials subclasses fall back to object-reference identity.
  • Omitted non-discriminating fields: Omits ProxyUid/ProxyPwd (rejected eagerly when trace export is on), SSLTrustStorePwd (store is identified by path/type/provider), and ambient OTel system properties.
  • Single concurrent JVM shutdown hook: Disables OTel's per-SDK shutdown hooks (.disableShutdownHook()) and registers one static hook calling shutdownAllSdks(), which initiates sdk.shutdown() on all active cached SDKs concurrently and awaits CompletableResultCode.ofAll(...) up to 10s.

Behavior Changes

  • Isolated SDK caching: Connections differing in universeDomain, credentials, ProxyHost/ProxyPort, SSLTrustStore*, or OAUTH2 token URI override no longer share a trace-exporting OpenTelemetrySdk; pooled connections with identical ImpersonatedCredentials or Drive-scoped ADC ExternalAccountCredentials continue to share one SDK.
  • Log-only SDK sharing: Log-only connections (enableGcpTraceExporter=false, enableGcpLogExporter=true) for the same project share a single no-exporter SDK regardless of transport or credential differences.
  • Bounded JVM exit cleanup: Shut down/closed driver SDKs no longer retain per-SDK JVM shutdown hooks, and active SDKs shut down concurrently on JVM exit instead of sequentially.

@keshavdandeva
keshavdandeva requested review from a team as code owners December 1, 2026 18:59

@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 introduces TelemetrySdkCacheKey to manage and cache driver-managed OpenTelemetrySdk instances, segregating them by project, universe domain, credential identity, proxy settings, and trust store coordinates without storing plaintext secrets. It also adds a shutdown hook to clean up cached SDKs on JVM shutdown. A review comment identifies a potential NullPointerException in TelemetrySdkCacheKey.java if the GOOGLE_APPLICATION_CREDENTIALS environment variable is not set, suggesting a null check before calling BigQueryJdbcOAuthUtility.isFileExists.

Comment on lines +258 to +260
if (BigQueryJdbcOAuthUtility.isFileExists(adcPath)) {
putFileDigest(hasher, adcPath);
}

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.

high

The environment variable GOOGLE_APPLICATION_CREDENTIALS may not be set in all environments, causing System.getenv(...) to return null. Passing a null path to BigQueryJdbcOAuthUtility.isFileExists can lead to a NullPointerException depending on its internal implementation (e.g., if it attempts to instantiate a File or Path object with a null argument). Adding an explicit null check for adcPath prevents this potential crash.

Suggested change
if (BigQueryJdbcOAuthUtility.isFileExists(adcPath)) {
putFileDigest(hasher, adcPath);
}
if (adcPath != null && BigQueryJdbcOAuthUtility.isFileExists(adcPath)) {
putFileDigest(hasher, adcPath);
}

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