Repository navigation
Conversation
Add `storage_experimental::EnableOTelMetricsOption` and `storage_experimental::EnableOTelDebugMetricsOption` to configure OpenTelemetry client metrics and debug metrics collection for Storage, defaulting to `false`. Support `GCP_STORAGE_CPP_ENABLE_OTEL_METRICS` and `GCP_STORAGE_CPP_ENABLE_OTEL_DEBUG_METRICS` environment variable overrides (`"true"` / `"false"") in `DefaultOptions()`, consistent with the Go and Java Storage SDKs. [Generated-by: AI]
There was a problem hiding this comment.
Code Review
This pull request introduces EnableOTelMetricsOption and EnableOTelDebugMetricsOption to configure OpenTelemetry client metrics and debug metrics collection for Storage, allowing overrides via environment variables. Unit tests are also added to verify this behavior. The review feedback recommends explicitly specifying the return type std::optionalstd::string instead of using auto when retrieving environment variables, in order to comply with the repository's style guide against obscuring return types.
| if (!o.has<storage_experimental::EnableOTelMetricsOption>()) { | ||
| o.set<storage_experimental::EnableOTelMetricsOption>(false); | ||
| } | ||
| auto const otel_metrics_env = GetEnv("GCP_STORAGE_CPP_ENABLE_OTEL_METRICS"); |
There was a problem hiding this comment.
According to the repository style guide, auto should not be used when it hides function return types. Please explicitly specify the return type std::optional<std::string> instead of using auto.
std::optional<std::string> const otel_metrics_env =
GetEnv("GCP_STORAGE_CPP_ENABLE_OTEL_METRICS");References
- Reject Obscured Domain & Return Types: Flag and reject
autowhen it hidesStatusOr<T>, domain objects, protobuf messages/fields, or function return types. (link)
There was a problem hiding this comment.
Updated to use std::optional<std::string> const explicitly.
Replied by cpriti-o11y-agent
| auto const otel_debug_metrics_env = | ||
| GetEnv("GCP_STORAGE_CPP_ENABLE_OTEL_DEBUG_METRICS"); |
There was a problem hiding this comment.
According to the repository style guide, auto should not be used when it hides function return types. Please explicitly specify the return type std::optional<std::string> instead of using auto.
std::optional<std::string> const otel_debug_metrics_env =
GetEnv("GCP_STORAGE_CPP_ENABLE_OTEL_DEBUG_METRICS");References
- Reject Obscured Domain & Return Types: Flag and reject
autowhen it hidesStatusOr<T>, domain objects, protobuf messages/fields, or function return types. (link)
There was a problem hiding this comment.
Updated to use std::optional<std::string> const explicitly.
Replied by cpriti-o11y-agent
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #16637 +/- ##
==========================================
- Coverage 92.48% 92.45% -0.03%
==========================================
Files 2269 2269
Lines 222192 222270 +78
==========================================
+ Hits 205487 205507 +20
- Misses 16705 16763 +58 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
…tOptions complexity
kalragauri
left a comment
There was a problem hiding this comment.
nit: the description names the env vars GOOGLE_CLOUD_CPP_STORAGE_ENABLE_OTEL_METRICS / ..._DEBUG_METRICS, but the code uses GCP_STORAGE_CPP_ENABLE_OTEL_METRICS / ..._DEBUG_METRICS. Also, "consistent with Go and Java" only holds for Go: in Java the builder setting takes precedence over the env var. Could you fix the names, state the precedence explicitly, and note that nothing consumes these options yet?
| }; | ||
|
|
||
| /** | ||
| * Enable or disable OpenTelemetry client metrics collection for Storage. |
There was a problem hiding this comment.
EnableOTelMetricsOption is documented as enabling metrics collection, but nothing reads it yet, so setting it has no effect. Is that intentional?
Please also document how it will interact with EnableGrpcMetricsOption.
There was a problem hiding this comment.
Yes, this is intentionally split out first to keep each PR in the series small and easy to review; the metric instruments that read these options are wired in the follow-up PRs. We also updated the docstrings here to clarify that both options are independent of EnableGrpcMetricsOption.
Replied by cpriti-o11y-agent
| } | ||
| std::optional<std::string> const val = GetEnv(env_var); | ||
| if (!val.has_value()) return; | ||
| if (*val == "true") { |
There was a problem hiding this comment.
This accepts only the exact lowercase strings, while storage clients in other languages also accept 1, t, and any casing for the equivalent variables. A deployment that sets =1 across languages would silently get no metrics from C++.
Is the stricter parsing intentional, and if so, should unrecognized values log a warning?
There was a problem hiding this comment.
Yes, matching only exact "true" and "false" and silently ignoring other or empty values is intentional to stay consistent with GOOGLE_CLOUD_ENABLE_DIRECT_PATH_XDS_OVER_INTERCONNECT in default_options.cc.
Replied by cpriti-o11y-agent
|
|
||
| TEST_F(ClientTest, OTelMetricsEnvVarOverridesOption) { | ||
| { | ||
| ScopedEnvironment env("GCP_STORAGE_CPP_ENABLE_OTEL_METRICS", "true"); |
There was a problem hiding this comment.
Both env vars and both options are always set to the same value in these tests, so they would still pass if DefaultOptions() read the debug variable for EnableOTelMetricsOption and vice versa.
Consider adding a case where only one variable is "true" and asserting the other option stays false.
There was a problem hiding this comment.
Good catch—updated OTelMetricsDefaultAndOption and OTelMetricsEnvVarOverridesOption to test each option and environment variable independently with opposite boolean values.
Replied by cpriti-o11y-agent
| /** | ||
| * Enable or disable OpenTelemetry client metrics collection for Storage. | ||
| * | ||
| * The default is `false`. The `GCP_STORAGE_CPP_ENABLE_OTEL_METRICS` |
There was a problem hiding this comment.
GCP_STORAGE_CPP_ENABLE_OTEL_METRICS and the debug variant are only documented here. Could you also add them to google/cloud/storage/doc/environment-variables.dox, next to the other experimental variables?
There was a problem hiding this comment.
Added both GCP_STORAGE_CPP_ENABLE_OTEL_METRICS and GCP_STORAGE_CPP_ENABLE_OTEL_DEBUG_METRICS to google/cloud/storage/doc/environment-variables.dox.
Replied by cpriti-o11y-agent
| } | ||
|
|
||
| TEST_F(ClientTest, OTelMetricsInvalidEnvVarIgnored) { | ||
| for (char const* val : {"1", "0", "TRUE", "False", "ON", "yes", ""}) { |
There was a problem hiding this comment.
A failure inside these nested loops would not say which val or configured combination failed.
Can we replace this with TEST_P and ::testing::Combine, so each case is reported by name?
There was a problem hiding this comment.
Added SCOPED_TRACE with val and configured inside the loop so any assertion failure reports the exact combination without the extra boilerplate of a TEST_P fixture.
Replied by cpriti-o11y-agent
|
Updated the PR description with the exact Replied by cpriti-o11y-agent |
Adds experimental options and environment variable overrides to gate OpenTelemetry client metrics collection for Google Cloud Storage:
storage_experimental::EnableOTelMetricsOption(overridden byGCP_STORAGE_CPP_ENABLE_OTEL_METRICS)storage_experimental::EnableOTelDebugMetricsOption(overridden byGCP_STORAGE_CPP_ENABLE_OTEL_DEBUG_METRICS)Precedence is
environment variable ("true" / "false") > option in code > default (false). This PR introduces the configuration options and environment variable parsing; the metric instruments that read these options are wired in follow-up PRs.Created by cpriti-o11y-agent