Skip to content

chore(spanner): add initial setup for built-in metrics#5967

Open
olavloite wants to merge 2 commits into
googleapis:mainfrom
olavloite:spanner-built-in-metrics-step-1
Open

chore(spanner): add initial setup for built-in metrics#5967
olavloite wants to merge 2 commits into
googleapis:mainfrom
olavloite:spanner-built-in-metrics-step-1

Conversation

@olavloite

Copy link
Copy Markdown
Contributor

Sets up the initial boiler-plate code for adding built-in metrics for Spanner.

The feature is hidden behind a feature flag, meaning that it is currently invisible to customers.

Sets up the initial boiler-plate code for adding built-in metrics for Spanner.

The feature is hidden behind a feature flag, meaning that it is currently invisible
to customers.
@olavloite olavloite requested review from a team as code owners June 30, 2026 15:20
@product-auto-label product-auto-label Bot added the api: spanner Issues related to the Spanner API. label Jun 30, 2026
@olavloite olavloite requested a review from sakthivelmanii June 30, 2026 15:20

@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 an experimental built-in metrics and observability framework for the Spanner client, adding dependencies on google-cloud-monitoring-v3 and opentelemetry to trace database operations. The reviewer feedback focuses on managing these new dependencies via cfg(google_cloud_unstable_tracing) flags instead of standard Cargo features to prevent dependency bloat, and conditionally compiling the observability module. Additionally, the reviewer recommends optimizing performance by using &'static str for method names to avoid unnecessary string allocations, and improving the robustness of the Server-Timing header parser to handle parameters in any order, along with adding corresponding test cases.

Comment thread src/spanner/Cargo.toml Outdated
Comment thread src/spanner/Cargo.toml Outdated
Comment thread src/spanner/src/lib.rs
Comment thread src/spanner/src/observability/metrics.rs
Comment thread src/spanner/src/observability/metrics.rs
Comment thread src/spanner/src/observability/metrics.rs
Comment thread src/spanner/src/observability/metrics.rs
@codecov

codecov Bot commented Jun 30, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 81.11888% with 54 lines in your changes missing coverage. Please review.
✅ Project coverage is 97.63%. Comparing base (187952a) to head (f599240).
⚠️ Report is 4 commits behind head on main.

Files with missing lines Patch % Lines
src/spanner/src/observability/metrics.rs 72.72% 48 Missing ⚠️
src/spanner/src/observability/exporter.rs 71.42% 6 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #5967      +/-   ##
==========================================
- Coverage   97.71%   97.63%   -0.09%     
==========================================
  Files         242      244       +2     
  Lines       60976    61243     +267     
==========================================
+ Hits        59582    59792     +210     
- Misses       1394     1451      +57     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@olavloite

Copy link
Copy Markdown
Contributor Author

/gemini review

@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 observability and metrics support to the Spanner client, integrating OpenTelemetry and exporting metrics to Google Cloud Monitoring under the google_cloud_unstable_tracing feature flag. The review feedback highlights critical compilation errors in metrics.rs regarding universe_domain cloning and tonic::Status code retrieval, as well as a potential lifetime issue in the define_idempotent_rpc macro closure. Additionally, improvements are suggested to preserve universe domain resolution by not hardcoding the monitoring endpoint, use the crate name for the meter, enhance readability in server timing parsing, and adhere to the repository's 'return early' style guide in parse_project_id.

Comment thread src/spanner/src/observability/metrics.rs
Comment thread src/spanner/src/observability/metrics.rs
Comment thread src/spanner/src/observability/metrics.rs Outdated
Comment thread src/spanner/src/observability/metrics.rs
Comment thread src/spanner/src/observability/metrics.rs Outdated
Comment thread src/spanner/src/client.rs Outdated
Comment thread src/spanner/src/database_client.rs
@olavloite olavloite force-pushed the spanner-built-in-metrics-step-1 branch from 6589d88 to abbeb89 Compare June 30, 2026 16:32
@olavloite

Copy link
Copy Markdown
Contributor Author

/gemini review

@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 observability and metrics tracking to the Spanner client using OpenTelemetry and Google Cloud Monitoring. It adds a new observability module, defines Spanner-specific metrics (such as operation and attempt latencies), and integrates these metrics across various transactions and client operations. The review feedback suggests optimizing environment variable parsing in metrics.rs by using eq_ignore_ascii_case instead of to_lowercase() to avoid unnecessary string allocations.

Comment thread src/spanner/src/observability/metrics.rs
@olavloite olavloite force-pushed the spanner-built-in-metrics-step-1 branch from abbeb89 to 42bbe04 Compare June 30, 2026 16:50
@olavloite

Copy link
Copy Markdown
Contributor Author

/gemini review

@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 observability and metrics tracking to the Spanner client under the google_cloud_unstable_tracing feature flag, integrating OpenTelemetry and Google Cloud Monitoring to record operation and attempt latencies. The review feedback highlights a critical compilation error in the status-to-string mapping due to private tonic::Status fields and a missing name() method on tonic::Code. Additionally, it is recommended to propagate more configuration options, such as the emulator endpoint, from ClientConfig when initializing the monitoring service.

Comment thread src/spanner/src/observability/metrics.rs
Comment thread src/spanner/src/observability/metrics.rs
@olavloite olavloite force-pushed the spanner-built-in-metrics-step-1 branch from 42bbe04 to ee92ecb Compare July 1, 2026 06:07
@olavloite

Copy link
Copy Markdown
Contributor Author

/gemini review

@olavloite olavloite force-pushed the spanner-built-in-metrics-step-1 branch from ee92ecb to 0fb4b96 Compare July 1, 2026 06:13
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Warning

Gemini encountered an error creating the review. You can try again by commenting /gemini review.

@olavloite olavloite force-pushed the spanner-built-in-metrics-step-1 branch from 0fb4b96 to f599240 Compare July 1, 2026 06:27
@olavloite

Copy link
Copy Markdown
Contributor Author

/gemini review

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Warning

Gemini encountered an error creating the review. You can try again by commenting /gemini review.

@olavloite

Copy link
Copy Markdown
Contributor Author

/gemini review

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Warning

Gemini encountered an error creating the review. You can try again by commenting /gemini review.

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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant