-
Notifications
You must be signed in to change notification settings - Fork 506
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
[Bug]: Global metrics provider gets shutdown when local provider is dropped #1661
Comments
Here's the output of the collector when running the demo Here's a workaround patch that keeps the provider created in the
With this patch applied, the collector log looks as expected and metrics are shown: collector-output-with-patch.log This is all against current I think the intended behaviour is to call |
@bwalk-at-ibm Your analysis is correct. We shouldn't have #[derive(Clone, Debug)]
pub struct SdkMeterProvider {
pipes: Arc<Pipelines>,
meters: Arc<Mutex<HashMap<Scope, Arc<SdkMeter>>>>,
is_shutdown: Arc<AtomicBool>,
}
impl Drop for SdkMeterProvider {
fn drop(&mut self) {
if let Err(err) = self.shutdown() {
global::handle_error(err);
}
}
} with #[derive(Clone, Debug)]
pub struct SdkMeterProvider {
inner: Arc<SdkMeterProviderInner>,
}
pub struct SdkMeterProviderInner {
pipes: Pipelines,
meters: Mutex<HashMap<Scope, Arc<SdkMeter>>>,
is_shutdown: AtomicBool,
}
impl Drop for SdkMeterProviderInner {
fn drop(&mut self) {
if let Err(err) = self.shutdown() {
global::handle_error(err);
}
}
} This will ensure that the shutdown is only invoked when all the references to Apart from this, separate from this issue, we also need to discuss -
|
That looks like an acceptable solution.
I think it would be preferable to remove the implicit call to
The only other reference I have is from the |
Yes to both! Lets continue discussing in #1592 |
What happened?
#1623 introduced
Drop
implementation forSdkMeterProvider
for proper shutdown semantics. This however introduced a bug with the preferred usage pattern like it is demonstrated in the demo.Here's what I assume happens: when building the metrics provider we register a copy of the provider as the global metrics provider. The
SdkMeterProvider
holds references to the underlying data like the pipelines in anArc
, so this behaviour is all good. However, when any provider (like the original provider) is dropped (like it happens in the example code and which seems to be the expected pattern because it is encouraged to use the global metrics provider) and sinceDrop
is implemented on theSdkMeterProvider
will callshutdown()
which will terminate the associated pipelines which are shared with the registered global metrics provider. Hence, we see no metrics and get an error when the global metrics provider gets dropped at application end.API Version
0.22
SDK Version
0.22.1
What Exporters are you seeing the problem on?
OTLP
Relevant log output
No response
The text was updated successfully, but these errors were encountered: