Skip to content
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

Implement layer::Filter for Option<Filter> #2402

Closed
wants to merge 7 commits into from

Conversation

jsgf
Copy link
Contributor

@jsgf jsgf commented Nov 29, 2022

Motivation

It's currently awkward to have an optional layer filter.

Solution

Implement Filter<S> for Option<F> where F: Filter<S>, following the example of Layer. A None layer filter passes everything through.

Also, it looks like Filter for Arc/Box doesn't pass through all the methods, so extend the filter_impl_body macro to include them.

Pass all the Filter methods through to the underlying Box/Arc Filter
rather than relying on default implementations.
Where None means "no filtering".
@jsgf jsgf requested review from hawkw and a team as code owners November 29, 2022 01:13
@jsgf jsgf changed the title Option layer filter 0.1 Implement layer Filter for Option<Filter> Nov 29, 2022
@jsgf jsgf changed the title Implement layer Filter for Option<Filter> Implement layer::Filter for Option<Filter> Nov 29, 2022
Copy link
Member

@davidbarsky davidbarsky left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am broadly in favor of this change (as a concrete example, Option<EnvFilter> will now be filter, where Option::None means that there is no filter enabled), but I think we should add documentation to https://docs.rs/tracing-subscriber/latest/tracing_subscriber/layer/index.html#per-layer-filtering that notes the implications of an Option-enabled filter. I can write those docs in a followup/on this branch.

While we're here, would you be able to add tests for a None filter? it's a bit silly, but ensuring that it's equivalent to not calling with_filter at all would help me get confidence in this, especially since layers/filters are kinda hairy!

@@ -134,7 +134,7 @@ fn gen_block<B: ToTokens>(
.into_iter()
.flat_map(|param| match param {
FnArg::Typed(PatType { pat, ty, .. }) => {
param_names(*pat, RecordType::parse_from_ty(&*ty))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for addressing the clippy lints.

@jsgf
Copy link
Contributor Author

jsgf commented Dec 8, 2022

Closing in favour of #2407 which is based on master

@jsgf jsgf closed this Dec 8, 2022
facebook-github-bot pushed a commit to facebookexperimental/rust-shed that referenced this pull request Mar 23, 2023
Summary: Import tokio-rs/tracing#2402 until it lands.

Reviewed By: zertosh

Differential Revision: D41689583

fbshipit-source-id: f1923244fcc652ba4dfcd6064aa37926a2b79bc7
facebook-github-bot pushed a commit to facebook/sapling that referenced this pull request Mar 23, 2023
Summary: Import tokio-rs/tracing#2402 until it lands.

Reviewed By: zertosh

Differential Revision: D41689583

fbshipit-source-id: f1923244fcc652ba4dfcd6064aa37926a2b79bc7
facebook-github-bot pushed a commit to facebook/fb303 that referenced this pull request Mar 23, 2023
Summary: Import tokio-rs/tracing#2402 until it lands.

Reviewed By: zertosh

Differential Revision: D41689583

fbshipit-source-id: f1923244fcc652ba4dfcd6064aa37926a2b79bc7
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants