mirror of
https://github.com/tokio-rs/tracing.git
synced 2025-10-02 07:20:35 +00:00
subscriber: clear enabled
filter map when short circuiting (#1575)
This is essentially the same change as #1569, but for `enabled` states rather than `register_callsite`. When a global filter returns `false` from `enabled`, ensure that the per-layer filter `FilterMap` and debug counters are cleared, so that they are empty on the next `enabled` call. See #1563
This commit is contained in:
parent
36476ac4dc
commit
b09b368e29
@ -709,6 +709,22 @@ impl FilterState {
|
||||
}
|
||||
}
|
||||
|
||||
/// Clears the current in-progress filter state.
|
||||
///
|
||||
/// This resets the [`FilterMap`] and current [`Interest`] as well as
|
||||
/// clearing the debug counters.
|
||||
pub(crate) fn clear_enabled() {
|
||||
// Drop the `Result` returned by `try_with` --- if we are in the middle
|
||||
// a panic and the thread-local has been torn down, that's fine, just
|
||||
// ignore it ratehr than panicking.
|
||||
let _ = FILTERING.try_with(|filtering| {
|
||||
filtering.enabled.set(FilterMap::default());
|
||||
|
||||
#[cfg(debug_assertions)]
|
||||
filtering.counters.in_filter_pass.set(0);
|
||||
});
|
||||
}
|
||||
|
||||
pub(crate) fn take_interest() -> Option<Interest> {
|
||||
FILTERING
|
||||
.try_with(|filtering| {
|
||||
|
@ -80,6 +80,13 @@ where
|
||||
self.inner.enabled(metadata)
|
||||
} else {
|
||||
// otherwise, the callsite is disabled by the layer
|
||||
|
||||
// If per-layer filters are in use, and we are short-circuiting
|
||||
// (rather than calling into the inner type), clear the current
|
||||
// per-layer filter `enabled` state.
|
||||
#[cfg(feature = "registry")]
|
||||
filter::FilterState::clear_enabled();
|
||||
|
||||
false
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user