Skip to content

experiment(secretmanager): Otel tracing prototype in google-cloud-secretmanager - #18086

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

experiment(secretmanager): Otel tracing prototype in google-cloud-secretmanager#18086
chalmerlowe wants to merge 8 commits into
mainfrom
feat/otel-tracing-secretmanager-prototype

Conversation

@chalmerlowe

Copy link
Copy Markdown
Contributor

Problem

Need to demonstrate and verify how generated Google Cloud Python clients should interact with the new custom tracer provider plumbing in google-api-core, specifically for gRPC.

Note

This Pull Request is Prototype Only and is illustrative of what the GAPIC (Google API Client) generator should produce. The changes in google-cloud-secret-manager are intended to inform generator template updates and/or base classes, not necessarily to be merged as handwritten code.

Solution

This Pull Request updates the google-cloud-secret-manager package to demonstrate end-to-end custom tracer provider injection and custom span attributes.

  1. Transport Configuration: Updated SecretManagerServiceClient to pass self._client_options as the configuration parameter when initializing transports.
  2. Transport Updates: Updated gRPC and REST transports to accept and pass through the configuration parameter.
  3. Custom Attributes: Added custom Google Cloud Platform attributes (service, version, repo, artifact) to the generated spans in access_secret_version.
  4. Observability Tests: Added unit tests in test_observability.py to verify that custom spans are created with the correct attributes when tracing is enabled.

Notes to Reviewers

@chalmerlowe chalmerlowe self-assigned this Aug 12, 2026
@chalmerlowe chalmerlowe added the do not merge Indicates a pull request not ready for merge, due to either quality or timing. label Aug 12, 2026
@chalmerlowe

Copy link
Copy Markdown
Contributor Author

DO NOT MERGE label added because this is an experiment to help define what changes should go into the GAPIC generator.

@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 in google-api-core and google-cloud-secret-manager by adding a tracer_provider option to ClientOptions and intercepting gRPC channels when tracing is enabled. The review feedback suggests defining configuration as an explicit parameter in the create_channel signatures instead of popping it from kwargs, addressing the unused configuration parameter in the REST transport, and adding test coverage to verify custom tracer provider injection rather than relying solely on the global provider.

Comment on lines +305 to +312
# NOTE: 'configuration' is popped to prevent a TypeError.
# Generated async transports (like those in secretmanager) pass 'configuration'
# down to this helper via **kwargs to support tracing in sync transports.
# However, 'aio.secure_channel' does not recognize this parameter and will
# crash if it is passed through.
# Async gRPC tracing is deferred to a future phase/PR, so we simply discard
# this parameter for now to ensure generated async code doesn't fail at runtime.
kwargs.pop("configuration", 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

Instead of manually popping configuration from kwargs inside the function body, consider adding configuration: Optional[object] = None as an explicit parameter to the create_channel function signature. Since named parameters are not captured in **kwargs, this will automatically prevent configuration from being passed down to aio.secure_channel, eliminating the need for this manual pop and the associated comment while improving type safety and discoverability.

target = _modify_target_for_direct_path(target)

return grpc.secure_channel(
configuration = kwargs.pop("configuration", 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

Instead of popping configuration from kwargs here, consider adding configuration: Optional[object] = None as an explicit parameter to the create_channel function signature. This makes the parameter explicit, improves discoverability, and allows static analysis tools to type-check it properly.

url_scheme: str = "https",
interceptor: Optional[SecretManagerServiceRestInterceptor] = None,
api_audience: Optional[str] = None,
configuration=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

The configuration parameter is accepted in __init__ but is never stored (e.g., self._configuration = configuration) or used within the REST transport. If tracing is to be supported or if this parameter is intended for future use, it should be stored or passed to the base class/helpers. Otherwise, it is currently a dead parameter.

Comment on lines +54 to +62
def test_access_secret_version_custom_span(setup_otel, monkeypatch):
"""Verify that calling access_secret_version produces a custom T3 span with attributes."""

# Enable tracing via env var (assuming this is how we gate it for clients too)
monkeypatch.setenv("GOOGLE_CLOUD_PYTHON_TRACING_ENABLED", "true")

client = secretmanager_v1.SecretManagerServiceClient(
credentials=ga_credentials.AnonymousCredentials(),
)

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

The observability tests currently only verify tracing using the global tracer provider (via the setup_otel fixture). Since the primary goal of this PR is to support custom tracer provider injection via ClientOptions, it would be highly beneficial to add a test case that explicitly passes a custom tracer_provider to the client's client_options and asserts that spans are recorded on that custom provider. This also avoids having to mock or override the private trace._TRACER_PROVIDER global variable.

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.

1 participant