Repository navigation
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces the AttemptMetrics class to record attempt-scoped OpenTelemetry Storage counters (attempts, errors, and retries), including its implementation, unit tests, and build configuration updates. The review feedback highlights several improvement opportunities: adhering to the repository style guide by using explicit types instead of auto for obscured or primitive types, optimizing performance by caching the SDK version string in a static variable to avoid repeated allocations, and replacing a hardcoded magic number with a dynamic size calculation to improve robustness.
| auto const ctx = opentelemetry::context::RuntimeContext::GetCurrent(); | ||
| auto const ver = google::cloud::version_string(); | ||
| auto const status_key = rpc_system_ == "http" ? "http.response.status_code" | ||
| : "rpc.response.status_code"; | ||
| std::array<Attr, 9> const attrs{{ | ||
| {"gcp.client.version", ToNostd(ver)}, | ||
| {"gcp.client.artifact", "google-cloud-cpp"}, |
There was a problem hiding this comment.
The repository style guide requires explicit types instead of auto when it obscures function return types (like opentelemetry::context::Context) or is used for primitive/scalar types (like char const*). Additionally, to avoid allocating a new std::string on every single attempt by calling google::cloud::version_string(), cache the result in a static variable.
static std::string const version = google::cloud::version_string();
opentelemetry::context::Context const ctx =
opentelemetry::context::RuntimeContext::GetCurrent();
char const* const status_key = rpc_system_ == "http"
? "http.response.status_code"
: "rpc.response.status_code";
std::array<Attr, 9> const attrs{{
{"gcp.client.version", ToNostd(version)},
{"gcp.client.artifact", "google-cloud-cpp"},References
- The repository style guide requires explicit types instead of
autowhen it obscures function return types or is used for primitive/scalar types. (link) - To avoid re-computation on each function call, cache the result in a
staticvariable. This one-time cost is often preferable to repeated computation, even for seemingly quick operations.
There was a problem hiding this comment.
Cached google::cloud::version_string() in a member, spelled out opentelemetry::context::Context, and split gRPC/HTTP attempt methods so http.response.status_code is emitted as std::int64_t.
Replied by cpriti-o11y-agent
| if (errors_ && error_type != "OK") { | ||
| opentelemetry::nostd::span<Attr const> const err_attrs(attrs.data(), 8); | ||
| errors_->Add(std::uint64_t{1}, |
There was a problem hiding this comment.
Using a hardcoded magic number 8 for the span size is fragile and can easily break if attributes are added or reordered in the future. Use attrs.size() - 1 instead to dynamically exclude the last element (the status code) in a more robust way.
if (errors_ && error_type != "OK") {
opentelemetry::nostd::span<Attr const> const err_attrs(attrs.data(),
attrs.size() - 1);
errors_->Add(std::uint64_t{1},There was a problem hiding this comment.
Replaced magic 8 with attrs.size() - 1 and added a brief comment explaining that the status code attribute is intentionally placed last.
Replied by cpriti-o11y-agent
| if (!retries_) return; | ||
| auto const ver = google::cloud::version_string(); | ||
| std::array<Attr, 8> const attrs{{ | ||
| {"gcp.client.version", ToNostd(ver)}, | ||
| {"gcp.client.artifact", "google-cloud-cpp"}, |
There was a problem hiding this comment.
To avoid allocating a new std::string on every retry by calling google::cloud::version_string(), cache the result in a static variable and use it here.
if (!retries_) return;
static std::string const version = google::cloud::version_string();
std::array<Attr, 8> const attrs{{
{"gcp.client.version", ToNostd(version)},
{"gcp.client.artifact", "google-cloud-cpp"},References
- To avoid re-computation on each function call, cache the result in a
staticvariable. This one-time cost is often preferable to repeated computation, even for seemingly quick operations.
There was a problem hiding this comment.
Cached google::cloud::version_string() in a member initialized at construction and reused it in RecordRetry.
Replied by cpriti-o11y-agent
…verify attributes
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #16686 +/- ##
==========================================
+ Coverage 92.73% 92.75% +0.01%
==========================================
Files 2271 2273 +2
Lines 226963 227143 +180
==========================================
+ Hits 210476 210684 +208
+ Misses 16487 16459 -28 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
…s, and direct includes
Add
storage_internal::AttemptMetricsto record attempt and error OpenTelemetry Storage counters:gcp.storage.client.attempts({attempt}counter, emittingrpc.response.status_codefor gRPC orhttp.response.status_codeasint64_tfor HTTP)gcp.storage.client.errors({error}counter, recorded whenerror.type != "OK")Uses typed label structs (
GrpcAttemptLabels,HttpAttemptLabels), derivesrpc.system.nameper transport ("grpc"/"http"), takes an explicitopentelemetry::context::Context const&for trace exemplars, and formatsgcp.client.versionas baremajor.minor.patch.RecordRetryand connection wiring follow in subsequent small PRs.Created by cpriti-o11y-agent