Skip to content

feat(jdbc): basic OpenTelemetry tracing integration for BigQuery JDBC Statement#12124

Merged
keshavdandeva merged 29 commits intojdbc/feature-branch-otelfrom
jdbc/otel-clean-branch
Apr 23, 2026
Merged

feat(jdbc): basic OpenTelemetry tracing integration for BigQuery JDBC Statement#12124
keshavdandeva merged 29 commits intojdbc/feature-branch-otelfrom
jdbc/otel-clean-branch

Conversation

@keshavdandeva
Copy link
Copy Markdown
Contributor

@keshavdandeva keshavdandeva commented Mar 20, 2026

b/491239772
b/491239773

Changes

  • New connection properties: enableGcpTraceExporter (Boolean, default: false) and enableGcpLogExporter (Boolean, default: false)

  • customOpenTelemetry (Instance): Programmatic injection of a custom SDK (User Application-Managed setup) via BigQueryDataSource.setCustomOpenTelemetry()

  • Added the core initialization logic for OpenTelemetry. During connection setup, it evaluates whether tracing is enabled and constructs an OpenTelemetry Tracer instance. Then, it passes this newly minted tracer strictly downward into the core BigQueryOptions.Builder via .setOpenTelemetryTracer()

  • Intercepted the execution functions (execute, executeQuery, executeLargeUpdate, executeBatch) to spawn child spans wrapping each database call.

@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request establishes the foundational OpenTelemetry tracing capabilities within the BigQuery JDBC driver. It allows for detailed observability of database interactions by automatically creating spans for JDBC query, update, and batch operations, enriching them with query details, execution times, and error information. This integration is designed to be non-disruptive, providing valuable insights into driver performance and behavior without altering existing workflows.

Highlights

  • OpenTelemetry Tracing Integration: Integrated foundational OpenTelemetry tracing into the BigQuery JDBC driver to provide observability for database interactions.
  • JDBC Execution Interception: Implemented interception for standard JDBC executions, including queries, updates, and batch operations, to create and manage OpenTelemetry spans.
  • Span Enrichment: Enhanced OpenTelemetry spans with details such as query text, execution latencies, and exception tagging for comprehensive performance monitoring.
  • Configuration Properties: Introduced new connection properties, EnableOpenTelemetry and OpenTelemetryExporter, allowing users to enable and configure tracing behavior.
  • Dependency Management: Updated Maven dependencies to include OpenTelemetry libraries and configured shading exclusions to prevent conflicts with OpenTelemetry API and Context classes.
  • Dedicated OpenTelemetry Utility: Added a new utility class, BigQueryJdbcOpenTelemetry, to centralize the initialization and management of OpenTelemetry instances and tracers.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

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 introduces foundational OpenTelemetry tracing for the BigQuery JDBC driver's statement execution, which is a valuable addition for observability. The implementation correctly handles context propagation for asynchronous operations like pagination and streaming, and follows standard OpenTelemetry patterns for creating spans and recording exceptions. I have provided a couple of suggestions: one is a minor correction for a copyright year, and the other is a recommendation to unify the exception handling logic within the new tracing code for improved consistency and maintainability. Overall, this is a solid contribution.

@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 PR introduces OpenTelemetry tracing for JDBC statements, which is a great feature for observability. The implementation correctly wraps statement execution methods to create spans, and it handles context propagation to asynchronous tasks. My review includes two main suggestions for improvement: refactoring duplicated tracing logic in BigQueryStatement to improve maintainability, and enhancing exception logging in BigQueryJdbcOpenTelemetry to retain stack traces for better diagnostics. Overall, the changes are well-structured and provide a solid foundation for tracing.

@keshavdandeva keshavdandeva marked this pull request as ready for review March 24, 2026 00:14
@keshavdandeva keshavdandeva requested review from a team as code owners March 24, 2026 00:14
@keshavdandeva keshavdandeva requested a review from logachev March 24, 2026 23:55
@keshavdandeva keshavdandeva marked this pull request as draft March 27, 2026 00:01
@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 integrates OpenTelemetry into the BigQuery JDBC driver to enable tracing for query execution, batch operations, and pagination. It introduces a new connection property, 'enableDefaultTelemetryExporter', and allows users to provide a custom OpenTelemetry instance. A critical compilation error was identified in the 'withTracing' method within BigQueryStatement.java, where a broad Exception is caught and rethrown, violating the method's checked exception signature.

@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 introduces OpenTelemetry tracing to the BigQuery JDBC driver by adding necessary dependencies, a telemetry utility class, and wrapping statement execution and pagination with tracing spans. It also enables telemetry configuration through connection properties and the DataSource class. A critical bug was noted in BigQueryDriver where passing a customOpenTelemetry object via connection properties results in it being incorrectly stringified into the URL, breaking programmatic injection; the reviewer recommends using the DataSource constructor to preserve the object reference.

@keshavdandeva
Copy link
Copy Markdown
Contributor Author

/gemini review

@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 introduces OpenTelemetry tracing to the BigQuery JDBC driver. Key changes include adding OpenTelemetry dependencies to the project, introducing a new connection property enableDefaultTelemetryExporter, and allowing a customOpenTelemetry instance to be passed through connection properties. The implementation wraps core execution methods in BigQueryStatement with tracing logic and ensures that asynchronous background tasks, such as result pagination and stream processing, correctly propagate the telemetry context. I have no feedback to provide as there were no review comments to evaluate.

@keshavdandeva keshavdandeva marked this pull request as ready for review March 27, 2026 03:38
@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 integrates OpenTelemetry into the BigQuery JDBC driver to provide tracing for query execution and asynchronous tasks. It introduces new connection properties for enabling GCP trace and log exporters, allows for a custom OpenTelemetry instance, and wraps key statement execution methods and background threads with tracing spans and context. Feedback was provided to add a private constructor to the BigQueryJdbcOpenTelemetry utility class to follow best practices for utility classes.

@keshavdandeva keshavdandeva requested a review from Neenu1995 April 3, 2026 14:38
@keshavdandeva keshavdandeva changed the base branch from main to jdbc/feature-branch-otel April 16, 2026 13:44
Comment thread java-bigquery/google-cloud-bigquery-jdbc/pom.xml
@keshavdandeva keshavdandeva requested a review from logachev April 22, 2026 13:31
sb.append(query);
}
String combinedQueries = sb.toString();
span.setAttribute("db.statement", combinedQueries);
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.

Should we define a separate attribute for a list of strings instead?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, and I also realised I can store the batch queries as a structured string array attribute (db.batch.statements) instead of a concatenated string.

}
Context.current()
.wrap(
() -> {
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.

At this point, should we move lambdas to functions instead?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it is getting quite messy.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I moved these two to new functions

@Override
public boolean execute(String sql) throws SQLException {
LOG.finest("++enter++");
Tracer tracer = getSafeTracer();
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.

Can probably add a generic method private T traceMethod(String spanName, Runnable<T> ) and pass Impl method as a lambda

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm I am a bit confused because the previous version of PR had that exact pattern (using a withTracing helper that took a lambda), but I refactored it because I interpreted your previous comment:

I'd suggest using executeQueryImpl method for core logic instead of moving it to lambda. So that way public interface method will be tracer-wrapper on top of actual executeQueryImpl

as a preference for avoiding lambdas in these execution methods.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can probably add a generic method private T traceMethod(String spanName, Runnable ) and pass Impl method as a lambda

Done

@logachev logachev changed the title feat(jdbc): basic OpenTelemetry tracing integration for BigQuery JDBC Statement [DO_NOT_MERGE] feat(jdbc): basic OpenTelemetry tracing integration for BigQuery JDBC Statement Apr 23, 2026
this.enableGcpTraceExporter, this.enableGcpLogExporter, this.customOpenTelemetry);
if (this.enableGcpTraceExporter || this.customOpenTelemetry != null) {
this.tracer = BigQueryJdbcOpenTelemetry.getTracer(openTelemetry);
bigQueryOptions.setOpenTelemetryTracer(this.tracer);
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.

What about the other clients? Do they support OTel?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, the BigQueryReadSettings also supports it. I have added it.

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.

There is a write client as well.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I checked the source for BigQueryWriteSettings in the parent project, and unlike the read client settings, it does not expose a setOpenTelemetryTracerProvider(...) method.
Also, I think its not needed, its network calls should be traced as children of our active spans via context propagation, once it is fully implemented

@keshavdandeva keshavdandeva requested a review from logachev April 23, 2026 13:55
Copy link
Copy Markdown
Contributor

@Neenu1995 Neenu1995 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. But add the write client as well if it supports OTel.

@keshavdandeva keshavdandeva changed the title [DO_NOT_MERGE] feat(jdbc): basic OpenTelemetry tracing integration for BigQuery JDBC Statement feat(jdbc): basic OpenTelemetry tracing integration for BigQuery JDBC Statement Apr 23, 2026
@keshavdandeva keshavdandeva merged commit a33f3fe into jdbc/feature-branch-otel Apr 23, 2026
88 checks passed
@keshavdandeva keshavdandeva deleted the jdbc/otel-clean-branch branch April 23, 2026 16:53
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.

3 participants