From 0e9debb68fd2bc40e635d3ea410af63654ebf036 Mon Sep 17 00:00:00 2001 From: Eliza Weisman Date: Thu, 12 Sep 2019 13:21:55 -0700 Subject: [PATCH] subscriber: fall back to checking statics in `enabled` Currently, the `tracing-subscriber` `EnvFilter` does not properly enable events that originate from the `tracing-log` `LogTracer` adapter. This is because those events are supposed to be filtered only by `enabled`, and will not generate proper `register_callsite` metadata. `EnvFilter`'s `enabled` method will assume that an event was not enabled statically, since `enabled` wouldn't have been called if the callsite was given the `Always` interest. However, this doesn't take `tracing-log` into account. I've changed `EnvFilter` to always check against static filters in `enabled` if the dynamic filters don't enable a given metadata. This fixes the filtering of `tracing-log` events. I've also added tests that fail against the current master. Signed-off-by: Eliza Weisman --- tracing-subscriber/src/filter/env/mod.rs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/tracing-subscriber/src/filter/env/mod.rs b/tracing-subscriber/src/filter/env/mod.rs index d3518cac53..6c486eff83 100644 --- a/tracing-subscriber/src/filter/env/mod.rs +++ b/tracing-subscriber/src/filter/env/mod.rs @@ -231,11 +231,15 @@ impl Layer for EnvFilter { } } - // TODO: other filters... - - false + // Otherwise, fall back to checking if the callsite is + // statically enabled. + // TODO(eliza): we *might* want to check this only if the `log` + // feature is enabled, since if this is a `tracing` event with a + // real callsite, it would already have been statically enabled... + self.statics.enabled(metadata) + }).unwrap_or_else(|| { + self.statics.enabled(metadata) }) - .unwrap_or(false) } fn new_span(&self, attrs: &span::Attributes<'_>, id: &span::Id, _: Context<'_, S>) {