googleapis / googleapis/google-cloud-python

BigQuery: provide a public API to opt out of built-in OpenTelemetry tracing

Abierto
#16,847 1 comentario 0 reacciones 1 asignado Reclamado por @daniel-sanche Ver en GitHub
Lenguaje dominante
Python
Estrellas
5.4k
Forks
1.8k
Merge medio
3 d 4 h
PR fusionados (30 d)
122

Descripción

### Determine this is the right repository

- [x] I determined this is the correct repository in which to report this feature request.

### Summary of the feature request

When `opentelemetry-api` is installed and a global tracer provider is configured, `google-cloud-bigquery` automatically wraps every BQ call in a span (`BigQuery.job.begin`, `BigQuery.getQueryResults`, etc.) via `opentelemetry_tracing.create_span`. There is no documented way to opt out, so projects that want OTel for their own code but not for BQ end up with their traces drowned in BQ spans.

### Desired code experience

Any of the following would be a supported, public way to disable the library's built-in tracing:

```python
# Option A — env var
# GOOGLE_CLOUD_BIGQUERY_DISABLE_TRACING=1

# Option B — constructor argument
from google.cloud import bigquery
client = bigquery.Client(enable_tracing=False)

# Option C — honor the OTel SDK's standard opt-out
# OTEL_PYTHON_DISABLED_INSTRUMENTATIONS=google-cloud-bigquery
```

Happy to send a PR if there is a preferred approach.

### Expected results

With any of the above set, BQ client calls should not emit spans, even though `opentelemetry-api` is installed and a tracer provider is configured for the rest of the application.

### API client name and version

google-cloud-bigquery v3.38.0

### Use case

We use Logfire (OpenTelemetry-based) to trace AI-agent runs and outbound HTTP. Once the tracer provider is configured, every BQ call also emits a span, which drowns out the agent traces we actually care about. We want OTel for our own code, but not for BQ.

### Additional context

The only working workaround today is mutating the module-level `HAS_OPENTELEMETRY` flag before any BQ call:

```python
import google.cloud.bigquery.opentelemetry_tracing as _bq_otel
_bq_otel.HAS_OPENTELEMETRY = False
```

This works because `create_span` reads the global at call time and `client.py` only imports `create_span`, not the flag itself. But it relies on a non-public attribute and could silently regress on any internal refactor. Uninstalling `opentelemetry-api` is not viable when the rest of the application depends on it.

Source reference: `packages/google-cloud-bigquery/google/cloud/bigquery/opentelemetry_tracing.py` — the `HAS_OPENTELEMETRY` flag and `create_span` function.

Guía de contribución

Abrir la guía de contribución

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.