@@ -45,6 +45,9 @@ constexpr double kDefaultHistogramBuckets[] = {
4545};
4646
4747class NoopMetricsRecorder : public MetricsRecorder {
48+ public:
49+ ~NoopMetricsRecorder () override = default ;
50+
4851 void IncrementEventStatus (std::string event, absl::Status status,
4952 uint64_t count = 1 ) override {}
5053
@@ -72,14 +75,16 @@ class MetricsRecorderImpl : public MetricsRecorder {
7275 event_status_count_ = meter->CreateUInt64Counter (
7376 " EventStatus" , " Count of status code associated with events." );
7477
75- // Catch all histogram, with preconfigured buckets which should work for
78+ // Catch- all histogram, with preconfigured buckets which should work for
7679 // most latencies distribution.
77- RegisterHistogramView (" Latency" , " Latency View" , {});
80+ RegisterHistogramView (" Latency" , " Latency View" , " ns " , {});
7881 latency_histogram_ = meter->CreateUInt64Histogram (
7982 " Latency" , " Histogram of latencies associated with events." ,
8083 " nanosecond" );
8184 }
8285
86+ ~MetricsRecorderImpl () override = default ;
87+
8388 void IncrementEventStatus (std::string event, absl::Status status,
8489 uint64_t count = 1 ) override {
8590 absl::flat_hash_map<std::string, std::string> labels = common_labels_;
@@ -132,7 +137,7 @@ class MetricsRecorderImpl : public MetricsRecorder {
132137 key_iter != histograms_.end ()) {
133138 return ;
134139 }
135- RegisterHistogramView (event, description, bucket_boundaries);
140+ RegisterHistogramView (event, description, unit, bucket_boundaries);
136141 auto meter = GetMeter ();
137142 auto histogram = meter->CreateUInt64Histogram (event, description, unit);
138143 histograms_.insert_or_assign (std::move (event), std::move (histogram));
@@ -143,7 +148,9 @@ class MetricsRecorderImpl : public MetricsRecorder {
143148 }
144149
145150 private:
146- void RegisterHistogramView (std::string name, std::string description,
151+ void RegisterHistogramView (const std::string& name,
152+ const std::string& description,
153+ const std::string& unit,
147154 std::vector<double > bucket_boundaries) {
148155 if (bucket_boundaries.empty ()) {
149156 bucket_boundaries.insert (bucket_boundaries.begin (),
@@ -161,13 +168,13 @@ class MetricsRecorderImpl : public MetricsRecorder {
161168 }
162169 auto histogram_instrument_selector =
163170 std::make_unique<metric_sdk::InstrumentSelector>(
164- metric_sdk::InstrumentType::kHistogram , name);
171+ metric_sdk::InstrumentType::kHistogram , name, unit );
165172 auto histogram_meter_selector = GetMeterSelector (std::string{kSchema });
166173 auto histogram_aggregation_config =
167174 std::make_shared<metric_sdk::HistogramAggregationConfig>();
168175 histogram_aggregation_config->boundaries_ = bucket_boundaries;
169176 auto histogram_view = std::make_unique<metric_sdk::View>(
170- name, description, metric_sdk::AggregationType::kHistogram ,
177+ name, description, unit, metric_sdk::AggregationType::kHistogram ,
171178 std::move (histogram_aggregation_config));
172179 sdk_provider->AddView (std::move (histogram_instrument_selector),
173180 std::move (histogram_meter_selector),
0 commit comments