-
Notifications
You must be signed in to change notification settings - Fork 709
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
Forward Filtered::downcast_raw
to wrapped Layer
#1619
Conversation
If `Filtered::downcast_raw` can't resolve the type given to it, forward the type to the wrapped `Layer`'s `downcast_raw`, in case that `Layer` has overridden that method.
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.
looks great! i had a couple minor suggestions regarding the test, but take it or leave it!
use tracing_subscriber::filter::Targets; | ||
use tracing_subscriber::prelude::*; | ||
use tracing_subscriber::Layer; | ||
|
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.
it may also be nice to add a test for downcasting to the Layer
type itself, ensuring that normal downcasting works? this PR doesn't affect that, so we certainly don't need to also add it, but it might be nice to have if we're going to have a module of downcast_raw
tests. could also be added in a follow-up change!
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.
OK, I added downcast_ref_to_inner_layer_and_filter
for this. Let me know if it needs anything more.
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 looks great, thanks again!
Not to push my luck too far (so tell me to buzz off if you want), but any idea when this would make it into a crates.io release? |
I want to publish a new |
# 0.2.25 (October 5, 2021) This release fixes an issue where a `Layer` implementation's custom `downcast_raw` implementation was lost when wrapping that layer with a per-layer filter. ### Fixed - **registry**: Forward `Filtered::downcast_raw` to wrapped `Layer` ([#1619]) ### Added - Documentation improvements ([#1596], [#1601]) Thanks to @bryanburgers for contributing to this release! [#1619]: #1619 [#1601]: #1601 [#1596]: #1596
# 0.2.25 (October 5, 2021) This release fixes an issue where a `Layer` implementation's custom `downcast_raw` implementation was lost when wrapping that layer with a per-layer filter. ### Fixed - **registry**: Forward `Filtered::downcast_raw` to wrapped `Layer` ([#1619]) ### Added - Documentation improvements ([#1596], [#1601]) Thanks to @bryanburgers for contributing to this release! [#1619]: #1619 [#1601]: #1601 [#1596]: #1596
## Motivation I'm trying to implement a `Layer` that has something very similar to tracing-error's [`WithContext`](https://github.com/tokio-rs/tracing/blob/66cd79f72af5ebcb6f21a1017b6ce33bea05558d/tracing-error/src/layer.rs#L32) to support erasing types and getting access to the current span's state. To do that, I implement `Layer::downcast_raw` in [the same way that tracing-error does](https://github.com/tokio-rs/tracing/blob/66cd79f72af5ebcb6f21a1017b6ce33bea05558d/tracing-error/src/layer.rs#L55-L63). This works great when the layer is not filtered. However, once I filter the layer ```rust let filter = tracing_subscriber::filter::Targets::new().with_default(tracing::Level::INFO); let layer = MyLayer::new(); tracing_subscriber::registry().with(layer.with_filter(filter)).init(); ``` I'm not able to get a `WithContext` instance anymore, because `Filtered` [handles `downcast_raw`, and doesn't forward it](https://github.com/tokio-rs/tracing/blob/66cd79f72af5ebcb6f21a1017b6ce33bea05558d/tracing-subscriber/src/filter/layer_filters.rs#L379-L391) to `MyLayer::downcast_raw`. ## Solution If `Filtered::downcast_raw` does not know how to handle the given type, forward it to the wrapped layer's `Layer::downcast_raw` implementation. Fixes #1618
…rs#1619) ## Motivation I'm trying to implement a `Layer` that has something very similar to tracing-error's [`WithContext`](https://github.com/tokio-rs/tracing/blob/66cd79f72af5ebcb6f21a1017b6ce33bea05558d/tracing-error/src/layer.rs#L32) to support erasing types and getting access to the current span's state. To do that, I implement `Layer::downcast_raw` in [the same way that tracing-error does](https://github.com/tokio-rs/tracing/blob/66cd79f72af5ebcb6f21a1017b6ce33bea05558d/tracing-error/src/layer.rs#L55-L63). This works great when the layer is not filtered. However, once I filter the layer ```rust let filter = tracing_subscriber::filter::Targets::new().with_default(tracing::Level::INFO); let layer = MyLayer::new(); tracing_subscriber::registry().with(layer.with_filter(filter)).init(); ``` I'm not able to get a `WithContext` instance anymore, because `Filtered` [handles `downcast_raw`, and doesn't forward it](https://github.com/tokio-rs/tracing/blob/66cd79f72af5ebcb6f21a1017b6ce33bea05558d/tracing-subscriber/src/filter/layer_filters.rs#L379-L391) to `MyLayer::downcast_raw`. ## Solution If `Filtered::downcast_raw` does not know how to handle the given type, forward it to the wrapped layer's `Layer::downcast_raw` implementation. Fixes tokio-rs#1618
# 0.2.25 (October 5, 2021) This release fixes an issue where a `Layer` implementation's custom `downcast_raw` implementation was lost when wrapping that layer with a per-layer filter. ### Fixed - **registry**: Forward `Filtered::downcast_raw` to wrapped `Layer` ([tokio-rs#1619]) ### Added - Documentation improvements ([tokio-rs#1596], [tokio-rs#1601]) Thanks to @bryanburgers for contributing to this release! [tokio-rs#1619]: tokio-rs#1619 [tokio-rs#1601]: tokio-rs#1601 [tokio-rs#1596]: tokio-rs#1596
Motivation
I'm trying to implement a
Layer
that has something very similar to tracing-error'sWithContext
to support erasing types and getting access to the current span's state.To do that, I implement
Layer::downcast_raw
in the same way that tracing-error does.This works great when the layer is not filtered. However, once I filter the layer
I'm not able to get a
WithContext
instance anymore, becauseFiltered
handlesdowncast_raw
, and doesn't forward it toMyLayer::downcast_raw
.Solution
If
Filtered::downcast_raw
does not know how to handle the given type, forward it to the wrapped layer'sLayer::downcast_raw
implementation.Fixes #1618