Skip to content
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
d00ae37
build: add OpenTelemetry shaded and unshaded dependencies to pom.xml
keshavdandeva Mar 20, 2026
01734d1
feat: add openTelemetry connection properties
keshavdandeva Mar 20, 2026
b743313
feat: add basic OpenTelemetry tracing hooks to BigQuery JDBC statements
keshavdandeva Mar 20, 2026
122c14e
lint: fix lint
keshavdandeva Mar 20, 2026
9eeed5f
chore: refactor spans
keshavdandeva Mar 23, 2026
927599a
chore: fix dependencies
keshavdandeva Mar 23, 2026
cb578ac
fix: remove versions from dependencies
keshavdandeva Mar 23, 2026
d9418fc
refactor: create functional interface `withTracing`
keshavdandeva Mar 24, 2026
fc0174f
Merge branch 'main' into jdbc/otel-clean-branch
keshavdandeva Mar 24, 2026
7b56606
refactor: remove exporter dep and logic
keshavdandeva Mar 24, 2026
27016c0
fix: lint
keshavdandeva Mar 24, 2026
c457034
refactor: rename connection property `EnableOpenTelemetry` and remove…
keshavdandeva Mar 27, 2026
1204b1f
chore: add Span Links for asynchronous pagination
keshavdandeva Mar 27, 2026
f1c14f0
fix: exception check for methods
keshavdandeva Mar 27, 2026
855ab94
fix: `customOpenTelemetry` injection in properties
keshavdandeva Mar 27, 2026
602b916
refactor: use `INSTRUMENTATION_SCOPE_NAME` contant
keshavdandeva Mar 27, 2026
59706e6
refactor: use `Context.current().wrap()` instead of Span Links
keshavdandeva Mar 27, 2026
88751ad
chore: remove unused code
keshavdandeva Mar 27, 2026
f177da6
fix: `getSafeTracer()`
keshavdandeva Mar 27, 2026
c0b915a
fix: NPE
keshavdandeva Mar 31, 2026
ec25dcf
Merge branch 'main' into jdbc/otel-clean-branch
keshavdandeva Mar 31, 2026
44a371b
chore: remove `enableDefaultTelemetryExporter` and introduce `enableG…
keshavdandeva Apr 3, 2026
483e073
Merge branch 'main' into jdbc/otel-clean-branch
keshavdandeva Apr 3, 2026
cf8b180
add private constructor for `BigQueryJdbcOpenTelemetry`
keshavdandeva Apr 3, 2026
494ad7a
add unit tests
keshavdandeva Apr 3, 2026
aa5e9a0
Merge branch 'main' into jdbc/otel-clean-branch
keshavdandeva Apr 16, 2026
437f748
chore: address pr feedback
keshavdandeva Apr 22, 2026
adba483
chore: refactor based on pr review
keshavdandeva Apr 23, 2026
50b9171
chore: add passing tracer to Storage Read client
keshavdandeva Apr 23, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions java-bigquery/google-cloud-bigquery-jdbc/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,10 @@
<relocation>
<pattern>io</pattern>
<shadedPattern>com.google.bqjdbc.shaded.io</shadedPattern>
<excludes>
<exclude>io.opentelemetry.api.*</exclude>
Comment thread
keshavdandeva marked this conversation as resolved.
<exclude>io.opentelemetry.context.*</exclude>
</excludes>
</relocation>
</relocations>
<filters>
Expand Down Expand Up @@ -277,6 +281,16 @@
<artifactId>httpcore5</artifactId>
</dependency>

<!-- OpenTelemetry APIs (unshaded) -->
<dependency>
<groupId>io.opentelemetry</groupId>
<artifactId>opentelemetry-api</artifactId>
</dependency>
<dependency>
<groupId>io.opentelemetry</groupId>
<artifactId>opentelemetry-context</artifactId>
</dependency>

<!-- Test Dependencies -->
<dependency>
<groupId>com.google.truth</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@
import com.google.cloud.bigquery.storage.v1.BigQueryWriteClient;
import com.google.cloud.bigquery.storage.v1.BigQueryWriteSettings;
import com.google.cloud.http.HttpTransportOptions;
import io.opentelemetry.api.OpenTelemetry;
import io.opentelemetry.api.trace.Tracer;
import java.io.IOException;
import java.io.InputStream;
import java.sql.CallableStatement;
Expand Down Expand Up @@ -138,6 +140,10 @@ public class BigQueryConnection extends BigQueryNoOpsConnection {
Long connectionPoolSize;
Long listenerPoolSize;
String partnerToken;
boolean enableDefaultTelemetryExporter;
OpenTelemetry customOpenTelemetry;
Tracer tracer =
OpenTelemetry.noop().getTracer(BigQueryJdbcOpenTelemetry.INSTRUMENTATION_SCOPE_NAME);

BigQueryConnection(String url) throws IOException {
this(url, DataSource.fromUrl(url));
Expand Down Expand Up @@ -242,6 +248,8 @@ public class BigQueryConnection extends BigQueryNoOpsConnection {
this.connectionPoolSize = ds.getConnectionPoolSize();
this.listenerPoolSize = ds.getListenerPoolSize();
this.partnerToken = ds.getPartnerToken();
this.enableDefaultTelemetryExporter = ds.getEnableDefaultTelemetryExporter();
this.customOpenTelemetry = ds.getCustomOpenTelemetry();

this.headerProvider = createHeaderProvider();
this.bigQuery = getBigQueryConnection();
Expand Down Expand Up @@ -935,6 +943,14 @@ private BigQuery getBigQueryConnection() {
bigQueryOptions.setTransportOptions(this.httpTransportOptions);
}

OpenTelemetry openTelemetry =
BigQueryJdbcOpenTelemetry.getOpenTelemetry(
this.enableDefaultTelemetryExporter, this.customOpenTelemetry);
if (this.enableDefaultTelemetryExporter || this.customOpenTelemetry != null) {
this.tracer = BigQueryJdbcOpenTelemetry.getTracer(openTelemetry);
Comment thread
keshavdandeva marked this conversation as resolved.
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

}

BigQueryOptions options = bigQueryOptions.setHeaderProvider(this.headerProvider).build();
options.setDefaultJobCreationMode(
this.useStatelessQueryMode
Expand Down Expand Up @@ -1083,4 +1099,8 @@ public CallableStatement prepareCall(
}
return prepareCall(sql);
}

public Tracer getTracer() {
return this.tracer;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.google.cloud.bigquery.exception.BigQueryJdbcRuntimeException;
import io.grpc.LoadBalancerRegistry;
import io.grpc.internal.PickFirstLoadBalancerProvider;
import io.opentelemetry.api.OpenTelemetry;
import java.io.IOException;
import java.sql.Connection;
import java.sql.Driver;
Expand Down Expand Up @@ -121,16 +122,22 @@ public Connection connect(String url, Properties info) throws SQLException {
LOG.finest("++enter++");
try {
if (acceptsURL(url)) {
// strip 'jdbc:' from the URL, add any extra properties
Properties connectInfo = info == null ? new Properties() : (Properties) info.clone();
Object customOpenTelemetryObj = connectInfo.remove("customOpenTelemetry");

String connectionUri =
BigQueryJdbcUrlUtility.appendPropertiesToURL(url.substring(5), this.toString(), info);
BigQueryJdbcUrlUtility.appendPropertiesToURL(
url.substring(5), this.toString(), connectInfo);
Comment thread
keshavdandeva marked this conversation as resolved.
try {
BigQueryJdbcUrlUtility.parseUrl(connectionUri);
} catch (BigQueryJdbcRuntimeException e) {
throw new BigQueryJdbcException(e.getMessage(), e);
}

DataSource ds = DataSource.fromUrl(connectionUri);
if (customOpenTelemetryObj instanceof OpenTelemetry) {
ds.setCustomOpenTelemetry((OpenTelemetry) customOpenTelemetryObj);
}

// LogLevel
String logLevelStr = ds.getLogLevel();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* Copyright 2026 Google LLC
Comment thread
keshavdandeva marked this conversation as resolved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.google.cloud.bigquery.jdbc;

import io.opentelemetry.api.GlobalOpenTelemetry;
import io.opentelemetry.api.OpenTelemetry;
import io.opentelemetry.api.trace.Tracer;

public class BigQueryJdbcOpenTelemetry {
Comment thread
keshavdandeva marked this conversation as resolved.

static final String INSTRUMENTATION_SCOPE_NAME = "com.google.cloud.bigquery.jdbc";

/**
* Initializes or returns the OpenTelemetry instance based on hybrid logic. Prefer
* customOpenTelemetry if provided; fallback to an auto-configured GCP exporter if requested.
*/
public static OpenTelemetry getOpenTelemetry(
boolean enableDefaultTelemetryExporter, OpenTelemetry customOpenTelemetry) {
if (customOpenTelemetry != null) {
return customOpenTelemetry;
}

if (enableDefaultTelemetryExporter) {
// TODO(b/491245568): Initialize and return GCP-specific auto-configured SDK
return GlobalOpenTelemetry.get();
}

return OpenTelemetry.noop();
}

/** Gets a Tracer for the JDBC driver instrumentation scope. */
public static Tracer getTracer(OpenTelemetry openTelemetry) {
return openTelemetry.getTracer(INSTRUMENTATION_SCOPE_NAME);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,9 @@ protected boolean removeEldestEntry(Map.Entry<String, Map<String, String>> eldes
static final int DEFAULT_SWA_APPEND_ROW_COUNT_VALUE = 1000;
static final String SWA_ACTIVATION_ROW_COUNT_PROPERTY_NAME = "SWA_ActivationRowCount";
static final int DEFAULT_SWA_ACTIVATION_ROW_COUNT_VALUE = 3;
static final String ENABLE_DEFAULT_TELEMETRY_EXPORTER_PROPERTY_NAME =
"enableDefaultTelemetryExporter";
static final boolean DEFAULT_ENABLE_DEFAULT_TELEMETRY_EXPORTER_VALUE = false;
private static final BigQueryJdbcCustomLogger LOG =
new BigQueryJdbcCustomLogger(BigQueryJdbcUrlUtility.class.getName());
static final String FILTER_TABLES_ON_DEFAULT_DATASET_PROPERTY_NAME =
Expand Down Expand Up @@ -607,6 +610,13 @@ protected boolean removeEldestEntry(Map.Entry<String, Map<String, String>> eldes
.setDescription(
"Reason for the request, which is passed as the x-goog-request-reason"
+ " header.")
.build(),
BigQueryConnectionProperty.newBuilder()
.setName(ENABLE_DEFAULT_TELEMETRY_EXPORTER_PROPERTY_NAME)
.setDescription(
"Enables or disables default OpenTelemetry exporters in the Driver. Disabled by default.")
.setDefaultValue(
String.valueOf(DEFAULT_ENABLE_DEFAULT_TELEMETRY_EXPORTER_VALUE))
.build())));

private static final List<String> NETWORK_PROPERTIES =
Expand Down
Loading
Loading