Skip to content

chore(spanner): add client identity and monitored resource attributes to built-in metrics - #6245

Open
olavloite wants to merge 1 commit into
googleapis:mainfrom
olavloite:spanner-built-in-metrics-client-identity
Open

chore(spanner): add client identity and monitored resource attributes to built-in metrics#6245
olavloite wants to merge 1 commit into
googleapis:mainfrom
olavloite:spanner-built-in-metrics-client-identity

Conversation

@olavloite

Copy link
Copy Markdown
Contributor
  • Add parse_database_name, generate_client_uid, generate_client_hash, and client_name helper functions for Spanner built-in metrics.
  • Attach an OpenTelemetry Resource (project_id, instance_id, location, instance_config, client_hash) to SdkMeterProvider in Observability::init so metrics export with correct spanner_instance resource labels.
  • Pre-construct common metric attributes (client_uid, client_name, database) on the Observability struct and include them on operation and attempt recordings without repeated string cloning.
  • Add comprehensive unit tests for database name parsing, deterministic client hashing, and client UID/name formatting.

@olavloite
olavloite requested review from a team as code owners July 31, 2026 13:44
@product-auto-label product-auto-label Bot added the api: spanner Issues related to the Spanner API. label Jul 31, 2026

@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 client-side metrics for Spanner observability by parsing database components, generating unique client identifiers (client_uid and client_hash), and attaching common attributes to metrics. Feedback suggests improving the client_hash calculation to use the 24 least significant bits of the FNV-1a hash to reduce collisions, and optimizing client_name to return a static string slice (&'static str) using the concat! macro to avoid unnecessary runtime allocations.

Comment thread src/spanner/src/observability/metrics.rs
Comment thread src/spanner/src/observability/metrics.rs
@codecov

codecov Bot commented Jul 31, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 96.92308% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 96.06%. Comparing base (57dae51) to head (3ffbd7d).
⚠️ Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
src/spanner/src/observability/metrics.rs 96.89% 4 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff            @@
##             main    #6245    +/-   ##
========================================
  Coverage   96.05%   96.06%            
========================================
  Files         271      271            
  Lines       68537    68649   +112     
========================================
+ Hits        65835    65946   +111     
- Misses       2702     2703     +1     

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

… to built-in metrics

- Add `parse_database_name`, `generate_client_uid`, `generate_client_hash`, and `client_name` helper functions for Spanner built-in metrics.
- Attach an OpenTelemetry `Resource` (`project_id`, `instance_id`, `location`, `instance_config`, `client_hash`) to `SdkMeterProvider` in `Observability::init` so metrics export with correct `spanner_instance` resource labels.
- Pre-construct common metric attributes (`client_uid`, `client_name`, `database`) on the `Observability` struct and include them on operation and attempt recordings without repeated string cloning.
- Add comprehensive unit tests for database name parsing, deterministic client hashing, and client UID/name formatting.
@olavloite
olavloite force-pushed the spanner-built-in-metrics-client-identity branch from 85138f7 to 3ffbd7d Compare July 31, 2026 14:16
@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 by adding the uuid dependency and implementing helper functions to parse database names, generate unique client identifiers, and compute client hashes. The Observability struct is updated to initialize and attach these common attributes to recorded metrics, supported by new unit tests. There are no review comments, and the changes conform to the repository's style guidelines.

@olavloite
olavloite requested a review from sakthivelmanii July 31, 2026 14:18
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