Skip to content

feat(secretmanager): add OpenTelemetry distributed tracing samples - #14647

Open
chalmerlowe wants to merge 7 commits into
mainfrom
feat/secretmanager-otel-tracing
Open

chalmerlowe wants to merge 7 commits into
mainfrom
feat/secretmanager-otel-tracing

Conversation

@chalmerlowe

@chalmerlowe chalmerlowe commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

Add OpenTelemetry distributed tracing samples for Secret Manager.

There is a push to add OpenTelemetry (Observability) support to the GAPIC generated libraries.

This is a collection of samples that applies to Secret Manager, but is intended to help users of any GAPIC generated library to take advantage of the new Observability capabilities that are rolling out.

Note

For clarity:

  • This new capability is NOT related to Google Cloud Trace (the UI). The traces that the generated code will produce are agnostic and can be ingested into any tracing UI backend (of which Google Cloud Trace is only one) and thus it should NOT go into python-docs-samples/trace which is specific to the Google Cloud Trace UI. We do include a sample to show users how to send traces to a backend (and for simplicity we point it at Cloud Trace).
  • This new capability is not related to any existing observability capabilities that may exist in a handful of handwritten libraries (e.g. bigquery, etc). This is new to GAPIC generated code.
  • The are some references to observability and the Cloud SDK CLI in the Google documentation but this is NOT related to that effort. This is focused on the Cloud SDK client libraries such as secretmanager, translate, etc.

Add standalone snippets and unit test suites demonstrating native OpenTelemetry
distributed tracing for SecretManagerServiceClient and SecretManagerServiceAsyncClient:
- Basic quickstart snippet using ConsoleSpanExporter and environment variable activation
- Google Cloud Trace exporter sample using CloudTraceSpanExporter and BatchSpanProcessor
- Programmatic configuration sample using ClientOptions(tracer_provider=...)
- Asynchronous client sample using SecretManagerServiceAsyncClient
- Mocked unit test suites with conftest fixture for isolated test execution
@product-auto-label product-auto-label Bot added api: secretmanager Issues related to the Secret Manager API. samples Issues that are directly related to samples. labels Oct 14, 2026
Comment thread secretmanager/snippets/secretmanager_trace.py Fixed
Comment thread secretmanager/snippets/secretmanager_trace_async.py Fixed
Comment thread secretmanager/snippets/secretmanager_trace_client_options.py Fixed
Comment thread secretmanager/snippets/secretmanager_trace_cloud_trace.py Fixed

@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 new Python snippets and unit tests demonstrating OpenTelemetry distributed tracing with the Secret Manager client libraries, covering synchronous, asynchronous, programmatic, and Google Cloud Trace configurations. The feedback highlights a critical anti-pattern where the global TracerProvider is initialized and shut down inside reusable functions, which can cause silent failures on subsequent invocations. The reviewer recommends moving the TracerProvider lifecycle management to the main entry points, updating the unit tests to set the global provider directly, and importing the root secretmanager module in the async snippet for consistency.

Comment thread secretmanager/snippets/secretmanager_trace.py
Comment thread secretmanager/snippets/secretmanager_trace.py Outdated
Comment thread secretmanager/snippets/secretmanager_trace_async.py
Comment thread secretmanager/snippets/secretmanager_trace_async.py Outdated
Comment thread secretmanager/snippets/secretmanager_trace_cloud_trace.py
Comment thread secretmanager/snippets/secretmanager_trace_cloud_trace.py Outdated
Comment thread secretmanager/snippets/secretmanager_trace_async.py Outdated
Comment thread secretmanager/snippets/secretmanager_trace_test.py
Comment thread secretmanager/snippets/secretmanager_trace_async_test.py
Comment thread secretmanager/snippets/secretmanager_trace.py Fixed
Comment thread secretmanager/snippets/secretmanager_trace_client_options.py Fixed
Comment thread secretmanager/snippets/secretmanager_trace_cloud_trace.py Fixed
@chalmerlowe
chalmerlowe marked this pull request as ready for review October 15, 2026 10:58
@chalmerlowe
chalmerlowe requested review from a team as code owners October 15, 2026 10:58
@snippet-bot

snippet-bot Bot commented Oct 15, 2026 •

Copy link
Copy Markdown

Here is the summary of changes.

You are about to add 4 region tags.

This comment is generated by snippet-bot.
If you find problems with this result, please file an issue at:
https://github.com/googleapis/repo-automation-bots/issues.
To update this comment, add snippet-bot:force-run label or use the checkbox below:

  • Refresh this comment

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

Labels

api: secretmanager Issues related to the Secret Manager API. samples Issues that are directly related to samples.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants