diff --git a/google/cloud/storage/google_cloud_cpp_storage.bzl b/google/cloud/storage/google_cloud_cpp_storage.bzl index 58ee2b8042356..9593553fdcdfb 100644 --- a/google/cloud/storage/google_cloud_cpp_storage.bzl +++ b/google/cloud/storage/google_cloud_cpp_storage.bzl @@ -86,6 +86,7 @@ google_cloud_cpp_storage_hdrs = [ "internal/md5hash.h", "internal/metadata_parser.h", "internal/metrics_attributes.h", + "internal/metrics_constants.h", "internal/metrics_error_type.h", "internal/notification_metadata_parser.h", "internal/notification_requests.h", @@ -96,6 +97,7 @@ google_cloud_cpp_storage_hdrs = [ "internal/object_read_streambuf.h", "internal/object_requests.h", "internal/object_write_streambuf.h", + "internal/operation_metrics.h", "internal/patch_builder.h", "internal/patch_builder_details.h", "internal/policy_document_request.h", @@ -212,6 +214,7 @@ google_cloud_cpp_storage_srcs = [ "internal/object_requests.cc", "internal/object_write_streambuf.cc", "internal/openssl/hash_function_impl.cc", + "internal/operation_metrics.cc", "internal/patch_builder.cc", "internal/patch_builder_details.cc", "internal/policy_document_request.cc", diff --git a/google/cloud/storage/google_cloud_cpp_storage.cmake b/google/cloud/storage/google_cloud_cpp_storage.cmake index fbdc5e3649469..0ba84aa1c303d 100644 --- a/google/cloud/storage/google_cloud_cpp_storage.cmake +++ b/google/cloud/storage/google_cloud_cpp_storage.cmake @@ -140,6 +140,7 @@ add_library( internal/metadata_parser.h internal/metrics_attributes.cc internal/metrics_attributes.h + internal/metrics_constants.h internal/metrics_error_type.cc internal/metrics_error_type.h internal/notification_metadata_parser.cc @@ -160,6 +161,8 @@ add_library( internal/object_write_streambuf.cc internal/object_write_streambuf.h internal/openssl/hash_function_impl.cc + internal/operation_metrics.cc + internal/operation_metrics.h internal/patch_builder.cc internal/patch_builder.h internal/patch_builder_details.cc @@ -475,6 +478,7 @@ if (BUILD_TESTING) internal/object_read_streambuf_test.cc internal/object_requests_test.cc internal/object_write_streambuf_test.cc + internal/operation_metrics_test.cc internal/patch_builder_test.cc internal/policy_document_request_test.cc internal/request_project_id_test.cc diff --git a/google/cloud/storage/internal/grpc/metrics_exporter_options.cc b/google/cloud/storage/internal/grpc/metrics_exporter_options.cc index fbcf00210fc59..584aef992104a 100644 --- a/google/cloud/storage/internal/grpc/metrics_exporter_options.cc +++ b/google/cloud/storage/internal/grpc/metrics_exporter_options.cc @@ -16,6 +16,7 @@ #include "google/cloud/storage/internal/grpc/metrics_exporter_options.h" #include "google/cloud/opentelemetry/monitoring_exporter.h" +#include "google/cloud/storage/internal/metrics_constants.h" #include "google/cloud/common_options.h" #include "google/cloud/internal/invocation_id_generator.h" #include "google/cloud/universe_domain_options.h" @@ -77,7 +78,7 @@ Options MetricsExporterOptions( return Options{} .set(true) .set([](std::string s) -> std::string { - if (s == "gcp.client.request.duration") { + if (s == kRequestDurationMetric) { return "storage.googleapis.com/client/request_duration"; } // Storage SDK metrics under `gcp.storage.client.*` are registered in diff --git a/google/cloud/storage/internal/grpc/metrics_meter_provider.h b/google/cloud/storage/internal/grpc/metrics_meter_provider.h index 28625222e8003..2f4ab965a0276 100644 --- a/google/cloud/storage/internal/grpc/metrics_meter_provider.h +++ b/google/cloud/storage/internal/grpc/metrics_meter_provider.h @@ -17,6 +17,7 @@ #ifdef GOOGLE_CLOUD_CPP_STORAGE_WITH_OTEL_METRICS +#include "google/cloud/storage/internal/metrics_constants.h" #include "google/cloud/version.h" #include #include @@ -31,15 +32,6 @@ namespace cloud { namespace storage_internal { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -/** - * The instrumentation scope for instruments created by this library. - * - * gRPC's own instruments use the `grpc-c++` scope. Using the same scope name - * as the tracer (`gl-cpp`) keeps the library's telemetry identifiable and - * lets `MakeGrpcMeterProvider()` attach a latency view to it. - */ -auto constexpr kStorageMeterName = "gl-cpp"; - /** * The fully qualified name of the `channel_creation_latency` instrument. * @@ -56,7 +48,7 @@ std::string ChannelCreationLatencyInstrument(); /// Storage SDK latency histogram instruments registered with explicit buckets. inline constexpr std::array kStorageLatencyHistogramInstruments = {{ - "gcp.client.request.duration", + kRequestDurationMetric, "gcp.storage.client.ttfb", "rpc.client.call.duration", "gcp.storage.client.stall.duration", diff --git a/google/cloud/storage/internal/metrics_constants.h b/google/cloud/storage/internal/metrics_constants.h new file mode 100644 index 0000000000000..11c2e9f135cd9 --- /dev/null +++ b/google/cloud/storage/internal/metrics_constants.h @@ -0,0 +1,47 @@ +// Copyright 2026 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_STORAGE_INTERNAL_METRICS_CONSTANTS_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_STORAGE_INTERNAL_METRICS_CONSTANTS_H + +#include "google/cloud/storage/version.h" +#include + +namespace google { +namespace cloud { +namespace storage_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +/** + * The instrumentation scope for instruments created by this library. + * + * gRPC's own instruments use the `grpc-c++` scope. Using the same scope name + * as the tracer (`gl-cpp`) keeps the library's telemetry identifiable and + * lets `MakeGrpcMeterProvider()` attach histogram views to it. + */ +inline constexpr char const* kStorageMeterName = "gl-cpp"; + +/// Shared OpenTelemetry instrument names referenced by both recorders and +/// exporter/view registration so they cannot drift apart. +inline constexpr std::string_view kOperationsMetric = + "gcp.storage.client.operations"; +inline constexpr std::string_view kRequestDurationMetric = + "gcp.client.request.duration"; + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace storage_internal +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_STORAGE_INTERNAL_METRICS_CONSTANTS_H diff --git a/google/cloud/storage/internal/operation_metrics.cc b/google/cloud/storage/internal/operation_metrics.cc new file mode 100644 index 0000000000000..7a78d38f0668c --- /dev/null +++ b/google/cloud/storage/internal/operation_metrics.cc @@ -0,0 +1,108 @@ +// Copyright 2026 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include "google/cloud/storage/internal/operation_metrics.h" +#include "google/cloud/storage/internal/metrics_constants.h" +#include "google/cloud/version.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace google { +namespace cloud { +namespace storage_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN +namespace { + +using Attr = std::pair; + +opentelemetry::nostd::string_view ToNostd(std::string_view sv) { + return opentelemetry::nostd::string_view(sv.data(), sv.size()); +} + +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()); +} + +} // namespace + +OperationMetrics::OperationMetrics( + opentelemetry::nostd::shared_ptr< + opentelemetry::metrics::MeterProvider> const& provider, + std::string server_address, std::string rpc_system) + : client_version_(SemanticVersionString()), + server_address_(std::move(server_address)), + rpc_system_(std::move(rpc_system)) { + if (!provider) return; + meter_ = + provider->GetMeter(kStorageMeterName, google::cloud::version_string()); + if (!meter_) return; + operations_ = meter_->CreateUInt64Counter( + ToNostd(kOperationsMetric), + "Number of logical GCS operations initiated by the client.", + "{operation}"); + request_duration_ = meter_->CreateDoubleHistogram( + ToNostd(kRequestDurationMetric), + "Application-level end-to-end latency of logical GCS operations.", "s"); +} + +void OperationMetrics::RecordOperation( + OperationLabels const& labels, std::chrono::steady_clock::duration elapsed, + opentelemetry::context::Context const& ctx) const { + if (!operations_ && !request_duration_) return; + // `rpc.method` is placed last so `operations_` can exclude it via a prefix + // span of size `attrs.size() - 1`. + std::array const attrs{{ + {"gcp.client.version", ToNostd(client_version_)}, + {"gcp.client.artifact", + opentelemetry::nostd::string_view("google-cloud-cpp")}, + {"gcp.client.service", opentelemetry::nostd::string_view("storage")}, + {"server.address", ToNostd(server_address_)}, + {"rpc.system.name", ToNostd(rpc_system_)}, + {"gcp.storage.operation", ToNostd(labels.operation)}, + {"gcp.client.method", ToNostd(labels.client_method)}, + {"error.type", ToNostd(labels.error_type)}, + {"rpc.method", ToNostd(labels.rpc_method)}, + }}; + if (operations_) { + opentelemetry::nostd::span const op_attrs(attrs.data(), + attrs.size() - 1); + operations_->Add(std::uint64_t{1}, + opentelemetry::common::MakeKeyValueIterableView(op_attrs), + ctx); + } + if (request_duration_) { + double const duration_seconds = + elapsed < std::chrono::steady_clock::duration::zero() + ? 0.0 + : std::chrono::duration(elapsed).count(); + request_duration_->Record( + duration_seconds, + opentelemetry::common::MakeKeyValueIterableView(attrs), ctx); + } +} + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace storage_internal +} // namespace cloud +} // namespace google diff --git a/google/cloud/storage/internal/operation_metrics.h b/google/cloud/storage/internal/operation_metrics.h new file mode 100644 index 0000000000000..e16c31147e861 --- /dev/null +++ b/google/cloud/storage/internal/operation_metrics.h @@ -0,0 +1,73 @@ +// Copyright 2026 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_STORAGE_INTERNAL_OPERATION_METRICS_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_STORAGE_INTERNAL_OPERATION_METRICS_H + +#include "google/cloud/storage/version.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace google { +namespace cloud { +namespace storage_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +/// Labels for recording a logical Storage operation. +struct OperationLabels { + std::string_view operation; + std::string_view client_method; + std::string_view rpc_method; + std::string_view error_type; +}; + +/// Thread-safe recorder for operation-scoped OpenTelemetry Storage metrics +/// (`gcp.storage.client.operations` and `gcp.client.request.duration`). +/// When constructed with a null provider, all methods are no-ops. +class OperationMetrics { + public: + OperationMetrics(opentelemetry::nostd::shared_ptr< + opentelemetry::metrics::MeterProvider> const& provider, + std::string server_address, std::string rpc_system); + + void RecordOperation(OperationLabels const& labels, + std::chrono::steady_clock::duration elapsed, + opentelemetry::context::Context const& ctx) const; + + private: + std::string client_version_; + std::string server_address_; + std::string rpc_system_; + opentelemetry::nostd::shared_ptr meter_; + opentelemetry::nostd::unique_ptr< + opentelemetry::metrics::Counter> + operations_; + opentelemetry::nostd::unique_ptr> + request_duration_; +}; + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace storage_internal +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_STORAGE_INTERNAL_OPERATION_METRICS_H diff --git a/google/cloud/storage/internal/operation_metrics_test.cc b/google/cloud/storage/internal/operation_metrics_test.cc new file mode 100644 index 0000000000000..663043d9e0270 --- /dev/null +++ b/google/cloud/storage/internal/operation_metrics_test.cc @@ -0,0 +1,264 @@ +// Copyright 2026 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include "google/cloud/storage/internal/operation_metrics.h" +#include "google/cloud/testing_util/mock_opentelemetry_metrics.h" +#include "google/cloud/version.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace google { +namespace cloud { +namespace storage_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN +namespace { + +using ::google::cloud::testing_util::MockCounter; +using ::google::cloud::testing_util::MockHistogram; +using ::google::cloud::testing_util::MockMeter; +using ::google::cloud::testing_util::MockMeterProvider; +using ::testing::_; +using ::testing::ByMove; +using ::testing::DoubleEq; +using ::testing::Eq; +using ::testing::Pair; +using ::testing::Return; +using ::testing::UnorderedElementsAre; + +using CounterPtr = opentelemetry::nostd::unique_ptr< + opentelemetry::metrics::Counter>; +using HistPtr = + opentelemetry::nostd::unique_ptr>; + +std::map ExtractStringAttrs( + opentelemetry::common::KeyValueIterable const& iterable) { + std::map result; + iterable.ForEachKeyValue( + [&](opentelemetry::nostd::string_view key, + opentelemetry::common::AttributeValue value) noexcept { + if (auto const* sv = + opentelemetry::nostd::get_if( + &value)) { + result.emplace(std::string(key.data(), key.size()), + std::string(sv->data(), sv->size())); + } else { + ADD_FAILURE() << "Unexpected non-string attribute for key: " + << std::string(key.data(), key.size()); + } + return true; + }); + return result; +} + +TEST(OperationMetricsTest, RecordsOperationsAndDurationWithAttributes) { + std::map op_attrs; + auto ops = std::make_unique>(); + EXPECT_CALL(*ops, Add(std::uint64_t{1}, _, _)) + .WillOnce([&](std::uint64_t, + opentelemetry::common::KeyValueIterable const& kv, + opentelemetry::context::Context const& ctx) { + opentelemetry::context::ContextValue const val = + ctx.GetValue("trace_marker"); + auto const* marker = opentelemetry::nostd::get_if(&val); + ASSERT_NE(marker, nullptr); + EXPECT_EQ(*marker, 42); + op_attrs = ExtractStringAttrs(kv); + }); + + std::map dur_attrs; + auto dur = std::make_unique>(); + EXPECT_CALL(*dur, Record(DoubleEq(0.25), _, _)) + .WillOnce([&](double, opentelemetry::common::KeyValueIterable const& kv, + opentelemetry::context::Context const& ctx) { + opentelemetry::context::ContextValue const val = + ctx.GetValue("trace_marker"); + auto const* marker = opentelemetry::nostd::get_if(&val); + ASSERT_NE(marker, nullptr); + EXPECT_EQ(*marker, 42); + dur_attrs = ExtractStringAttrs(kv); + }); + + opentelemetry::nostd::shared_ptr meter = + std::make_shared(); + EXPECT_CALL(*meter, CreateUInt64Counter(Eq("gcp.storage.client.operations"), + _, Eq("{operation}"))) + .WillOnce(Return(ByMove(CounterPtr(ops.release())))); + EXPECT_CALL(*meter, CreateDoubleHistogram(Eq("gcp.client.request.duration"), + _, Eq("s"))) + .WillOnce(Return(ByMove(HistPtr(dur.release())))); + + auto provider = std::make_shared(); + EXPECT_CALL(*provider, GetMeter) +#if OPENTELEMETRY_ABI_VERSION_NO >= 2 + .WillOnce([&](opentelemetry::nostd::string_view scope, + opentelemetry::nostd::string_view scope_version, + opentelemetry::nostd::string_view, + opentelemetry::common::KeyValueIterable const*) { +#else + .WillOnce([&](opentelemetry::nostd::string_view scope, + opentelemetry::nostd::string_view scope_version, + opentelemetry::nostd::string_view) { +#endif + EXPECT_EQ(std::string(scope.data(), scope.size()), "gl-cpp"); + EXPECT_EQ(std::string(scope_version.data(), scope_version.size()), + google::cloud::version_string()); + return meter; + }); + opentelemetry::nostd::shared_ptr mp( + std::static_pointer_cast( + provider)); + + OperationMetrics metrics(mp, "storage.googleapis.com", "grpc"); + opentelemetry::context::Context const ctx = + opentelemetry::context::Context("trace_marker", std::int64_t{42}); + metrics.RecordOperation({"ReadObject", "Client::ReadObject", + "google.storage.v2.Storage/ReadObject", "OK"}, + std::chrono::milliseconds(250), ctx); + + std::string const ver = std::to_string(google::cloud::version_major()) + "." + + std::to_string(google::cloud::version_minor()) + "." + + std::to_string(google::cloud::version_patch()); + EXPECT_THAT(op_attrs, UnorderedElementsAre( + Pair("gcp.client.version", ver), + Pair("gcp.client.artifact", "google-cloud-cpp"), + Pair("gcp.client.service", "storage"), + Pair("server.address", "storage.googleapis.com"), + Pair("rpc.system.name", "grpc"), + Pair("gcp.storage.operation", "ReadObject"), + Pair("gcp.client.method", "Client::ReadObject"), + Pair("error.type", "OK"))); + EXPECT_THAT(dur_attrs, + UnorderedElementsAre( + Pair("gcp.client.version", ver), + Pair("gcp.client.artifact", "google-cloud-cpp"), + Pair("gcp.client.service", "storage"), + Pair("server.address", "storage.googleapis.com"), + Pair("rpc.system.name", "grpc"), + Pair("gcp.storage.operation", "ReadObject"), + Pair("gcp.client.method", "Client::ReadObject"), + Pair("error.type", "OK"), + Pair("rpc.method", "google.storage.v2.Storage/ReadObject"))); +} + +TEST(OperationMetricsTest, ClampsNegativeDurationToZero) { + auto ops = std::make_unique>(); + EXPECT_CALL(*ops, Add(std::uint64_t{1}, _, _)).Times(1); + auto dur = std::make_unique>(); + EXPECT_CALL(*dur, Record(DoubleEq(0.0), _, _)).Times(1); + + opentelemetry::nostd::shared_ptr meter = + std::make_shared(); + EXPECT_CALL(*meter, CreateUInt64Counter) + .WillOnce(Return(ByMove(CounterPtr(ops.release())))); + EXPECT_CALL(*meter, CreateDoubleHistogram) + .WillOnce(Return(ByMove(HistPtr(dur.release())))); + + auto provider = std::make_shared(); + EXPECT_CALL(*provider, GetMeter).WillOnce(Return(meter)); + opentelemetry::nostd::shared_ptr mp( + std::static_pointer_cast( + provider)); + + OperationMetrics metrics(mp, "storage.googleapis.com", "grpc"); + metrics.RecordOperation({"ReadObject", "Client::ReadObject", + "google.storage.v2.Storage/ReadObject", "OK"}, + std::chrono::milliseconds(-5), + opentelemetry::context::Context{}); +} + +TEST(OperationMetricsTest, NullProviderAndNullMeterAreNoOps) { + OperationLabels const labels{"ReadObject", "Client::ReadObject", + "google.storage.v2.Storage/ReadObject", "OK"}; + opentelemetry::context::Context const ctx{}; + OperationMetrics no_provider(nullptr, "storage.googleapis.com", "grpc"); + no_provider.RecordOperation(labels, std::chrono::milliseconds(100), ctx); + + auto provider = std::make_shared(); + EXPECT_CALL(*provider, GetMeter) + .WillOnce(Return( + opentelemetry::nostd::shared_ptr{ + nullptr})); + opentelemetry::nostd::shared_ptr mp( + std::static_pointer_cast( + provider)); + OperationMetrics no_meter(mp, "storage.googleapis.com", "grpc"); + no_meter.RecordOperation(labels, std::chrono::milliseconds(100), ctx); +} + +TEST(OperationMetricsTest, NullAndPartialInstruments) { + OperationLabels const labels{"ReadObject", "Client::ReadObject", + "google.storage.v2.Storage/ReadObject", "OK"}; + opentelemetry::context::Context const ctx{}; + + opentelemetry::nostd::shared_ptr empty_meter = + std::make_shared(); + EXPECT_CALL(*empty_meter, CreateUInt64Counter) + .WillOnce(Return(ByMove(CounterPtr(nullptr)))); + EXPECT_CALL(*empty_meter, CreateDoubleHistogram) + .WillOnce(Return(ByMove(HistPtr(nullptr)))); + + auto dur = std::make_unique>(); + EXPECT_CALL(*dur, Record(DoubleEq(0.5), _, _)).Times(1); + opentelemetry::nostd::shared_ptr duration_only_meter = + std::make_shared(); + EXPECT_CALL(*duration_only_meter, CreateUInt64Counter) + .WillOnce(Return(ByMove(CounterPtr(nullptr)))); + EXPECT_CALL(*duration_only_meter, CreateDoubleHistogram) + .WillOnce(Return(ByMove(HistPtr(dur.release())))); + + auto ops = std::make_unique>(); + EXPECT_CALL(*ops, Add(std::uint64_t{1}, _, _)).Times(1); + opentelemetry::nostd::shared_ptr ops_only_meter = + std::make_shared(); + EXPECT_CALL(*ops_only_meter, CreateUInt64Counter) + .WillOnce(Return(ByMove(CounterPtr(ops.release())))); + EXPECT_CALL(*ops_only_meter, CreateDoubleHistogram) + .WillOnce(Return(ByMove(HistPtr(nullptr)))); + + auto provider = std::make_shared(); + EXPECT_CALL(*provider, GetMeter) + .WillOnce(Return(empty_meter)) + .WillOnce(Return(duration_only_meter)) + .WillOnce(Return(ops_only_meter)); + opentelemetry::nostd::shared_ptr mp( + std::static_pointer_cast( + provider)); + + OperationMetrics none(mp, "storage.googleapis.com", "grpc"); + none.RecordOperation(labels, std::chrono::milliseconds(100), ctx); + + OperationMetrics duration_only(mp, "storage.googleapis.com", "grpc"); + duration_only.RecordOperation(labels, std::chrono::milliseconds(500), ctx); + + OperationMetrics ops_only(mp, "storage.googleapis.com", "grpc"); + ops_only.RecordOperation(labels, std::chrono::milliseconds(500), ctx); +} + +} // namespace +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace storage_internal +} // namespace cloud +} // namespace google diff --git a/google/cloud/storage/storage_client_unit_tests.bzl b/google/cloud/storage/storage_client_unit_tests.bzl index de5122cc89529..e646a81293431 100644 --- a/google/cloud/storage/storage_client_unit_tests.bzl +++ b/google/cloud/storage/storage_client_unit_tests.bzl @@ -83,6 +83,7 @@ storage_client_unit_tests = [ "internal/object_read_streambuf_test.cc", "internal/object_requests_test.cc", "internal/object_write_streambuf_test.cc", + "internal/operation_metrics_test.cc", "internal/patch_builder_test.cc", "internal/policy_document_request_test.cc", "internal/request_project_id_test.cc",