From 380a709162a57262c8cf12d7653a7d1806684ac3 Mon Sep 17 00:00:00 2001 From: Cijo Thomas Date: Mon, 30 Sep 2024 15:45:31 -0700 Subject: [PATCH] MeterProvider modified to not do shutdown if user has already shut down (#2156) Co-authored-by: Lalit Kumar Bhasin --- opentelemetry-sdk/CHANGELOG.md | 3 +++ opentelemetry-sdk/src/metrics/meter_provider.rs | 8 ++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/opentelemetry-sdk/CHANGELOG.md b/opentelemetry-sdk/CHANGELOG.md index 4b6679940a..ce8ce1edec 100644 --- a/opentelemetry-sdk/CHANGELOG.md +++ b/opentelemetry-sdk/CHANGELOG.md @@ -14,6 +14,9 @@ - For Delta Temporality, exporters are not invoked unless there were new measurements since the last collect/export. [#2153](https://github.com/open-telemetry/opentelemetry-rust/pull/2153) +- `MeterProvider` modified to not invoke shutdown on `Drop`, if user has already + called `shutdown()`. + [#2156](https://github.com/open-telemetry/opentelemetry-rust/pull/2156) ## v0.25.0 diff --git a/opentelemetry-sdk/src/metrics/meter_provider.rs b/opentelemetry-sdk/src/metrics/meter_provider.rs index 9cd798eb44..d5bae2f4ac 100644 --- a/opentelemetry-sdk/src/metrics/meter_provider.rs +++ b/opentelemetry-sdk/src/metrics/meter_provider.rs @@ -130,8 +130,12 @@ impl SdkMeterProviderInner { impl Drop for SdkMeterProviderInner { fn drop(&mut self) { - if let Err(err) = self.shutdown() { - global::handle_error(err); + // If user has already shutdown the provider manually by calling + // shutdown(), then we don't need to call shutdown again. + if !self.is_shutdown.load(Ordering::Relaxed) { + if let Err(err) = self.shutdown() { + global::handle_error(err); + } } } }