Skip to content

impl(storage): add PayloadMetrics recorder for OTel body size histograms - #16712

Open
cpriti-os wants to merge 1 commit into
googleapis:mainfrom
cpriti-os:impl-storage-payload-metrics
Open

cpriti-os wants to merge 1 commit into
googleapis:mainfrom
cpriti-os:impl-storage-payload-metrics

Conversation

@cpriti-os

Copy link
Copy Markdown
Contributor

Adds the internal PayloadMetrics recorder for the Storage OpenTelemetry payload body size histograms:

  • gcp.storage.client.request.body.size (UInt64Histogram, unit By)
  • gcp.storage.client.response.body.size (UInt64Histogram, unit By)

Both histograms record logical payload byte counts (including 0-byte payloads) with the standard Storage base attributes (gcp.client.version, gcp.client.artifact, gcp.client.service, server.address) and operation attributes (rpc.system.name, gcp.storage.operation, gcp.client.method), propagating the explicit opentelemetry::context::Context and safely no-oping when the provider, meter, or individual instruments are null.

Also registers payload_metrics.{h,cc,_test.cc} in Bazel and CMake build files.


Created by cpriti-o11y-agent

@cpriti-os
cpriti-os requested review from a team as code owners November 26, 2026 07:47
@product-auto-label product-auto-label Bot added the api: storage Issues related to the Cloud Storage API. label Nov 26, 2026
@cpriti-os
cpriti-os requested a review from kalragauri November 26, 2026 07:48

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

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 the PayloadMetrics class to record OpenTelemetry metrics for request and response payload body sizes in Google Cloud Storage, along with comprehensive unit tests and build file updates. The review feedback suggests simplifying the implementation and tests by directly using google::cloud::version_string() instead of defining and using a custom SemanticVersionString() helper.

Comment on lines +46 to +50
std::string SemanticVersionString() {
return std::to_string(google::cloud::version_major()) + "." +
std::to_string(google::cloud::version_minor()) + "." +
std::to_string(google::cloud::version_patch());
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

We can simplify the code and avoid manual string formatting by using google::cloud::version_string() directly instead of defining a custom SemanticVersionString() helper. This is also more consistent with how the client version is recorded in other parts of the SDK.

opentelemetry::nostd::shared_ptr<
opentelemetry::metrics::MeterProvider> const& provider,
std::string server_address, std::string rpc_system)
: client_version_(SemanticVersionString()),

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

Use google::cloud::version_string() directly here to initialize client_version_.

    : client_version_(google::cloud::version_string()),

Comment on lines +148 to +151
std::string const expected_version =
std::to_string(google::cloud::version_major()) + "." +
std::to_string(google::cloud::version_minor()) + "." +
std::to_string(google::cloud::version_patch());

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

Simplify this to use google::cloud::version_string() directly, matching the change in PayloadMetrics.

  std::string const expected_version = google::cloud::version_string();

@codecov

codecov Bot commented Nov 26, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 98.06452% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 92.79%. Comparing base (088ccec) to head (8067373).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
...gle/cloud/storage/internal/payload_metrics_test.cc 98.30% 2 Missing ⚠️
google/cloud/storage/internal/payload_metrics.cc 97.29% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #16712      +/-   ##
==========================================
+ Coverage   92.76%   92.79%   +0.02%     
==========================================
  Files        2273     2277       +4     
  Lines      227827   228136     +309     
==========================================
+ Hits       211355   211692     +337     
+ Misses      16472    16444      -28     

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

This branch has not been deployed

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

Labels

api: storage Issues related to the Cloud Storage API.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant