Clarify filter.not() w.r.t. event_enabled#2251
Conversation
| /// Essentially, where a normal filter is roughly | ||
| /// | ||
| /// ```ignore (psuedo-code) | ||
| /// // for spans | ||
| /// match callsite_enabled() { | ||
| /// ALWAYS => on_span(), | ||
| /// SOMETIMES => if enabled() { on_span() }, | ||
| /// NEVER => (), | ||
| /// } | ||
| /// // for events | ||
| /// match callsite_enabled() { | ||
| /// ALWAYS => on_event(), | ||
| /// SOMETIMES => if enabled() && event_enabled() { on_event() }, | ||
| /// NEVER => (), | ||
| /// } | ||
| /// ``` | ||
| /// | ||
| /// an inverted filter is roughly | ||
| /// | ||
| /// ```ignore (psuedo-code) | ||
| /// // for spans | ||
| /// match callsite_enabled() { | ||
| /// ALWAYS => (), | ||
| /// SOMETIMES => if !enabled() { on_span() }, | ||
| /// NEVER => on_span(), | ||
| /// } | ||
| /// // for events | ||
| /// match callsite_enabled() { | ||
| /// ALWAYS => (), | ||
| /// SOMETIMES => if !enabled() { on_event() }, | ||
| /// NEVER => on_event(), | ||
| /// } | ||
| /// ``` |
There was a problem hiding this comment.
i'm not completely sure how i feel about the use of Rust-like pseudocode in the documentation; it seems like it could potentially create some confusion if people incorrectly interpret it actual code. do you think it would make sense to document this as a Markdown table or something, instead? i'm fine with this if it's really the best way to document this behavior, but i am mildly skeptical about it...
There was a problem hiding this comment.
The thing which is easier explained with pseudocode is the short circuiting behavior. Also, just trying to reason about using a filter on top of a layer which reports global filtering is overloading my brain atm, so...
That said, here's an attempt at a table to communicate the same information plus a bit:
Normal
F::callsite_enabled |
F::enabled |
S::enabled |
F::event_enabled |
S::event_enabled |
lifecycle callbacks |
|---|---|---|---|---|---|
ALWAYS |
✗ | ✗ | ✗ | ✗ | ✓ |
NEVER |
✗ | ✗ | ✗ | ✗ | ✗ |
SOMETIMES |
true |
✓ | ✗ | ✗ | ✓ (span) |
SOMETIMES |
true |
✓ | true |
✓ | ✓ (event) |
SOMETIMES |
true |
✓ | false |
✗ | ✗ (event) |
SOMETIMES |
false |
✗ | ✗ | ✗ | ✗ |
Not
F::callsite_enabled |
F::enabled |
S::enabled |
F::event_enabled |
S::event_enabled |
lifecycle callbacks |
|---|---|---|---|---|---|
ALWAYS |
✗ | ✗ | ✗ | ✗ | ✗ |
NEVER |
✗ | ✗ | ✗ | ✗ | ✓ |
SOMETIMES |
true |
✗ | ✗ | ✗ | ✗ |
SOMETIMES |
false |
✓ | ✗ | ✗ | ✓ (span) |
SOMETIMES |
false |
✓ | ✗ | ✓ | ✓ (event) |
Pure logical filter inverse without time travel
F::callsite_enabled |
F::enabled |
S::enabled |
F::event_enabled |
S::event_enabled |
lifecycle callbacks |
|---|---|---|---|---|---|
ALWAYS |
✗ | ✗ | ✗ | ✗ | ✗ |
NEVER |
✗ | ✗ | ✗ | ✗ | ✓ |
SOMETIMES |
true |
✗ | ✗ | ✗ | ✗ (span) |
SOMETIMES |
true |
✓ | true |
✗ | ✗ (event) |
SOMETIMES |
true |
✓ | false |
✓ | ✓ (event) |
SOMETIMES |
false |
✓ | ✗ | ✗ | ✓ (span) |
SOMETIMES |
false |
✓ | ✗ | ✓ | ✓ (event) |
I wish I could give a nice visual diff between the tables, but this'll have to do: diff Not to "logical":
| `F::callsite_enabled` | `F::enabled` | `S::enabled` | `F::event_enabled` | `S::event_enabled` | lifecycle callbacks |
| :-: | :-: | :-: | :-: | :-: | :-: |
| `ALWAYS` | ✗ | ✗ | ✗ | ✗ | ✗ |
| `NEVER` | ✗ | ✗ | ✗ | ✗ | ✓ |
-| `SOMETIMES` | `true` | ✗ | ✗ | ✗ | ✗ |
+| `SOMETIMES` | `true` | ✗ | ✗ | ✗ | ✗ (span) |
+| `SOMETIMES` | `true` | ✓ | `true` | ✗ | ✗ (event) |
+| `SOMETIMES` | `true` | ✓ | `false` | ✓ | ✓ (event) |
| `SOMETIMES` | `false` | ✓ | ✗ | ✗ | ✓ (span) |
| `SOMETIMES` | `false` | ✓ | ✗ | ✓ | ✓ (event) |There was a problem hiding this comment.
hmm, yeah, that's...not great. i'm fine with the pseudocode instead, then.
There was a problem hiding this comment.
(It's worth noting that the pseudocode doesn't contain the S::* information from the tables, so for a fair comparison drop those two columns. But yeah, communicating short circuiting in a table is hard.)
There was a problem hiding this comment.
You mentioned thinking maybe we should've made event_enabled return Option<bool>; the "correct" behavior I think would've been for (a time machine and) enabled to also return Interest, then iff that returns a sometimes() calling span_enabled/event_enabled for a final determination.
So roughly
- Cached once per callsite,
callsite_enabled. - Each time
span!is entered:- if callsite enabled always: Evaluate fields. Return active span.
- if callsite enabled sometimes:
- Check
enabled. - if
enabledalways: Evaluate fields. Return active span. - if
enabledsometimes:- Evaluate fields.
- If
span_enabled: Return active span.
- Check
- Return disabled span.
- Each time
event!is entered:- if callsite enabled always: Evaluate fields. Emit event.
- if callsite enabled sometimes:
- Check
enabled. - If
enabledalways: Evaluate fields. Emit event. - If
enabledsometimes:- Evaluate fields.
- If
event_enabled: Emit event.
- Check
In terms of signatures,
Collectregister_callsite(&self, &Metadata) -> Interestenabled(&self, &Metadata) -> Interestspan_enabled(&self, &Attributes) -> boolevent_enabled(&self, &Attributes) -> bool
Subscribe(but only local filtering)register_callsite(&self, &Metadata) -> Interestenabled(&self, &Metadata, &Context) -> Interestspan_enabled(&self, &Attributes, &Context) -> boolevent_enabled(&self, &Attributes, &Context) -> bool
- Per-layer filtering is done by layering
Subscribein a tree fashion.
(I'd personally also say that the enabled functions not being called when !interest.is_sometimes() is purely an optimization and you are not allowed to rely on this being true. This isn't necessary, but it's imho easier to reason about for wrapping collectors/filters.)
(Yes, there's complexity in the system I'm not fully aware of that probably makes that too simple.)
Co-authored-by: David Barsky <me@davidbarsky.com>
hawkw
left a comment
There was a problem hiding this comment.
noticed a misspelling that got duplicated a bunch of times (presumably by copying and pasting it). besides that, looks good to me!
* Explain filter.not() w.r.t. event_enabled Co-authored-by: David Barsky <me@davidbarsky.com> Co-authored-by: Eliza Weisman <eliza@buoyant.io>
* Explain filter.not() w.r.t. event_enabled Co-authored-by: David Barsky <me@davidbarsky.com> Co-authored-by: Eliza Weisman <eliza@buoyant.io>
* Explain filter.not() w.r.t. event_enabled Co-authored-by: David Barsky <me@davidbarsky.com> Co-authored-by: Eliza Weisman <eliza@buoyant.io>
# 0.3.16 (October 6, 2022) This release of `tracing-subscriber` fixes a regression introduced in [v0.3.15][subscriber-0.3.15] where `Option::None`'s `Layer` implementation would set the max level hint to `OFF`. In addition, it adds several new APIs, including the `Filter::event_enabled` method for filtering events based on fields values, and the ability to log internal errors that occur when writing a log line. This release also replaces the dependency on the unmaintained [`ansi-term`] crate with the [`nu-ansi-term`] crate, resolving an *informational* security advisory ([RUSTSEC-2021-0139] for [`ansi-term`]'s maintainance status. This increases the minimum supported Rust version (MSRV) to Rust 1.50+, although the crate should still compile for the previous MSRV of Rust 1.49+ when the `ansi` feature is not enabled. ### Fixed - **layer**: `Option::None`'s `Layer` impl always setting the `max_level_hint` to `LevelFilter::OFF` (#2321) - Compilation with `-Z minimal versions` (#2246) - **env-filter**: Clarify that disabled level warnings are emitted by `tracing-subscriber` (#2285) ### Added - **fmt**: Log internal errors to `stderr` if writing a log line fails (#2102) - **fmt**: `FmtLayer::log_internal_errors` and `FmtSubscriber::log_internal_errors` methods for configuring whether internal writer errors are printed to `stderr` (#2102) - **fmt**: `#[must_use]` attributes on builders to warn if a `Subscriber` is configured but not set as the default subscriber (#2239) - **filter**: `Filter::event_enabled` method for filtering an event based on its fields (#2245, #2251) - **filter**: `Targets::default_level` accessor (#2242) ### Changed - **ansi**: Replaced dependency on unmaintained `ansi-term` crate with `nu-ansi-term` ((#2287, fixes informational advisory [RUSTSEC-2021-0139]) - `tracing-core`: updated to [0.1.30][core-0.1.30] - Minimum Supported Rust Version (MSRV) increased to Rust 1.50+ (when the `ansi`) feature flag is enabled (#2287) ### Documented - **fmt**: Correct inaccuracies in `fmt::init` documentation (#2224) - **filter**: Fix incorrect doc link in `filter::Not` combinator (#2249) Thanks to new contributors @cgbur, @DesmondWillowbrook, @RalfJung, and @poliorcetics, as well as returning contributors @CAD97, @connec, @jswrenn, @guswynn, and @bryangarza, for contributing to this release! [nu-ansi-term]: https://github.com/nushell/nu-ansi-term [ansi_term]: https://github.com/ogham/rust-ansi-term [RUSTSEC-2021-0139]: https://rustsec.org/advisories/RUSTSEC-2021-0139.html [core-0.1.30]: https://github.com/tokio-rs/tracing/releases/tag/tracing-core-0.1.30 [subscriber-0.3.15]: https://github.com/tokio-rs/tracing/releases/tag/tracing-subscriber-0.3.15
# 0.3.16 (October 6, 2022) This release of `tracing-subscriber` fixes a regression introduced in [v0.3.15][subscriber-0.3.15] where `Option::None`'s `Layer` implementation would set the max level hint to `OFF`. In addition, it adds several new APIs, including the `Filter::event_enabled` method for filtering events based on fields values, and the ability to log internal errors that occur when writing a log line. This release also replaces the dependency on the unmaintained [`ansi-term`] crate with the [`nu-ansi-term`] crate, resolving an *informational* security advisory ([RUSTSEC-2021-0139] for [`ansi-term`]'s maintainance status. This increases the minimum supported Rust version (MSRV) to Rust 1.50+, although the crate should still compile for the previous MSRV of Rust 1.49+ when the `ansi` feature is not enabled. ### Fixed - **layer**: `Option::None`'s `Layer` impl always setting the `max_level_hint` to `LevelFilter::OFF` (#2321) - Compilation with `-Z minimal versions` (#2246) - **env-filter**: Clarify that disabled level warnings are emitted by `tracing-subscriber` (#2285) ### Added - **fmt**: Log internal errors to `stderr` if writing a log line fails (#2102) - **fmt**: `FmtLayer::log_internal_errors` and `FmtSubscriber::log_internal_errors` methods for configuring whether internal writer errors are printed to `stderr` (#2102) - **fmt**: `#[must_use]` attributes on builders to warn if a `Subscriber` is configured but not set as the default subscriber (#2239) - **filter**: `Filter::event_enabled` method for filtering an event based on its fields (#2245, #2251) - **filter**: `Targets::default_level` accessor (#2242) ### Changed - **ansi**: Replaced dependency on unmaintained `ansi-term` crate with `nu-ansi-term` ((#2287, fixes informational advisory [RUSTSEC-2021-0139]) - `tracing-core`: updated to [0.1.30][core-0.1.30] - Minimum Supported Rust Version (MSRV) increased to Rust 1.50+ (when the `ansi`) feature flag is enabled (#2287) ### Documented - **fmt**: Correct inaccuracies in `fmt::init` documentation (#2224) - **filter**: Fix incorrect doc link in `filter::Not` combinator (#2249) Thanks to new contributors @cgbur, @DesmondWillowbrook, @RalfJung, and @poliorcetics, as well as returning contributors @CAD97, @connec, @jswrenn, @guswynn, and @bryangarza, for contributing to this release! [nu-ansi-term]: https://github.com/nushell/nu-ansi-term [ansi_term]: https://github.com/ogham/rust-ansi-term [RUSTSEC-2021-0139]: https://rustsec.org/advisories/RUSTSEC-2021-0139.html [core-0.1.30]: https://github.com/tokio-rs/tracing/releases/tag/tracing-core-0.1.30 [subscriber-0.3.15]: https://github.com/tokio-rs/tracing/releases/tag/tracing-subscriber-0.3.15
# 0.3.16 (October 6, 2022) This release of `tracing-subscriber` fixes a regression introduced in [v0.3.15][subscriber-0.3.15] where `Option::None`'s `Layer` implementation would set the max level hint to `OFF`. In addition, it adds several new APIs, including the `Filter::event_enabled` method for filtering events based on fields values, and the ability to log internal errors that occur when writing a log line. This release also replaces the dependency on the unmaintained [`ansi-term`] crate with the [`nu-ansi-term`] crate, resolving an *informational* security advisory ([RUSTSEC-2021-0139] for [`ansi-term`]'s maintainance status. This increases the minimum supported Rust version (MSRV) to Rust 1.50+, although the crate should still compile for the previous MSRV of Rust 1.49+ when the `ansi` feature is not enabled. ### Fixed - **layer**: `Option::None`'s `Layer` impl always setting the `max_level_hint` to `LevelFilter::OFF` (#2321) - Compilation with `-Z minimal versions` (#2246) - **env-filter**: Clarify that disabled level warnings are emitted by `tracing-subscriber` (#2285) ### Added - **fmt**: Log internal errors to `stderr` if writing a log line fails (#2102) - **fmt**: `FmtLayer::log_internal_errors` and `FmtSubscriber::log_internal_errors` methods for configuring whether internal writer errors are printed to `stderr` (#2102) - **fmt**: `#[must_use]` attributes on builders to warn if a `Subscriber` is configured but not set as the default subscriber (#2239) - **filter**: `Filter::event_enabled` method for filtering an event based on its fields (#2245, #2251) - **filter**: `Targets::default_level` accessor (#2242) ### Changed - **ansi**: Replaced dependency on unmaintained `ansi-term` crate with `nu-ansi-term` ((#2287, fixes informational advisory [RUSTSEC-2021-0139]) - `tracing-core`: updated to [0.1.30][core-0.1.30] - Minimum Supported Rust Version (MSRV) increased to Rust 1.50+ (when the `ansi`) feature flag is enabled (#2287) ### Documented - **fmt**: Correct inaccuracies in `fmt::init` documentation (#2224) - **filter**: Fix incorrect doc link in `filter::Not` combinator (#2249) Thanks to new contributors @cgbur, @DesmondWillowbrook, @RalfJung, and @poliorcetics, as well as returning contributors @CAD97, @connec, @jswrenn, @guswynn, and @bryangarza, for contributing to this release! [nu-ansi-term]: https://github.com/nushell/nu-ansi-term [ansi_term]: https://github.com/ogham/rust-ansi-term [RUSTSEC-2021-0139]: https://rustsec.org/advisories/RUSTSEC-2021-0139.html [core-0.1.30]: https://github.com/tokio-rs/tracing/releases/tag/tracing-core-0.1.30 [subscriber-0.3.15]: https://github.com/tokio-rs/tracing/releases/tag/tracing-subscriber-0.3.15
…s#2251) * Explain filter.not() w.r.t. event_enabled Co-authored-by: David Barsky <me@davidbarsky.com> Co-authored-by: Eliza Weisman <eliza@buoyant.io>
# 0.3.16 (October 6, 2022) This release of `tracing-subscriber` fixes a regression introduced in [v0.3.15][subscriber-0.3.15] where `Option::None`'s `Layer` implementation would set the max level hint to `OFF`. In addition, it adds several new APIs, including the `Filter::event_enabled` method for filtering events based on fields values, and the ability to log internal errors that occur when writing a log line. This release also replaces the dependency on the unmaintained [`ansi-term`] crate with the [`nu-ansi-term`] crate, resolving an *informational* security advisory ([RUSTSEC-2021-0139] for [`ansi-term`]'s maintainance status. This increases the minimum supported Rust version (MSRV) to Rust 1.50+, although the crate should still compile for the previous MSRV of Rust 1.49+ when the `ansi` feature is not enabled. ### Fixed - **layer**: `Option::None`'s `Layer` impl always setting the `max_level_hint` to `LevelFilter::OFF` (tokio-rs#2321) - Compilation with `-Z minimal versions` (tokio-rs#2246) - **env-filter**: Clarify that disabled level warnings are emitted by `tracing-subscriber` (tokio-rs#2285) ### Added - **fmt**: Log internal errors to `stderr` if writing a log line fails (tokio-rs#2102) - **fmt**: `FmtLayer::log_internal_errors` and `FmtSubscriber::log_internal_errors` methods for configuring whether internal writer errors are printed to `stderr` (tokio-rs#2102) - **fmt**: `#[must_use]` attributes on builders to warn if a `Subscriber` is configured but not set as the default subscriber (tokio-rs#2239) - **filter**: `Filter::event_enabled` method for filtering an event based on its fields (tokio-rs#2245, tokio-rs#2251) - **filter**: `Targets::default_level` accessor (tokio-rs#2242) ### Changed - **ansi**: Replaced dependency on unmaintained `ansi-term` crate with `nu-ansi-term` ((tokio-rs#2287, fixes informational advisory [RUSTSEC-2021-0139]) - `tracing-core`: updated to [0.1.30][core-0.1.30] - Minimum Supported Rust Version (MSRV) increased to Rust 1.50+ (when the `ansi`) feature flag is enabled (tokio-rs#2287) ### Documented - **fmt**: Correct inaccuracies in `fmt::init` documentation (tokio-rs#2224) - **filter**: Fix incorrect doc link in `filter::Not` combinator (tokio-rs#2249) Thanks to new contributors @cgbur, @DesmondWillowbrook, @RalfJung, and @poliorcetics, as well as returning contributors @CAD97, @connec, @jswrenn, @guswynn, and @bryangarza, for contributing to this release! [nu-ansi-term]: https://github.com/nushell/nu-ansi-term [ansi_term]: https://github.com/ogham/rust-ansi-term [RUSTSEC-2021-0139]: https://rustsec.org/advisories/RUSTSEC-2021-0139.html [core-0.1.30]: https://github.com/tokio-rs/tracing/releases/tag/tracing-core-0.1.30 [subscriber-0.3.15]: https://github.com/tokio-rs/tracing/releases/tag/tracing-subscriber-0.3.15
No description provided.