Skip to content

feat(storage): add status and checksum error classification for OTel metrics - #16639

Open
cpriti-os wants to merge 1 commit into
googleapis:mainfrom
cpriti-os:feat-storage-metrics-error-type
Open

cpriti-os wants to merge 1 commit into
googleapis:mainfrom
cpriti-os:feat-storage-metrics-error-type

Conversation

@cpriti-os

@cpriti-os cpriti-os commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

Adds storage_internal::ComputeErrorType(Status const&) to map google::cloud::Status outcomes to low-cardinality error.type attribute strings for OpenTelemetry client metrics:

  • "OK" on success.
  • "CHECKSUM_MISMATCH" on client/server CRC32C and MD5 hash validation failures.
  • Preserves fine-grained HTTP status mappings from error_info().metadata() (429 -> "RESOURCE_EXHAUSTED", 408/504 -> "DEADLINE_EXCEEDED", 500 -> "INTERNAL") and falls back to StatusCodeToString(status.code()).

Created by cpriti-o11y-agent

@product-auto-label product-auto-label Bot added the api: storage Issues related to the Cloud Storage API. label Nov 9, 2026

@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 a new utility, ComputeErrorType, to classify google::cloud::Status codes into low-cardinality error type strings for metrics, along with associated unit tests and build configuration updates. The feedback highlights a compilation issue where absl::StrContainsIgnoreCase is used but does not exist in Abseil. To fix this, the status message should be converted to lowercase using absl::AsciiStrToLower (which requires including <absl/strings/ascii.h>) before performing standard absl::StrContains checks.

Comment on lines +15 to +17
#include "google/cloud/storage/internal/metrics_error_type.h"
#include "absl/strings/match.h"
#include <string_view>

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

high

To support case-insensitive string matching using absl::AsciiStrToLower, we need to include <absl/strings/ascii.h>.

#include "google/cloud/storage/internal/metrics_error_type.h"
#include "absl/strings/ascii.h"
#include "absl/strings/match.h"
#include <string_view>
References
  1. Prefer including headers (such as <string_view>) directly in .cc files rather than .h files if they are only needed in the implementation, to reduce compilation times for other files that include the header.

Comment on lines +35 to +37
return (absl::StrContainsIgnoreCase(msg, "crc32c") ||
absl::StrContainsIgnoreCase(msg, "md5")) &&
absl::StrContainsIgnoreCase(msg, "match");

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

high

Abseil does not have a function named absl::StrContainsIgnoreCase. Using it will cause a compilation error. Instead, convert the message to lowercase using absl::AsciiStrToLower and perform standard absl::StrContains checks.

  std::string const lower_msg = absl::AsciiStrToLower(msg);
  return (absl::StrContains(lower_msg, "crc32c") ||
          absl::StrContains(lower_msg, "md5")) &&
         absl::StrContains(lower_msg, "match");

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.

absl::StrContainsIgnoreCase is provided by "absl/strings/match.h" and avoids allocating a lowercase std::string copy on each check.


Replied by cpriti-o11y-agent

…metrics

Add `storage_internal::ComputeErrorType(Status const&)` to classify
`Status` values into low-cardinality `error.type` attribute strings for
OpenTelemetry client metrics:

- `"OK"` on success
- `"CHECKSUM_MISMATCH"` on client/server CRC32C and MD5 hash mismatches
- Canonical status names (`"RESOURCE_EXHAUSTED"` for HTTP 429,
  `"DEADLINE_EXCEEDED"` for HTTP 408/504, `"INTERNAL"` for HTTP 500, and
  `StatusCodeToString(status.code())`) otherwise

[Generated-by: AI]
@cpriti-os cpriti-os changed the title feat(storage): add error type classification for OTel metrics feat(storage): add status and checksum error classification for OTel metrics Nov 9, 2026
@cpriti-os
cpriti-os force-pushed the feat-storage-metrics-error-type branch from a217274 to a4cded8 Compare November 9, 2026 08:07
@codecov

codecov Bot commented Nov 9, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.45%. Comparing base (b1e9b10) to head (a4cded8).

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #16639      +/-   ##
==========================================
- Coverage   92.48%   92.45%   -0.03%     
==========================================
  Files        2269     2271       +2     
  Lines      222192   222239      +47     
==========================================
- Hits       205487   205476      -11     
- Misses      16705    16763      +58     

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

@cpriti-os
cpriti-os marked this pull request as ready for review November 9, 2026 09:08
@cpriti-os
cpriti-os requested review from a team as code owners November 9, 2026 09:08
@cpriti-os
cpriti-os requested a review from kalragauri November 9, 2026 09:08

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