Skip to content

Commit

Permalink
Fixed instrumentation scope
Browse files Browse the repository at this point in the history
  • Loading branch information
marcalff committed Jul 7, 2023
1 parent fdbef73 commit 63fde43
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 14 deletions.
3 changes: 1 addition & 2 deletions sdk/include/opentelemetry/sdk/metrics/meter.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ class Meter final : public opentelemetry::metrics::Meter
explicit Meter(
std::weak_ptr<sdk::metrics::MeterContext> meter_context,
std::unique_ptr<opentelemetry::sdk::instrumentationscope::InstrumentationScope> scope =
opentelemetry::sdk::instrumentationscope::InstrumentationScope::Create(""),
const opentelemetry::common::KeyValueIterable *attributes = nullptr) noexcept;
opentelemetry::sdk::instrumentationscope::InstrumentationScope::Create("")) noexcept;

nostd::unique_ptr<opentelemetry::metrics::Counter<uint64_t>> CreateUInt64Counter(
nostd::string_view name,
Expand Down
10 changes: 4 additions & 6 deletions sdk/src/metrics/meter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,13 @@ namespace metrics
namespace metrics = opentelemetry::metrics;
namespace nostd = opentelemetry::nostd;

Meter::Meter(std::weak_ptr<MeterContext> meter_context,
std::unique_ptr<sdk::instrumentationscope::InstrumentationScope> instrumentation_scope,
const opentelemetry::common::KeyValueIterable *attributes) noexcept
Meter::Meter(
std::weak_ptr<MeterContext> meter_context,
std::unique_ptr<sdk::instrumentationscope::InstrumentationScope> instrumentation_scope) noexcept
: scope_{std::move(instrumentation_scope)},
meter_context_{meter_context},
observable_registry_(new ObservableRegistry())
{
// FIXME: use attributes
}
{}

nostd::unique_ptr<metrics::Counter<uint64_t>> Meter::CreateUInt64Counter(
nostd::string_view name,
Expand Down
23 changes: 17 additions & 6 deletions sdk/src/metrics/meter_provider.cc
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,6 @@ nostd::shared_ptr<metrics_api::Meter> 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.");
Expand All @@ -62,8 +58,23 @@ nostd::shared_ptr<metrics_api::Meter> MeterProvider::GetMeter(
return nostd::shared_ptr<metrics_api::Meter>{meter};
}
}
auto lib = instrumentationscope::InstrumentationScope::Create(name, version, schema_url);
auto meter = std::shared_ptr<Meter>(new Meter(context_, std::move(lib), attributes));

std::unique_ptr<instrumentationscope::InstrumentationScope> 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<Meter>(new Meter(context_, std::move(scope)));
context_->AddMeter(meter);
return nostd::shared_ptr<metrics_api::Meter>{meter};
}
Expand Down

0 comments on commit 63fde43

Please sign in to comment.