Skip to content

Commit dcc2a68

Browse files
fix(bigquery): prevent NullPointerException in OTel tracing when JobId is null (#13301)
b/517929704 This PR addresses a `NullPointerException` that occurs in the BigQuery client library when OpenTelemetry tracing is enabled and operations are performed on jobs that do not have a client-assigned `JobId` at the start of the call. A notable case where this happens is during dry-run queries (often used to determine statement type or fetch statistics) where `JobInfo.getJobId()` returns null. The OTel instrumentation was attempting to extract attributes from the `JobId` without checking for nullability. **Changes:** * Added null checks before calling `JobId.getOtelAttributes()` in `BigQueryImpl.create(JobInfo)` (line 455). * Added null checks before calling `JobId.getOtelAttributes()` in `BigQueryImpl.getQueryResults(JobId)` (line 2128). * These changes align with the safe-check pattern already implemented in `BigQueryImpl.queryWithTimeout` (line 2075).
1 parent 6710ae0 commit dcc2a68

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

  • java-bigquery/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery

java-bigquery/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigQueryImpl.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,10 @@ && getOptions().getOpenTelemetryTracer() != null) {
452452
getOptions()
453453
.getOpenTelemetryTracer()
454454
.spanBuilder("com.google.cloud.bigquery.BigQuery.createJob")
455-
.setAllAttributes(jobInfo.getJobId().getOtelAttributes())
455+
.setAllAttributes(
456+
jobInfo.getJobId() != null
457+
? jobInfo.getJobId().getOtelAttributes()
458+
: Attributes.empty())
456459
.setAllAttributes(otelAttributesFromOptions(options))
457460
.startSpan();
458461
}
@@ -2072,7 +2075,7 @@ && getOptions().getOpenTelemetryTracer() != null) {
20722075
getOptions()
20732076
.getOpenTelemetryTracer()
20742077
.spanBuilder("com.google.cloud.bigquery.BigQuery.queryWithTimeout")
2075-
.setAllAttributes(jobId != null ? jobId.getOtelAttributes() : null)
2078+
.setAllAttributes(jobId != null ? jobId.getOtelAttributes() : Attributes.empty())
20762079
.setAllAttributes(otelAttributesFromOptions(options))
20772080
.startSpan();
20782081
}
@@ -2125,7 +2128,7 @@ && getOptions().getOpenTelemetryTracer() != null) {
21252128
getOptions()
21262129
.getOpenTelemetryTracer()
21272130
.spanBuilder("com.google.cloud.bigquery.BigQuery.getQueryResults")
2128-
.setAllAttributes(jobId.getOtelAttributes())
2131+
.setAllAttributes(jobId != null ? jobId.getOtelAttributes() : Attributes.empty())
21292132
.setAllAttributes(otelAttributesFromOptions(options))
21302133
.startSpan();
21312134
}

0 commit comments

Comments
 (0)