Skip to content

feat(api-core): Opentelemetry tracing support for gRPC transports in google-api-core - #18069

Draft
chalmerlowe wants to merge 9 commits into
mainfrom
feat/otel-tracing-core-infra
Draft

feat(api-core): Opentelemetry tracing support for gRPC transports in google-api-core#18069
chalmerlowe wants to merge 9 commits into
mainfrom
feat/otel-tracing-core-infra

Conversation

@chalmerlowe

Copy link
Copy Markdown
Contributor

Problem

Currently, users of Google Cloud Python client libraries cannot specify a custom OpenTelemetry Tracer Provider for gRPC transports.

Solution

This Pull Request introduces the foundational plumbing in google-api-core to support custom tracer providers for gRPC transports.

  1. Client Options: Added tracer_provider as a recognized parameter in ClientOptions.
  2. gRPC Helper Plumbing: Updated grpc_helpers.create_channel to extract the tracer_provider from the configuration (supporting both dictionary and object formats) and pass it to the OpenTelemetry gRPC client interceptor.
  3. Async Safety: Updated grpc_helpers_async.create_channel to safely discard the configuration parameter. This prevents TypeError when generated async code passes it down, ensuring generated code does not fail even though async tracing is deferred to a future phase of this project.

Notes to Reviewers

  • Fail Open: The OpenTelemetry import in grpc_helpers.py continues to fail open. If the opentelemetry-instrumentation-grpc package is not installed, tracing is skipped quietly without failing the transport creation.
  • Async Deferral: Async gRPC tracing is NOT implemented in this Pull Request. The changes in grpc_helpers_async.py are strictly defensive to prevent runtime errors when generated code tries to pass configuration down.

@chalmerlowe chalmerlowe self-assigned this Aug 11, 2026
@chalmerlowe chalmerlowe changed the title feat(api-core): Opentelemetry tracing for gRPC transports feat(api-core): Opentelemetry tracing support for gRPC transports in google-api-core Aug 11, 2026

@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 OpenTelemetry tracing support for gRPC channels. It adds a tracer_provider option to ClientOptions, integrates the OpenTelemetry gRPC client interceptor in grpc_helpers.create_channel when tracing is enabled, and discards the configuration parameter in the async helper to prevent runtime errors. The reviewer identified a critical bug where the code incorrectly attempts to call intercept_channel from the opentelemetry.instrumentation.grpc module instead of the standard grpc module, which would cause a runtime crash. Actionable suggestions and corresponding test updates were provided to resolve this issue.

Comment thread packages/google-api-core/google/api_core/grpc_helpers.py Outdated
Comment thread packages/google-api-core/tests/unit/test_grpc_helpers_otel.py Outdated
Comment thread packages/google-api-core/tests/unit/test_grpc_helpers_otel.py Outdated
Comment thread packages/google-api-core/tests/unit/test_grpc_helpers_otel.py
Comment thread packages/google-api-core/google/api_core/grpc_helpers_async.py Outdated
Comment thread packages/google-api-core/google/api_core/grpc_helpers_async.py Outdated
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.

1 participant