Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
subscriber: fix incorrect filtering for
tracing-log
events (#344)
## Motivation 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. ## Solution 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. This fixes the regression reported by @samscott89. Signed-off-by: Eliza Weisman <eliza@buoyant.io>
- Loading branch information
Showing
3 changed files
with
44 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
mod support; | ||
use self::support::*; | ||
use tracing::{self, subscriber::with_default, Level}; | ||
use tracing_subscriber::{filter::EnvFilter, prelude::*}; | ||
|
||
#[test] | ||
fn log_is_enabled() { | ||
mod my_module { | ||
pub(crate) fn do_test() { | ||
log::trace!("this should be disabled"); | ||
log::info!("this shouldn't be"); | ||
log::debug!("this should be disabled"); | ||
log::warn!("this should be enabled"); | ||
log::warn!(target: "something else", "this shouldn't be enabled"); | ||
log::error!("this should be enabled too"); | ||
} | ||
} | ||
tracing_log::LogTracer::init().expect("logger should be unset"); | ||
let filter: EnvFilter = "filter_log::my_module=info" | ||
.parse() | ||
.expect("filter should parse"); | ||
let (subscriber, finished) = subscriber::mock() | ||
.event(event::mock().at_level(Level::INFO)) | ||
.event(event::mock().at_level(Level::WARN)) | ||
.event(event::mock().at_level(Level::ERROR)) | ||
.done() | ||
.run_with_handle(); | ||
let subscriber = subscriber.with(filter); | ||
|
||
with_default(subscriber, || { | ||
my_module::do_test(); | ||
}); | ||
|
||
finished.assert_finished(); | ||
} |