Skip to content

feat: Add OpenTelemetry environment variable and options configuration helpers.#17524

Draft
chalmerlowe wants to merge 8 commits into
mainfrom
feat/otel-prototype
Draft

feat: Add OpenTelemetry environment variable and options configuration helpers.#17524
chalmerlowe wants to merge 8 commits into
mainfrom
feat/otel-prototype

Conversation

@chalmerlowe

@chalmerlowe chalmerlowe commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

This PR introduces a foundational configuration layer for integrating OpenTelemetry (OTel) observability into Google Cloud Python client libraries. It establishes the google.api_core.observability module, which is responsible for resolving telemetry configuration settings in a standardized, hierarchical manner (and ultimately enabling traces, metrics, and logs).

Intent & Motivation

To provide a consistent observability experience across all Google Cloud Python clients, we are standardizing how telemetry signals (traces, metrics, logs) are enabled or disabled. This module parses and resolves configuration from multiple sources, falling back gracefully, so that users can control telemetry globally or on a per-service basis.

Changes Included

  • Configuration Resolution Logic: Added the is_signal_enabled function in the new observability package to resolve telemetry enablement settings based on a precedence hierarchy:

Resolves settings in the following order of precedence:
1. Programmatic overrides in client_options (checks tracer_provider)
2. Language-wide Environment Variable: GOOGLE_CLOUD_PYTHON_TRACING_ENABLED
(natively checks for an EXPERIMENTAL prefix variant first)
3. Default fallback

  • Experimental Fallbacks: Implemented fallback logic that automatically checks for EXPERIMENTAL prefixes within the environment variable definitions to support early-stage adoption and rollout phases safely.

  • Test Coverage: Provided test coverage using pytest for precedence rules and environmental scenarios.

@gemini-code-assist gemini-code-assist Bot left a comment

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.

Code Review

This pull request introduces observability environment variable and client options resolution helpers under a new observability module, including the is_signal_enabled function and corresponding unit tests. Feedback is provided to improve the resolution of client options by avoiding direct __dict__ access (which fails for classes using __slots__ or properties) in favor of getattr, and replacing rstrip('s') with a safer suffix removal method to prevent unintended character stripping.

Comment thread packages/google-api-core/google/api_core/observability/options.py
Comment thread packages/google-api-core/google/api_core/observability/options.py Outdated
The assert statement was incorrectly indented inside the pytest.raises context manager, causing it to never execute. Dedented the assert to ensure exception messages are actually verified, which also resolves coverage gaps.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants