Skip to content

fix(bigquery-jdbc): migrate direct Cloud Logging to GAPIC LoggingClient - #15373

Open
keshavdandeva wants to merge 4 commits into
fix/jdbc-telemetry-v2-2b-otel-universe-proxy-tlsfrom
fix/jdbc-telemetry-v2-3b-gapic-cloud-logging
Open

keshavdandeva wants to merge 4 commits into
fix/jdbc-telemetry-v2-2b-otel-universe-proxy-tlsfrom
fix/jdbc-telemetry-v2-3b-gapic-cloud-logging

Conversation

@keshavdandeva

Copy link
Copy Markdown
Contributor

Summary

Migrates direct Cloud Logging export (enableGcpLogExporter=true) from the legacy com.google.cloud.logging.Logging client to the GAPIC com.google.cloud.logging.v2.LoggingClient via a package-private GcpLogWriter, enabling per-connection gRPC proxy (including authenticated proxies), SSLTrustStore*, universeDomain, and OAuth scope/override propagation.

Key Decisions

  • GAPIC LoggingClient via GcpLogWriter: Legacy GrpcLoggingRpc builds its own channel from LoggingOptions.getHost() and cannot accept a TransportChannelProvider. Passing BigQueryConnection's transportChannelProvider into GAPIC LoggingSettings routes Cloud Logging through the exact same HTTP CONNECT proxy (authenticated or unauthenticated) and SSLTrustStore* channel configuration as BigQuery Storage gRPC clients.
  • Scoped credentials + fail-closed universe validation: Reuses TelemetryTransportConfig.resolveCredentials("https://www.googleapis.com/auth/logging.write") so BigQuery-only credentials derive a logging.write-scoped credential without mutating query credentials and reject mismatched universe domains with checked BigQueryJdbcException.
  • Non-blocking, bounded best-effort sink: Relies on GAPIC's ThrowException flow-control behavior to drop overflow entries instead of stalling JDBC threads, guards against re-entrant JUL logging with a ThreadLocal, logs the first write failure once and summarizes total dropped writes on close, and enforces a bounded 6-second flush deadline (shutdownNow() on timeout/interruption) with a single shared deadline across writers in OpenTelemetryJulHandler.flush().
  • Lazy JVM-wide MonitoredResource detection: Caches host environment detection once per JVM (stamping project_id per connection) to avoid MonitoredResourceUtil's unsynchronized cache and repeated metadata probes.

Behavior Changes

  • Direct Cloud Logging honors ProxyHost/ProxyPort/ProxyUid/ProxyPwd, SSLTrustStore*, universeDomain, EndpointOverrides (OAUTH2), HeaderProvider, and logging.write OAuth scoping.
  • OpenTelemetryJulHandler delegates direct Cloud Logging writes to GcpLogWriter, propagating traceId, spanId, and traceSampled.
  • Cloud Logging initialization errors surface as checked BigQueryJdbcException (SQLException), and BigQueryConnection's constructor finally block releases any cached OpenTelemetry SDK if GcpLogWriter.create(...) fails.
  • Removes legacy BigQueryJdbcOpenTelemetry.createLoggingClient(...).

@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 GcpLogWriter, a package-private direct Google Cloud Logging writer backed by the GAPIC LoggingClient, replacing the previous usage of com.google.cloud.logging.Logging across the JDBC driver. Feedback on these changes focuses on enhancing robustness and performance within GcpLogWriter. Specifically, it is recommended to catch all exceptions during log writes to prevent runtime exceptions from propagating to the application thread, add defensive null checks during environment resource detection to avoid potential NullPointerExceptions, and reuse the ApiFuture instance as the key in pendingWrites to reduce object allocation overhead.

@keshavdandeva
keshavdandeva force-pushed the fix/jdbc-telemetry-v2-3b-gapic-cloud-logging branch from 3b2ce48 to 4c9ea3e 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