Skip to content

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

Open
chalmerlowe wants to merge 11 commits into
mainfrom
feat/otel-prototype
Open

feat: Add OpenTelemetry environment variable and options configuration helpers.#17524
chalmerlowe wants to merge 11 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
@chalmerlowe chalmerlowe force-pushed the feat/otel-prototype branch from 53085c1 to 9aa54fb Compare July 6, 2026 12:18
@chalmerlowe chalmerlowe marked this pull request as ready for review July 6, 2026 18:24
@chalmerlowe chalmerlowe requested a review from a team as a code owner July 6, 2026 18:24
@chalmerlowe chalmerlowe added the do not merge Indicates a pull request not ready for merge, due to either quality or timing. label Jul 6, 2026
@chalmerlowe

Copy link
Copy Markdown
Contributor Author

While it is likely that this PR is complete, we want to wait until the design doc (being handled internally) is complete and approved before merging.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

do not merge Indicates a pull request not ready for merge, due to either quality or timing.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants