Skip to content

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

Open
olavloite wants to merge 3 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 3 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.65%. Comparing base (ac6f825) to head (9b2436d).

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.73%   97.65%   -0.08%     
==========================================
  Files         244      246       +2     
  Lines       61161    61428     +267     
==========================================
+ Hits        59776    59989     +213     
- Misses       1385     1439      +54     

☔ 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.

@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 experimental built-in metrics support for the Spanner client, gated behind the experimental-builtin-metrics feature. It adds dependencies on opentelemetry, opentelemetry_sdk, and google-cloud-monitoring-v3, and implements an observability layer to track operation and attempt latencies and counts. Feedback on the changes points out a compilation issue in metrics.rs where PeriodicReader::builder is called with only one argument instead of also requiring a runtime argument like opentelemetry_sdk::runtime::Tokio.

Comment thread src/spanner/src/observability/metrics.rs
Comment thread src/spanner/Cargo.toml
unstable-stream = ["dep:futures"]
default-rustls-provider = ["gaxi/_default-rustls-provider"]
unstable-stream = ["dep:futures"]
experimental-builtin-metrics = ["dep:google-cloud-monitoring-v3", "dep:opentelemetry", "dep:opentelemetry_sdk"]

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.

A thing we learnt the hard way: removing a public feature is a breaking change. You may want to name this _experimental-builtin-metrics because that makes the feature private (by convention) and then removing it is fine.

Comment thread src/spanner/Cargo.toml
wkt = { workspace = true, features = ["time"] }

# Optional dependencies for built-in metrics
google-cloud-monitoring-v3 = { workspace = true, optional = true }

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.

The new shinny is to use the OpenTelemetry Lightweight Protocol (OTLP). Google Cloud supports the protocol. There are Rust exporters for OTLP, they do lack a connector to inject the auth headers.

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.

3 participants