Skip to content

feat(spanner): Add sample opting out of built-in client metrics - #14857

Open
iennae wants to merge 5 commits into
mainfrom
feat/spanner-disable-builtin-metrics
Open

iennae wants to merge 5 commits into
mainfrom
feat/spanner-disable-builtin-metrics

Conversation

@iennae

@iennae iennae commented Nov 17, 2026

Copy link
Copy Markdown
Contributor

Description

Applications managing their own OpenTelemetry pipelines can opt out of built-in Cloud Monitoring client-side metrics by passing disable_builtin_metrics=True to spanner.Client.

Establishes spanner/observability and adds spanner_disable_builtin_metrics to replace the inline snippet.

Checklist

Testing

  • I have tested this change on a live environment and verified it works as intended. Unit and live integration tests pass on Python 3.13.

Compliance & Style


Post-Approval Actions

  • Please merge this PR for me once it is approved

Applications exporting custom OpenTelemetry telemetry can disable default Cloud Monitoring client metrics with disable_builtin_metrics=True.
@iennae
iennae requested review from a team as code owners November 17, 2026 23:47
@product-auto-label product-auto-label Bot added api: spanner Issues related to the Spanner API. samples Issues that are directly related to samples. labels Nov 17, 2026
@snippet-bot

snippet-bot Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

Here is the summary of changes.

You are about to add 1 region tag.

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

@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 Cloud Spanner Observability samples in Python, featuring a sample script to disable built-in Cloud Monitoring metrics, along with its associated configuration, dependency files, and tests. Feedback is provided to simplify a redundant nested os.environ.get call in the test configuration file.

Comment thread spanner/observability/tests/conftest.py Outdated
Comment on lines +23 to +25
LIVE_DATABASE_ID = os.environ.get(
"SPANNER_DATABASE_ID", os.environ.get("SPANNER_DATABASE_ID", "")
)

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 default value in the outer os.environ.get call redundantly calls os.environ.get again with the exact same key. This can be simplified to a single os.environ.get call.

LIVE_DATABASE_ID = os.environ.get("SPANNER_DATABASE_ID", "")

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! This comment refers to an earlier revision of this file; the code here has since been reworked in later commits, so this thread no longer applies to the current diff.

Avoids logging project identifiers in stdout or stderr diagnostics and simplifies duplicate environment lookup in test configuration.
…omission

Simplifies duplicate SPANNER_DATABASE_ID lookup in test configuration and asserts project identifiers are omitted from output.
…tions

Prints only runtime query results and verifies real spanner.Client options via wraps in live integration tests.
Comment thread spanner/observability/tests/conftest.py Resolved
Problem: review of this sample identified correctness and robustness
improvements in the sample and its tests.

Solution: apply the accepted review suggestions and extend the tests to
cover the updated behavior. Details are in the review thread replies.

Files updated:
  - spanner/observability/README.md
  - spanner/observability/tests/disable_builtin_metrics_test.py
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api: spanner Issues related to the Spanner API. samples Issues that are directly related to samples.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants