Skip to content

fix(bigquery-jdbc): feature branch failing tests#13287

Open
keshavdandeva wants to merge 3 commits into
jdbc/feature-branch-otelfrom
jdbc/fix-otel-feature-branch
Open

fix(bigquery-jdbc): feature branch failing tests#13287
keshavdandeva wants to merge 3 commits into
jdbc/feature-branch-otelfrom
jdbc/fix-otel-feature-branch

Conversation

@keshavdandeva
Copy link
Copy Markdown
Contributor

@keshavdandeva keshavdandeva commented May 28, 2026

b/517498094

This PR fixes dependency analysis failures and flaky test issues identified in the OpenTelemetry integration feature branch.

@keshavdandeva keshavdandeva changed the base branch from main to jdbc/feature-branch-otel May 28, 2026 17:10
@keshavdandeva keshavdandeva changed the title Jdbc/fix otel feature branch fix(bigquery-jdbc): feature branch failing tests May 28, 2026
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 integrates OpenTelemetry tracing and logging into the BigQuery JDBC driver, adding a custom JUL logging handler (OpenTelemetryJulHandler) and updating core connection, statement, and metadata classes to support tracing and context propagation. The review feedback identifies a performance risk from synchronous blocking network calls inside the logging handler's publish method, recommending offloading to a bounded thread pool. Additionally, it highlights a thread-safety issue in ensureGlobalHandlerAttached that could lead to duplicate handlers, suggesting the use of an explicit lock to secure concurrent initialization.

I am having trouble creating individual review comments. Click here to see my feedback.

java-bigquery-jdbc/src/main/java/com/google/cloud/bigquery/jdbc/OpenTelemetryJulHandler.java (110)

high

Calling loggingClient.write synchronously inside the publish method of a logging Handler introduces a blocking network call on the application's critical path. This can severely degrade performance, especially when logging is verbose (e.g., at FINE or INFO levels). Consider offloading the log writing to a background bounded thread pool (e.g., ThreadPoolExecutor with a defined maximum size) or queue, or configuring the Logging client with asynchronous batching options.

References
  1. For safety, use a bounded thread pool (e.g., ThreadPoolExecutor with a defined maximum size) instead of an unbounded one (e.g., Executors.newCachedThreadPool()), even if the current logic seems to limit concurrent tasks.

java-bigquery-jdbc/src/main/java/com/google/cloud/bigquery/jdbc/BigQueryJdbcOpenTelemetry.java (143-155)

medium

The ensureGlobalHandlerAttached method is not thread-safe. If multiple connections are initialized concurrently, multiple threads might check logger.getHandlers() simultaneously, find no handler, and both add a new OpenTelemetryJulHandler. This would result in duplicate handlers and duplicate log exports. To protect this shared state while ensuring thread safety and visibility in performance-sensitive code, prefer using an explicit lock over the synchronized keyword.

  private static final java.util.concurrent.locks.ReentrantLock lock = new java.util.concurrent.locks.ReentrantLock();

  public static void ensureGlobalHandlerAttached() {
    lock.lock();
    try {
      Logger logger = Logger.getLogger(BIGQUERY_NAMESPACE);
      boolean present = false;
      for (Handler h : logger.getHandlers()) {
        if (h instanceof OpenTelemetryJulHandler) {
          present = true;
          break;
        }
      }
      if (!present) {
        logger.addHandler(new OpenTelemetryJulHandler());
      }
    } finally {
      lock.unlock();
    }
  }
References
  1. In performance-sensitive code, prefer using explicit locks over the 'synchronized' keyword to protect shared state while ensuring thread safety and visibility.

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