-
Notifications
You must be signed in to change notification settings - Fork 676
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
subscriber: add combinators for combining filters #1578
Conversation
} | ||
|
||
fn max_level_hint(&self) -> Option<LevelFilter> { | ||
// TODO(eliza): figure this out??? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is the main reason this PR is still a draft
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
jeez, yeah, that really fucks with my brain. i'd maybe return None
for now
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The reason this is confusing is that I don't think we can simply return the "opposite" of the inner filter's hint, since the filter might be enabling things based on a particular characteristic other than levels, and we might still enable things of the same level. I think maybe we should just return None
and have this break caching...though honestly, I'm not totally sure how necessary the Not
filter even is...
#[test] | ||
fn and() { | ||
let (layer, handle) = layer::mock() | ||
.event( | ||
event::msg("a very interesting event") | ||
.at_level(tracing::Level::INFO) | ||
.with_target("interesting_target"), | ||
) | ||
.done() | ||
.run_with_handle(); | ||
|
||
// Enables spans and events with targets starting with `interesting_target`: | ||
let target_filter = filter::filter_fn(|meta| meta.target().starts_with("interesting_target")); | ||
|
||
// Enables spans and events with levels `INFO` and below: | ||
let level_filter = LevelFilter::INFO; | ||
|
||
// Combine the two filters together, returning a filter that only enables | ||
// spans and events that *both* filters will enable: | ||
let filter = target_filter.and(level_filter); | ||
|
||
let _subscriber = tracing_subscriber::registry() | ||
.with(layer.with_filter(filter)) | ||
.set_default(); | ||
|
||
// This event will *not* be enabled: | ||
tracing::info!("an event with an uninteresting target"); | ||
|
||
// This event *will* be enabled: | ||
tracing::info!(target: "interesting_target", "a very interesting event"); | ||
|
||
// This event will *not* be enabled: | ||
tracing::debug!(target: "interesting_target", "interesting debug event..."); | ||
|
||
handle.assert_finished(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
whoops this was supposed to be in a separate commit. lol whatever.
@davidbarsky any thoughts on whether the approach in a131037 or in 14e3a9b is better? |
@davidbarsky ping |
1 similar comment
@davidbarsky ping |
} | ||
|
||
fn max_level_hint(&self) -> Option<LevelFilter> { | ||
// TODO(eliza): figure this out??? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
jeez, yeah, that really fucks with my brain. i'd maybe return None
for now
Signed-off-by: Eliza Weisman <eliza@buoyant.io>
Signed-off-by: Eliza Weisman <eliza@buoyant.io>
Signed-off-by: Eliza Weisman <eliza@buoyant.io>
apparently the `S` type param just can't ever be inferred when using the combinators. that kicks ass lmao Signed-off-by: Eliza Weisman <eliza@buoyant.io>
...but i'm not sure if that's better or worse. this fixes the type inference issues and allows us to check that the combined layers are both `Filter`s for the same subscriber. it also allows the `FilterExt` trait to only be implemented for `Filter`s. on the other hand, it means propagating a bunch of phantomdatas everywhere. this makes the code grosser and also takes longer for the compiler to typecheck (though i doubt people will be nesting these combinators deep enough to notice). it also means we can't derive traits like `Debug` and `Clone`, and need manual implementations. which is *fine*, it's just annoying... Signed-off-by: Eliza Weisman <eliza@buoyant.io>
thanks @davidbarsky Co-authored-by: David Barsky <me@davidbarsky.com>
Signed-off-by: Eliza Weisman <eliza@buoyant.io>
647ff18
to
17b5680
Compare
# 0.3.7 (Jan 25, 2022) This release adds combinators for combining filters. Additionally, this release also updates the `thread-local` crate to v1.1.4, fixing warnings for the security advisory [RUSTSEC-2022-0006]. Note that previous versions of `tracing-subscriber` did not use any of the `thread-local` crate's APIs effected by the vulnerability. However, updating the version fixes warnings emitted by `cargo audit` and similar tools. ### Added - **filter**: Added combinators for combining filters ([#1578]) ### Fixed - **registry**: Updated `thread-local` to v1.1.4 ([#1858]) Thanks to new contributor @matze for contributing to this release! [RUSTSEC-2022-0006]: https://rustsec.org/advisories/RUSTSEC-2022-0006 [#1578]: #1578 [#1858]: #1858
# 0.3.7 (Jan 25, 2022) This release adds combinators for combining filters. Additionally, this release also updates the `thread-local` crate to v1.1.4, fixing warnings for the security advisory [RUSTSEC-2022-0006]. Note that previous versions of `tracing-subscriber` did not use any of the `thread-local` crate's APIs effected by the vulnerability. However, updating the version fixes warnings emitted by `cargo audit` and similar tools. ### Added - **filter**: Added combinators for combining filters ([#1578]) ### Fixed - **registry**: Updated `thread-local` to v1.1.4 ([#1858]) Thanks to new contributor @matze for contributing to this release! [RUSTSEC-2022-0006]: https://rustsec.org/advisories/RUSTSEC-2022-0006 [#1578]: #1578 [#1858]: #1858
## Motivation In some cases, it can be useful to express a more complex filtering behavior by composing multiple filters. This is especially useful when re-using the same logic in multiple filters. ## Solution This branch adds a new `FilterExt` extension trait with combinators for composing filters. The current set of combinators are `And` (enables spans/events that are enabled by *both* filters), `Or` (enables any span or event enabled by *either* filter), and `Not` (negate the output of a filter). Signed-off-by: Eliza Weisman <eliza@buoyant.io>
# 0.3.7 (Jan 25, 2022) This release adds combinators for combining filters. Additionally, this release also updates the `thread-local` crate to v1.1.4, fixing warnings for the security advisory [RUSTSEC-2022-0006]. Note that previous versions of `tracing-subscriber` did not use any of the `thread-local` crate's APIs effected by the vulnerability. However, updating the version fixes warnings emitted by `cargo audit` and similar tools. ### Added - **filter**: Added combinators for combining filters ([tokio-rs#1578]) ### Fixed - **registry**: Updated `thread-local` to v1.1.4 ([tokio-rs#1858]) Thanks to new contributor @matze for contributing to this release! [RUSTSEC-2022-0006]: https://rustsec.org/advisories/RUSTSEC-2022-0006 [tokio-rs#1578]: tokio-rs#1578 [tokio-rs#1858]: tokio-rs#1858
This isn't quite done yet, but I thought it was kinda cool.