Skip to content

Commit

Permalink
fix: metrics shutdown
Browse files Browse the repository at this point in the history
  • Loading branch information
luan committed Dec 5, 2023
1 parent b19cb0a commit 48c26b9
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/lib/metrics/metrics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<metrics_sdk::MeterProvider*>(provider.get());

if (opts.enableOStreamExporter) {
Expand Down Expand Up @@ -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<metrics_api::MeterProvider> none;
metrics_api::Provider::SetMeterProvider(none);
Expand Down
3 changes: 1 addition & 2 deletions src/lib/metrics/metrics.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,12 +145,11 @@ namespace metrics {
phmap::flat_hash_map<std::string, Counter<double>> counters;

Meter getMeter() {
return provider->GetMeter(meterName, otelVersion);
return metrics_api::Provider::GetMeterProvider()->GetMeter(meterName, otelVersion);
}

private:
std::mutex mutex_;
std::shared_ptr<opentelemetry::metrics::MeterProvider> provider;

std::string meterName { "stats" };
std::string otelVersion { "1.2.0" };
Expand Down

0 comments on commit 48c26b9

Please sign in to comment.