Skip to content

Experiment(secret-manager): add tracing transport logic to google-cloud-secret-manager - #18188

Draft
chalmerlowe wants to merge 2 commits into
feat/otel-tracing-api-core-logicfrom
feat/otel-tracing-transport-logic
Draft

Experiment(secret-manager): add tracing transport logic to google-cloud-secret-manager#18188
chalmerlowe wants to merge 2 commits into
feat/otel-tracing-api-core-logicfrom
feat/otel-tracing-transport-logic

Conversation

@chalmerlowe

Copy link
Copy Markdown
Contributor

Problem

Client libraries currently lack built-in support for OpenTelemetry tracing interceptors. We need a flexible, explicit mechanism to inject these interceptors into the transport pipeline without tying the core low-level helpers too tightly to specific observability features.

Solution

This PR implements explicit interceptor injection in the SecretManagerServiceClient and its gRPC transport.

  • Updated SecretManagerServiceClient to resolve OpenTelemetry interceptors using google-api-core helpers and explicitly pass them to the transport.
  • Updated SecretManagerServiceGrpcTransport to accept an interceptors list and explicitly apply them to the gRPC channel using grpc.intercept_channel.
  • Added unit tests (test_secret_manager_service_client_otel_interceptor_injection and *_disabled variant) to verify that interceptors are correctly injected and applied.

Notes to Reviewers

  • Async Deferred: As per the design plan, Async gRPC updates are deferred to a separate PR to keep this implementation small and clean.
  • Stacked PRs: This work builds on the foundational helpers introduced in the google-api-core PR (Phase 1).
  • Explicit Injection: This demonstrates an "active orchestrator" role of the generated client, delegating resolution to core helpers but explicitly controlling the pipeline.

Fixes #18139 (partially, this is Phase 2 of the larger effort)

@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 (OTel) tracing support by adding a helper module _otel_helpers.py to resolve and instantiate OTel gRPC interceptors, extending ClientOptions to accept a tracer_provider, and updating the Secret Manager gRPC transport to inject these interceptors. The review feedback highlights Python compatibility issues in _otel_helpers.py due to the use of the | union operator, which is unsupported in older Python versions, and suggests using typing.Union instead. Additionally, it recommends adding a defensive None check for client_options to avoid calling getattr on a None object.

Comment thread packages/google-api-core/google/api_core/_otel_helpers.py
Comment thread packages/google-api-core/google/api_core/_otel_helpers.py
Comment on lines +53 to +56
if isinstance(client_options, dict):
tracer_provider = client_options.get("tracer_provider")
else:
tracer_provider = getattr(client_options, "tracer_provider", None)

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.

medium

When processing optional parameters with a helper function, prefer placing the null or None check within the function body rather than at the call site to simplify the calling code and improve encapsulation. This also avoids confusing or non-idiomatic getattr(None, ...) calls.

Suggested change
if isinstance(client_options, dict):
tracer_provider = client_options.get("tracer_provider")
else:
tracer_provider = getattr(client_options, "tracer_provider", None)
if isinstance(client_options, dict):
tracer_provider = client_options.get("tracer_provider")
elif client_options is not None:
tracer_provider = getattr(client_options, "tracer_provider", None)
else:
tracer_provider = None
References
  1. When processing optional parameters with a helper function, prefer placing the null or None check within the function body rather than at the call site to simplify the calling code and improve encapsulation.

@chalmerlowe
chalmerlowe force-pushed the feat/otel-tracing-transport-logic branch from 916213b to d1a7a0f Compare August 21, 2026 14:16
@chalmerlowe
chalmerlowe changed the base branch from main to feat/otel-tracing-api-core-logic August 21, 2026 14:18
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