-
Notifications
You must be signed in to change notification settings - Fork 1.1k
feat(jdbc): basic OpenTelemetry tracing integration for BigQuery JDBC Statement #12124
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
d00ae37
01734d1
b743313
122c14e
9eeed5f
927599a
cb578ac
d9418fc
fc0174f
7b56606
27016c0
c457034
1204b1f
f1c14f0
855ab94
602b916
59706e6
88751ad
f177da6
c0b915a
ec25dcf
44a371b
483e073
cf8b180
494ad7a
aa5e9a0
437f748
adba483
50b9171
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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; | ||
|
|
@@ -138,6 +140,11 @@ public class BigQueryConnection extends BigQueryNoOpsConnection { | |
| Long connectionPoolSize; | ||
| Long listenerPoolSize; | ||
| String partnerToken; | ||
| Boolean enableGcpTraceExporter; | ||
| Boolean enableGcpLogExporter; | ||
| OpenTelemetry customOpenTelemetry; | ||
| Tracer tracer = | ||
| OpenTelemetry.noop().getTracer(BigQueryJdbcOpenTelemetry.INSTRUMENTATION_SCOPE_NAME); | ||
| DatabaseMetaData databaseMetaData; | ||
|
|
||
| BigQueryConnection(String url) throws IOException { | ||
|
|
@@ -243,6 +250,9 @@ public class BigQueryConnection extends BigQueryNoOpsConnection { | |
| this.connectionPoolSize = ds.getConnectionPoolSize(); | ||
| this.listenerPoolSize = ds.getListenerPoolSize(); | ||
| this.partnerToken = ds.getPartnerToken(); | ||
| this.enableGcpTraceExporter = ds.getEnableGcpTraceExporter(); | ||
| this.enableGcpLogExporter = ds.getEnableGcpLogExporter(); | ||
| this.customOpenTelemetry = ds.getCustomOpenTelemetry(); | ||
|
|
||
| this.headerProvider = createHeaderProvider(); | ||
| this.bigQuery = getBigQueryConnection(); | ||
|
|
@@ -939,6 +949,14 @@ private BigQuery getBigQueryConnection() { | |
| bigQueryOptions.setTransportOptions(this.httpTransportOptions); | ||
| } | ||
|
|
||
| OpenTelemetry openTelemetry = | ||
| BigQueryJdbcOpenTelemetry.getOpenTelemetry( | ||
| this.enableGcpTraceExporter, this.enableGcpLogExporter, this.customOpenTelemetry); | ||
| if (this.enableGcpTraceExporter || this.customOpenTelemetry != null) { | ||
|
Neenu1995 marked this conversation as resolved.
|
||
| this.tracer = BigQueryJdbcOpenTelemetry.getTracer(openTelemetry); | ||
|
keshavdandeva marked this conversation as resolved.
|
||
| bigQueryOptions.setOpenTelemetryTracer(this.tracer); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What about the other clients? Do they support OTel?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, the
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is a write client as well.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, I checked the source for |
||
| } | ||
|
|
||
| BigQueryOptions options = bigQueryOptions.setHeaderProvider(this.headerProvider).build(); | ||
| options.setDefaultJobCreationMode( | ||
| this.useStatelessQueryMode | ||
|
|
@@ -987,6 +1005,13 @@ private BigQueryReadClient getBigQueryReadClientConnection() throws IOException | |
|
|
||
| bigQueryReadSettings.setTransportChannelProvider(activeProvider); | ||
|
|
||
| OpenTelemetry openTelemetry = | ||
| BigQueryJdbcOpenTelemetry.getOpenTelemetry( | ||
| this.enableGcpTraceExporter, this.enableGcpLogExporter, this.customOpenTelemetry); | ||
| if (this.enableGcpTraceExporter || this.customOpenTelemetry != null) { | ||
| bigQueryReadSettings.setOpenTelemetryTracerProvider(openTelemetry.getTracerProvider()); | ||
| } | ||
|
|
||
| return BigQueryReadClient.create(bigQueryReadSettings.build()); | ||
| } | ||
|
|
||
|
|
@@ -1087,4 +1112,8 @@ public CallableStatement prepareCall( | |
| } | ||
| return prepareCall(sql); | ||
| } | ||
|
|
||
| public Tracer getTracer() { | ||
| return this.tracer; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| /* | ||
| * Copyright 2026 Google LLC | ||
|
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.OpenTelemetry; | ||
| import io.opentelemetry.api.trace.Tracer; | ||
|
|
||
| public class BigQueryJdbcOpenTelemetry { | ||
|
keshavdandeva marked this conversation as resolved.
|
||
|
|
||
| static final String INSTRUMENTATION_SCOPE_NAME = "com.google.cloud.bigquery.jdbc"; | ||
|
|
||
| private BigQueryJdbcOpenTelemetry() {} | ||
|
|
||
| /** | ||
| * 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 enableGcpTraceExporter, | ||
| boolean enableGcpLogExporter, | ||
| OpenTelemetry customOpenTelemetry) { | ||
| if (customOpenTelemetry != null) { | ||
| return customOpenTelemetry; | ||
| } | ||
|
|
||
| if (enableGcpTraceExporter || enableGcpLogExporter) { | ||
| // TODO(b/491238299): Initialize and return GCP-specific auto-configured SDK | ||
| return OpenTelemetry.noop(); | ||
| } | ||
|
|
||
| return OpenTelemetry.noop(); | ||
| } | ||
|
|
||
| /** Gets a Tracer for the JDBC driver instrumentation scope. */ | ||
| public static Tracer getTracer(OpenTelemetry openTelemetry) { | ||
| return openTelemetry.getTracer(INSTRUMENTATION_SCOPE_NAME); | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.