Skip to content

Commit

Permalink
Global error handler cleanup - MeterProvider (#2237)
Browse files Browse the repository at this point in the history
  • Loading branch information
lalitb authored Oct 24, 2024
1 parent 0202299 commit d3b1c47
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions opentelemetry-sdk/src/metrics/meter_provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@ use std::{
};

use opentelemetry::{
global,
metrics::{Meter, MeterProvider, MetricsError, Result},
KeyValue,
otel_debug, otel_error, KeyValue,
};

use crate::{instrumentation::Scope, Resource};
Expand Down Expand Up @@ -137,13 +136,21 @@ impl Drop for SdkMeterProviderInner {
fn drop(&mut self) {
// 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);
}
if self.is_shutdown.load(Ordering::Relaxed) {
otel_debug!(
name: "MeterProvider.AlreadyShutdown",
message = "Meter provider was already shut down; drop will not attempt shutdown again."
);
} else if let Err(err) = self.shutdown() {
otel_error!(
name: "MeterProvider.ShutdownFailed",
message = "Shutdown attempt failed during drop of MeterProvider.",
reason = format!("{}", err)
);
}
}
}

impl MeterProvider for SdkMeterProvider {
fn versioned_meter(
&self,
Expand Down

0 comments on commit d3b1c47

Please sign in to comment.