Skip to content

Commit

Permalink
subscriber: clear enabled filter map when short circuiting
Browse files Browse the repository at this point in the history
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
  • Loading branch information
hawkw committed Sep 17, 2021
1 parent a792aa8 commit 1202a86
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
13 changes: 13 additions & 0 deletions tracing-subscriber/src/filter/layer_filters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -700,6 +700,19 @@ 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() {
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| {
Expand Down
7 changes: 7 additions & 0 deletions tracing-subscriber/src/layer/layered.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down

0 comments on commit 1202a86

Please sign in to comment.