Skip to content

Commit ab89d12

Browse files
google-genai-botcopybara-github
authored andcommitted
refactor(plugins)!: use OpenTelemetry for BigQuery plugin tracing
This refactors the BigQueryAgentAnalyticsPlugin to use the standard OpenTelemetry API for trace and span ID generation and propagation, replacing the custom ContextVar implementation. Key changes: - Utilizes `opentelemetry.trace` for starting/ending spans. - Correctly uses `opentelemetry.context` for context attachment and detachment. - Span information is now derived from the OpenTelemetry context when available. - Added a fallback mechanism to ensure span_id and parent_span_id are still populated if the OpenTelemetry SDK is not initialized. To get standard OpenTelemetry trace information in BigQuery logs, users should install `opentelemetry-sdk` and initialize a global `TracerProvider` in their application *before* initializing ADK components. Example minimal initialization: ```python # Install: pip install opentelemetry-sdk from opentelemetry import trace from opentelemetry.sdk.trace import TracerProvider trace.set_tracer_provider(TracerProvider()) ``` PiperOrigin-RevId: 858965562
1 parent 645bd0e commit ab89d12

2 files changed

Lines changed: 383 additions & 117 deletions

File tree

0 commit comments

Comments
 (0)