diff --git a/src/lib/metrics/metrics.cpp b/src/lib/metrics/metrics.cpp index ad83ad4d3e7..3e57d86fc43 100644 --- a/src/lib/metrics/metrics.cpp +++ b/src/lib/metrics/metrics.cpp @@ -17,7 +17,7 @@ Metrics &Metrics::getInstance() { } void Metrics::init(Options opts) { - provider = metrics_sdk::MeterProviderFactory::Create(); + auto provider = metrics_sdk::MeterProviderFactory::Create(); auto* p = static_cast(provider.get()); if (opts.enableOStreamExporter) { @@ -70,7 +70,7 @@ void Metrics::init(Options opts) { } if (opts.enableOStreamExporter || opts.enablePrometheusExporter) { - metrics_api::Provider::SetMeterProvider(provider); + metrics_api::Provider::SetMeterProvider(std::move(provider)); } else { std::shared_ptr none; metrics_api::Provider::SetMeterProvider(none); diff --git a/src/lib/metrics/metrics.hpp b/src/lib/metrics/metrics.hpp index 9edb1e64859..de3ac999ab1 100644 --- a/src/lib/metrics/metrics.hpp +++ b/src/lib/metrics/metrics.hpp @@ -145,12 +145,11 @@ namespace metrics { phmap::flat_hash_map> counters; Meter getMeter() { - return provider->GetMeter(meterName, otelVersion); + return metrics_api::Provider::GetMeterProvider()->GetMeter(meterName, otelVersion); } private: std::mutex mutex_; - std::shared_ptr provider; std::string meterName { "stats" }; std::string otelVersion { "1.2.0" };