diff --git a/sdk/include/opentelemetry/sdk/metrics/meter.h b/sdk/include/opentelemetry/sdk/metrics/meter.h index 36dea2b183..41a10f69e9 100644 --- a/sdk/include/opentelemetry/sdk/metrics/meter.h +++ b/sdk/include/opentelemetry/sdk/metrics/meter.h @@ -42,8 +42,7 @@ class Meter final : public opentelemetry::metrics::Meter explicit Meter( std::weak_ptr meter_context, std::unique_ptr scope = - opentelemetry::sdk::instrumentationscope::InstrumentationScope::Create(""), - const opentelemetry::common::KeyValueIterable *attributes = nullptr) noexcept; + opentelemetry::sdk::instrumentationscope::InstrumentationScope::Create("")) noexcept; nostd::unique_ptr> CreateUInt64Counter( nostd::string_view name, diff --git a/sdk/src/metrics/meter.cc b/sdk/src/metrics/meter.cc index 517964cdc5..6b8b6c8925 100644 --- a/sdk/src/metrics/meter.cc +++ b/sdk/src/metrics/meter.cc @@ -26,15 +26,13 @@ namespace metrics namespace metrics = opentelemetry::metrics; namespace nostd = opentelemetry::nostd; -Meter::Meter(std::weak_ptr meter_context, - std::unique_ptr instrumentation_scope, - const opentelemetry::common::KeyValueIterable *attributes) noexcept +Meter::Meter( + std::weak_ptr meter_context, + std::unique_ptr instrumentation_scope) noexcept : scope_{std::move(instrumentation_scope)}, meter_context_{meter_context}, observable_registry_(new ObservableRegistry()) -{ - // FIXME: use attributes -} +{} nostd::unique_ptr> Meter::CreateUInt64Counter( nostd::string_view name, diff --git a/sdk/src/metrics/meter_provider.cc b/sdk/src/metrics/meter_provider.cc index 2bdb853281..62bea2b0f5 100644 --- a/sdk/src/metrics/meter_provider.cc +++ b/sdk/src/metrics/meter_provider.cc @@ -42,10 +42,6 @@ nostd::shared_ptr MeterProvider::GetMeter( #endif ) noexcept { -#if OPENTELEMETRY_ABI_VERSION_NO < 2 - const opentelemetry::common::KeyValueIterable *attributes = nullptr; -#endif - if (name.data() == nullptr || name == "") { OTEL_INTERNAL_LOG_WARN("[MeterProvider::GetMeter] Library name is empty."); @@ -62,8 +58,23 @@ nostd::shared_ptr MeterProvider::GetMeter( return nostd::shared_ptr{meter}; } } - auto lib = instrumentationscope::InstrumentationScope::Create(name, version, schema_url); - auto meter = std::shared_ptr(new Meter(context_, std::move(lib), attributes)); + + std::unique_ptr scope; + +#if OPENTELEMETRY_ABI_VERSION_NO >= 2 + if (attributes != nullptr) + { + instrumentationscope::InstrumentationScopeAttributes attrs_map(*attributes); + scope = + instrumentationscope::InstrumentationScope::Create(name, version, schema_url, attrs_map); + } + else +#endif + { + scope = instrumentationscope::InstrumentationScope::Create(name, version, schema_url); + } + + auto meter = std::shared_ptr(new Meter(context_, std::move(scope))); context_->AddMeter(meter); return nostd::shared_ptr{meter}; }