2020#include " opentelemetry/sdk/metrics/meter.h"
2121#include < couchbase/metrics/meter.hxx>
2222
23+ #include < algorithm>
2324#include < iostream>
2425#include < thread>
2526#include < utility>
@@ -37,58 +38,53 @@ namespace couchbase::metrics
3738class otel_sync_histogram
3839{
3940public:
40- otel_sync_histogram (nostd::shared_ptr<metrics_api::Histogram<long >> histogram_counter)
41+ otel_sync_histogram (nostd::shared_ptr<metrics_api::Histogram<std:: uint64_t >> histogram_counter)
4142 : histogram_counter_(histogram_counter)
4243 {
4344 }
44- void record (uint64_t value,
45+
46+ void record (std::uint64_t value,
4547 const opentelemetry::common::KeyValueIterable& tags,
4648 opentelemetry::context::Context& ctx)
4749 {
48- // overflow
49- if (value > LONG_MAX) {
50- value = LONG_MAX;
51- }
52- long lvalue = static_cast <long >(value);
53- histogram_counter_->Record (lvalue, tags, ctx);
50+ histogram_counter_->Record (value, tags, ctx);
5451 }
5552
5653private:
57- nostd::shared_ptr<metrics_api::Histogram<long >> histogram_counter_;
54+ nostd::shared_ptr<metrics_api::Histogram<std:: uint64_t >> histogram_counter_;
5855 std::mutex mutex_;
5956};
6057
6158class otel_value_recorder : public couchbase ::metrics::value_recorder
6259{
6360public:
64- explicit otel_value_recorder (nostd::shared_ptr<metrics_api::Histogram<long >> histogram_counter,
65- const std::map<std::string, std::string>& tags)
61+ explicit otel_value_recorder (
62+ nostd::shared_ptr<metrics_api::Histogram<std::uint64_t >> histogram_counter,
63+ const std::map<std::string, std::string>& tags)
6664 : histogram_counter_(histogram_counter)
6765 , tags_(tags)
6866 {
6967 }
7068 void record_value (std::int64_t value) override
7169 {
72- if (value > LONG_MAX) {
73- value = LONG_MAX;
74- }
75- long lvalue = static_cast <long >(value);
70+ value = std::max<int64_t >(value, 0 );
71+ auto uvalue = static_cast <std::uint64_t >(value);
7672 histogram_counter_->Record (
77- value , opentelemetry::common::KeyValueIterableView<decltype (tags_)>{ tags_ }, context_);
73+ uvalue , opentelemetry::common::KeyValueIterableView<decltype (tags_)>{ tags_ }, context_);
7874 }
7975
8076 const std::map<std::string, std::string> tags ()
8177 {
8278 return tags_;
8379 }
8480
85- nostd::shared_ptr<metrics_api::Histogram<long >> histogram_counter ()
81+ nostd::shared_ptr<metrics_api::Histogram<std:: uint64_t >> histogram_counter ()
8682 {
8783 return histogram_counter_;
8884 }
8985
9086private:
91- nostd::shared_ptr<metrics_api::Histogram<long >> histogram_counter_;
87+ nostd::shared_ptr<metrics_api::Histogram<std:: uint64_t >> histogram_counter_;
9288 const std::map<std::string, std::string> tags_;
9389 opentelemetry::context::Context context_{};
9490 std::mutex mutex_;
@@ -115,8 +111,8 @@ public:
115111 // api doesn't seem to allow this.
116112 return recorders_
117113 .insert ({ name,
118- std::make_shared<otel_value_recorder>(meter_-> CreateLongHistogram (name, " " , " us " ),
119- tags) })
114+ std::make_shared<otel_value_recorder>(
115+ meter_-> CreateUInt64Histogram (name, " " , " us " ), tags) })
120116 ->second ;
121117 }
122118 // so it is already, lets see if we already have one with those tags, or need
0 commit comments