feat(jdbc): basic OpenTelemetry tracing integration for BigQuery JDBC Statement#12124
feat(jdbc): basic OpenTelemetry tracing integration for BigQuery JDBC Statement#12124keshavdandeva wants to merge 4 commits intomainfrom
Conversation
Summary of ChangesHello, 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
Using Gemini Code AssistThe 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
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 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
|
There was a problem hiding this comment.
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.
| @@ -0,0 +1,120 @@ | |||
| /* | |||
| * Copyright 2026 Google LLC | |||
| Tracer tracer = getSafeTracer(); | ||
| Span span = tracer.spanBuilder("BigQueryStatement.executeQuery").startSpan(); | ||
| try (Scope scope = span.makeCurrent()) { | ||
| span.setAttribute("db.statement", sql); | ||
| this.otelContext = Context.current(); | ||
| logQueryExecutionStart(sql); | ||
| try { | ||
| QueryJobConfiguration jobConfiguration = | ||
| setDestinationDatasetAndTableInJobConfig(getJobConfig(sql).build()); | ||
| runQuery(sql, jobConfiguration); | ||
| } catch (InterruptedException ex) { | ||
| span.recordException(ex); | ||
| span.setStatus(StatusCode.ERROR, ex.getMessage()); | ||
| throw new BigQueryJdbcException(ex); | ||
| } catch (Exception ex) { | ||
| span.recordException(ex); | ||
| span.setStatus(StatusCode.ERROR, ex.getMessage()); | ||
| throw ex; | ||
| } | ||
|
|
||
| if (!isSingularResultSet()) { | ||
| throw new BigQueryJdbcException( | ||
| "Query returned more than one or didn't return any ResultSet."); | ||
| if (!isSingularResultSet()) { | ||
| BigQueryJdbcException ex = | ||
| new BigQueryJdbcException( | ||
| "Query returned more than one or didn't return any ResultSet."); | ||
| span.recordException(ex); | ||
| span.setStatus(StatusCode.ERROR, ex.getMessage()); | ||
| throw ex; | ||
| } | ||
| // This contains all the other assertions spec required on this method | ||
| return getCurrentResultSet(); | ||
| } finally { | ||
| span.end(); | ||
| } |
There was a problem hiding this comment.
The exception handling and tracing logic here is a bit verbose and inconsistent with the cleaner pattern used in executeBatch. To improve consistency and maintainability, I suggest refactoring this method to use a single outer try-catch block for recording exceptions on the span. This avoids repetitive exception recording and simplifies the code structure.
The same refactoring should be applied to executeLargeUpdate (lines 280-312) and execute (lines 331-359) for consistency across all traced methods.
Tracer tracer = getSafeTracer();
Span span = tracer.spanBuilder("BigQueryStatement.executeQuery").startSpan();
try (Scope scope = span.makeCurrent()) {
span.setAttribute("db.statement", sql);
this.otelContext = Context.current();
logQueryExecutionStart(sql);
try {
QueryJobConfiguration jobConfiguration =
setDestinationDatasetAndTableInJobConfig(getJobConfig(sql).build());
runQuery(sql, jobConfiguration);
} catch (InterruptedException ex) {
throw new BigQueryJdbcException(ex);
}
if (!isSingularResultSet()) {
throw new BigQueryJdbcException(
"Query returned more than one or didn't return any ResultSet.");
}
// This contains all the other assertions spec required on this method
return getCurrentResultSet();
} catch (Exception ex) {
span.recordException(ex);
span.setStatus(StatusCode.ERROR, ex.getMessage());
throw ex;
} finally {
span.end();
}
b/491239772
b/491239773
This PR introduces the foundational
OpenTelemetrytracing for the BigQuery JDBC driver. It intercepts standard JDBC executions (queries, updates, batch) to open spans, capture query text, track latencies, and tag exceptions natively, without breaking existing driver flows.