Skip to content

feat(jdbc): implement OTel SDK and export tracing logic#13039

Open
keshavdandeva wants to merge 6 commits intojdbc/feature-branch-otelfrom
jdbc/otel-sdk-and-export-traces-impl
Open

feat(jdbc): implement OTel SDK and export tracing logic#13039
keshavdandeva wants to merge 6 commits intojdbc/feature-branch-otelfrom
jdbc/otel-sdk-and-export-traces-impl

Conversation

@keshavdandeva
Copy link
Copy Markdown
Contributor

b/491238299

This PR completes the implementation of the OpenTelemetry SDK lifecycle and cross-project authentication for the BigQuery JDBC driver. It introduces thread-safe caching of heavy OTel SDK instances to support multi-project tracing without global side effects.

Changes

BigQueryJdbcOpenTelemetry.java

  • A ConcurrentHashMap caches OpenTelemetrySdk instances, keyed by a concatenated string of ProjectId and Credentials
  • The getOpenTelemetry() method lazily loads and initializes the SDK only when requested and not present in the cache.
  • A JVM shutdown hook closes each cached SDK to ensure pending traces are flushed on application exit.

BigQueryJdbcUrlUtility.java

  • gcpTelemetryCredentials and gcpTelemetryProjectId are added to connection properties.

BigQueryJdbcOAuthUtility.java

  • The isJson() helper method is changed from private to package-private to allow reuse in BigQueryJdbcOpenTelemetry.

BigQueryConnection.java

  • Added new connection properties to be used
  • Uses Boolean.TRUE.equals() when checking enableGcpLogExporter and enableGcpTraceExporter to safely handle cases where these properties are not specified null and avoid NullPointerException during auto-unboxing.

BigQueryJdbcOpenTelemetryTest.java

  • New unit tests verify that SDK instances are correctly cached for identical keys and isolated for different keys.

BigQueryArrowStructTest.java

  • A fix is applied to avoid varargs ambiguity in array creation, resolving a specific coercion failure in the structOfArrays test.

Copy link
Copy Markdown
Contributor

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

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 implements OpenTelemetry SDK initialization and OTLP exporting for the BigQuery JDBC driver. It introduces new connection properties for telemetry credentials and project IDs, and implements a caching mechanism for OTel SDK instances. Review feedback identifies a potential bug in the caching logic where configuration flags are missing from the cache key, and a resource leak caused by registering multiple shutdown hooks. Suggestions were provided to include flags in the cache key and use a single global shutdown hook to manage SDK lifecycle.

@keshavdandeva
Copy link
Copy Markdown
Contributor Author

/gemini review

Copy link
Copy Markdown
Contributor

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

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 implements auto-configuration and caching for OpenTelemetry SDK instances within the BigQuery JDBC driver. It introduces new connection properties for GCP telemetry credentials and project IDs, enabling more flexible telemetry setup. The review feedback identifies critical risks regarding potential NullPointerExceptions when unboxing Boolean flags and suggests a more robust cache key construction to prevent key collisions in the SDK cache.

@keshavdandeva
Copy link
Copy Markdown
Contributor Author

/gemini review

Copy link
Copy Markdown
Contributor

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

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 implements OpenTelemetry auto-configuration for the BigQuery JDBC driver, enabling the use of GCP-specific telemetry credentials and project IDs. It introduces a caching layer for OpenTelemetrySdk instances and a shutdown hook for resource cleanup. Feedback points out that the OTLP exporter configuration lacks proper authentication for GCP and identifies a potential memory leak in connection management. Further suggestions include refining the SDK caching logic to remove redundant keys and ensuring the shutdown hook is exception-safe.

@keshavdandeva keshavdandeva marked this pull request as ready for review May 8, 2026 16:37
@keshavdandeva keshavdandeva requested review from a team as code owners May 8, 2026 16:37
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