Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Global error handler cleanup - MeterProvider #2237

Merged
merged 7 commits into from
Oct 24, 2024
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 opentelemetry::{
global,
metrics::{Meter, MeterProvider, MetricsError, Result},
KeyValue,
otel_debug, KeyValue,
};

use crate::{instrumentation::Scope, Resource};
Expand Down Expand Up @@ -137,13 +136,21 @@
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."
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: change semicolon to comma?

);

Check warning on line 143 in opentelemetry-sdk/src/metrics/meter_provider.rs

View check run for this annotation

Codecov / codecov/patch

opentelemetry-sdk/src/metrics/meter_provider.rs#L140-L143

Added lines #L140 - L143 were not covered by tests
} else if let Err(err) = self.shutdown() {
otel_debug!(

Check warning on line 145 in opentelemetry-sdk/src/metrics/meter_provider.rs

View check run for this annotation

Codecov / codecov/patch

opentelemetry-sdk/src/metrics/meter_provider.rs#L145

Added line #L145 was not covered by tests
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one is a better fit for otel_error, I guess? It's helpful to know if the metrics were not flushed out during the app/meter provider shutdown.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, deciding between otel_error and otel_debug is challenging in this case—since not all failure errors may be actionable by the user. We can make it more granular later to capture different types of errors and log them separately based on the error type. For now, it’s best to use otel_error, as it's a one-time error during shutdown, and no harm in user knowing even if they can't do anything.

name: "MeterProvider.ShutdownFailed",
message = "Shutdown attempt failed during drop of MeterProvider.",
reason = format!("{}", err)

Check warning on line 148 in opentelemetry-sdk/src/metrics/meter_provider.rs

View check run for this annotation

Codecov / codecov/patch

opentelemetry-sdk/src/metrics/meter_provider.rs#L148

Added line #L148 was not covered by tests
);
}
}
}

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