Skip to content

feat(storage): add OTel metrics feature gate options and env vars - #16637

Open
cpriti-os wants to merge 4 commits into
googleapis:mainfrom
cpriti-os:feat-storage-otel-metrics-options
Open

cpriti-os wants to merge 4 commits into
googleapis:mainfrom
cpriti-os:feat-storage-otel-metrics-options

Conversation

@cpriti-os

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

Copy link
Copy Markdown
Contributor

Adds the experimental OpenTelemetry metrics feature gate options and environment variables for Cloud Storage C++ SDK, consistent with Go and Java SDKs:

  • storage_experimental::EnableOTelMetricsOption (populated from GOOGLE_CLOUD_CPP_STORAGE_ENABLE_OTEL_METRICS, defaults to false)
  • storage_experimental::EnableOTelDebugMetricsOption (populated from GOOGLE_CLOUD_CPP_STORAGE_ENABLE_OTEL_DEBUG_METRICS, defaults to false)

Created by cpriti-o11y-agent

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]
@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 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.

Comment thread google/cloud/storage/client.cc Outdated
if (!o.has<storage_experimental::EnableOTelMetricsOption>()) {
o.set<storage_experimental::EnableOTelMetricsOption>(false);
}
auto const otel_metrics_env = GetEnv("GCP_STORAGE_CPP_ENABLE_OTEL_METRICS");

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

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
  1. Reject Obscured Domain & Return Types: Flag and reject auto when it hides StatusOr<T>, domain objects, protobuf messages/fields, or function return types. (link)

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.

Updated to use std::optional<std::string> const explicitly.


Replied by cpriti-o11y-agent

Comment thread google/cloud/storage/client.cc Outdated
Comment on lines +720 to +721
auto const otel_debug_metrics_env =
GetEnv("GCP_STORAGE_CPP_ENABLE_OTEL_DEBUG_METRICS");

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

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
  1. Reject Obscured Domain & Return Types: Flag and reject auto when it hides StatusOr<T>, domain objects, protobuf messages/fields, or function return types. (link)

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.

Updated to use std::optional<std::string> const explicitly.


Replied by cpriti-o11y-agent

@cpriti-os
cpriti-os marked this pull request as ready for review November 9, 2026 06:19
@cpriti-os
cpriti-os requested review from a team as code owners November 9, 2026 06:19
@cpriti-os
cpriti-os requested a review from kalragauri November 9, 2026 06:19
@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 (e024623).

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #16637      +/-   ##
==========================================
- Coverage   92.48%   92.45%   -0.03%     
==========================================
  Files        2269     2269              
  Lines      222192   222257      +65     
==========================================
+ Hits       205487   205494       +7     
- 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.

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