20#include "opentelemetry/sdk/metrics/meter.h"
31namespace nostd = opentelemetry::nostd;
32namespace metrics_api = opentelemetry::metrics;
33namespace metrics_sdk = opentelemetry::sdk::metrics;
42 : histogram_counter_(histogram_counter)
47 const opentelemetry::common::KeyValueIterable& tags,
48 opentelemetry::context::Context& ctx)
50 histogram_counter_->Record(value, tags, ctx);
54 nostd::shared_ptr<metrics_api::Histogram<std::uint64_t>> histogram_counter_;
63 const std::map<std::string, std::string>&
tags)
70 value = std::max<int64_t>(value, 0);
71 auto uvalue =
static_cast<std::uint64_t
>(value);
72 histogram_counter_->Record(
73 uvalue, opentelemetry::common::KeyValueIterableView<
decltype(tags_)>{ tags_ }, context_);
76 const std::map<std::string, std::string>
tags()
83 return histogram_counter_;
87 nostd::shared_ptr<metrics_api::Histogram<std::uint64_t>> histogram_counter_;
88 const std::map<std::string, std::string> tags_;
89 opentelemetry::context::Context context_{};
102 -> std::shared_ptr<value_recorder>
override
105 std::scoped_lock<std::mutex> lock(mutex_);
106 auto it = recorders_.equal_range(name);
107 if (it.first == it.second) {
114 std::make_shared<otel_value_recorder>(
115 meter_->CreateUInt64Histogram(name,
"",
"us"), tags) })
120 for (
auto itr = it.first; itr != it.second; itr++) {
121 if (tags == itr->second->tags()) {
130 std::make_shared<otel_value_recorder>(it.first->second->histogram_counter(), tags) })
135 nostd::shared_ptr<metrics_api::Meter> meter_;
137 std::multimap<std::string, std::shared_ptr<otel_value_recorder>> recorders_;
Definition otel_meter.hxx:94
auto get_value_recorder(const std::string &name, const std::map< std::string, std::string > &tags) -> std::shared_ptr< value_recorder > override
Definition otel_meter.hxx:101
otel_meter(nostd::shared_ptr< metrics_api::Meter > meter)
Definition otel_meter.hxx:96
Definition otel_meter.hxx:39
void record(std::uint64_t value, const opentelemetry::common::KeyValueIterable &tags, opentelemetry::context::Context &ctx)
Definition otel_meter.hxx:46
otel_sync_histogram(nostd::shared_ptr< metrics_api::Histogram< std::uint64_t > > histogram_counter)
Definition otel_meter.hxx:41
Definition otel_meter.hxx:59
void record_value(std::int64_t value) override
Definition otel_meter.hxx:68
otel_value_recorder(nostd::shared_ptr< metrics_api::Histogram< std::uint64_t > > histogram_counter, const std::map< std::string, std::string > &tags)
Definition otel_meter.hxx:61
nostd::shared_ptr< metrics_api::Histogram< std::uint64_t > > histogram_counter()
Definition otel_meter.hxx:81
const std::map< std::string, std::string > tags()
Definition otel_meter.hxx:76