Skip to content

feat(observability): implement universal 4-path OpenTelemetry tracing - #18433

Merged
chalmerlowe merged 3 commits into
mainfrom
feat/otel-tracing-universal-4path
Oct 7, 2026
Merged

chalmerlowe merged 3 commits into
mainfrom
feat/otel-tracing-universal-4path

Conversation

@chalmerlowe

Copy link
Copy Markdown
Contributor

feat(observability): implement universal 4-path OpenTelemetry tracing

Problems Solved

Google Cloud Python client libraries support four communication paths: synchronous gRPC, asynchronous gRPC, synchronous REST (HTTP), and asynchronous REST (HTTP). Previously, distributed OpenTelemetry tracing was only wired for synchronous gRPC calls, leaving asynchronous and HTTP communications untraced. Additionally, earlier drafts of asynchronous tracing attempted to modify gRPC channels after creation, which violated the immutability rules of the underlying Python gRPC library, and did not consistently forward client options across all transport classes.

Solutions

This pull request provides a unified, cross-transport tracing implementation:

  1. Universal 4-Transport Support:

    • Synchronous gRPC (GrpcTransport): Continues using OpenTelemetry gRPC channel interceptors.
    • Asynchronous gRPC (GrpcAsyncIOTransport): Supplies OpenTelemetry interceptors directly during channel creation, respecting the immutable design of asynchronous gRPC channels.
    • Synchronous REST (RestTransport): Adds wire span tracking around HTTP requests with automatic W3C trace context header injection (traceparent).
    • Asynchronous REST (AsyncRestTransport): Integrates HTTP wire span tracking and async context lifecycle handling with W3C header propagation.
  2. Refined Transport Contracts & Cleanup:

    • Replaced per-instance signature inspection with module-level constants to eliminate overhead during method invocation.
    • Configured BaseTransport.kind to safely return an empty string by default instead of raising an exception.
    • Updated REST and base transport initializers to accept and store client options, ensuring options are forwarded uniformly across all transport classes.
    • Resolved an issue in asynchronous method wrappers where caller-specified compression settings were not correctly evaluated.
    • Added task cancellation handling (asyncio.CancelledError) so spans are closed accurately when asynchronous tasks are cancelled.

Notes for Reviewers

  • This pull request targets template definitions in packages/gapic-generator and core helper functions in packages/google-api-core.
  • Per team coordination, generated client library code and integration goldens are not included in this change and will be updated in a follow-up step.
  • All additions maintain backward compatibility and preserve zero overhead when tracing is disabled.

Loading
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.

3 participants