Blanket-implement tracing::instrument::WithSubscriber#1424
Blanket-implement tracing::instrument::WithSubscriber#1424hawkw merged 1 commit intotokio-rs:v0.1.xfrom
Conversation
| } | ||
| } | ||
|
|
||
| impl<T: Sized> WithSubscriber for T {} |
There was a problem hiding this comment.
The bound here is copied from tracing-futures. It might be worth adding a Future bound to avoid polluting autocompletes too much though?
There was a problem hiding this comment.
The tracing-futures version does not have a Future bound because it also allows wrapping types implementing other traits, such as Stream, with a subscriber. However, tracing's version only provides implementations for Future, because tracing depends only on the standard library, not the futures crate. So, it should be fine to restrict the blanket impl to T: Future, here.
However, when the Stream trait eventually does make it into std, we'll probably want to add a Stream impl for WithSubscriber<T: Stream>, as well. Then, we'll have to make the blanket impl more general. Technically, I think this is a breaking change, as it could break user WithSubscriber impls for types that don't implement Future. To protect against that, I think we would need to seal the trait so that downstream code can't add WithSubscriber impls. Then, it would be fine to add a Future bound on the blanket impl, for now.
hawkw
left a comment
There was a problem hiding this comment.
Thanks, this looks good --- not having it was definitely an oversight.
In re: your comment about adding a Future bound to the blanket impl, I think we could do that, but it might require a little more complexity to avoid breaking changes if we want to add WithSubscriber impls for other traits. I left a more detailed comment as a reply to yours.
I'd be happy to merge this as-is, or we could make the additional changes I suggested in my comment, whatever you think is better?
| } | ||
| } | ||
|
|
||
| impl<T: Sized> WithSubscriber for T {} |
There was a problem hiding this comment.
The tracing-futures version does not have a Future bound because it also allows wrapping types implementing other traits, such as Stream, with a subscriber. However, tracing's version only provides implementations for Future, because tracing depends only on the standard library, not the futures crate. So, it should be fine to restrict the blanket impl to T: Future, here.
However, when the Stream trait eventually does make it into std, we'll probably want to add a Stream impl for WithSubscriber<T: Stream>, as well. Then, we'll have to make the blanket impl more general. Technically, I think this is a breaking change, as it could break user WithSubscriber impls for types that don't implement Future. To protect against that, I think we would need to seal the trait so that downstream code can't add WithSubscriber impls. Then, it would be fine to add a Future bound on the blanket impl, for now.
|
Yeah.. good point about I suppose we should just go ahead then. |
# 0.1.27 (September 13, 2021) This release adds a new [`Span::or_current`] method to aid in efficiently propagating span contexts to spawned threads or tasks. Additionally, it updates the [`tracing-core`] version to [0.1.20] and the [`tracing-attributes`] version to [0.1.16], ensuring that a number of new features in those crates are present. ### Fixed - **instrument**: Added missing `WithSubscriber` implementations for futures and other types ([#1424]) ### Added - `Span::or_current` method, to help with efficient span context propagation ([#1538]) - **attributes**: add `skip_all` option to `#[instrument]` ([#1548]) - **attributes**: record primitive types as primitive values rather than as `fmt::Debug` ([#1378]) - **core**: `NoSubscriber`, a no-op `Subscriber` implementation ([#1549]) - **core**: Added `Visit::record_f64` and support for recording floating-point values ([#1507], [#1522]) - A large number of documentation improvements and fixes ([#1369], [#1398], [#1435], [#1442], [#1524], [#1556]) Thanks to new contributors @dzvon and @mbergkvist, as well as @teozkr, @maxburke, @LukeMathWalker, and @jsgf, for contributing to this release! [`Span::or_current`]: https://docs.rs/tracing/0.1.27/tracing/struct.Span.html#method.or_current [`tracing-core`]: https://crates.io/crates/tracing-core [`tracing-attributes`]: https://crates.io/crates/tracing-attributes [`tracing-core`]: https://crates.io/crates/tracing-core [0.1.20]: https://github.com/tokio-rs/tracing/releases/tag/tracing-core-0.1.20 [0.1.16]: https://github.com/tokio-rs/tracing/releases/tag/tracing-attributes-0.1.16 [#1424]: #1424 [#1538]: #1538 [#1548]: #1548 [#1378]: #1378 [#1507]: #1507 [#1522]: #1522 [#1369]: #1369 [#1398]: #1398 [#1435]: #1435 [#1442]: #1442
# 0.1.27 (September 13, 2021) This release adds a new [`Span::or_current`] method to aid in efficiently propagating span contexts to spawned threads or tasks. Additionally, it updates the [`tracing-core`] version to [0.1.20] and the [`tracing-attributes`] version to [0.1.16], ensuring that a number of new features in those crates are present. ### Fixed - **instrument**: Added missing `WithSubscriber` implementations for futures and other types (#1424) ### Added - `Span::or_current` method, to help with efficient span context propagation (#1538) - **attributes**: add `skip_all` option to `#[instrument]` (#1548) - **attributes**: record primitive types as primitive values rather than as `fmt::Debug` (#1378) - **core**: `NoSubscriber`, a no-op `Subscriber` implementation (#1549) - **core**: Added `Visit::record_f64` and support for recording floating-point values (#1507, #1522) - A large number of documentation improvements and fixes (#1369, #1398, #1435, #1442, #1524, #1556) Thanks to new contributors @dzvon and @mbergkvist, as well as @teozkr, @maxburke, @LukeMathWalker, and @jsgf, for contributing to this release! [`Span::or_current`]: https://docs.rs/tracing/0.1.27/tracing/struct.Span.html#method.or_current [`tracing-core`]: https://crates.io/crates/tracing-core [`tracing-attributes`]: https://crates.io/crates/tracing-attributes [`tracing-core`]: https://crates.io/crates/tracing-core [0.1.20]: https://github.com/tokio-rs/tracing/releases/tag/tracing-core-0.1.20 [0.1.16]: https://github.com/tokio-rs/tracing/releases/tag/tracing-attributes-0.1.16
# 0.1.27 (September 13, 2021) This release adds a new [`Span::or_current`] method to aid in efficiently propagating span contexts to spawned threads or tasks. Additionally, it updates the [`tracing-core`] version to [0.1.20] and the [`tracing-attributes`] version to [0.1.16], ensuring that a number of new features in those crates are present. ### Fixed - **instrument**: Added missing `WithSubscriber` implementations for futures and other types (tokio-rs#1424) ### Added - `Span::or_current` method, to help with efficient span context propagation (tokio-rs#1538) - **attributes**: add `skip_all` option to `#[instrument]` (tokio-rs#1548) - **attributes**: record primitive types as primitive values rather than as `fmt::Debug` (tokio-rs#1378) - **core**: `NoSubscriber`, a no-op `Subscriber` implementation (tokio-rs#1549) - **core**: Added `Visit::record_f64` and support for recording floating-point values (tokio-rs#1507, tokio-rs#1522) - A large number of documentation improvements and fixes (tokio-rs#1369, tokio-rs#1398, tokio-rs#1435, tokio-rs#1442, tokio-rs#1524, tokio-rs#1556) Thanks to new contributors @dzvon and @mbergkvist, as well as @teozkr, @maxburke, @LukeMathWalker, and @jsgf, for contributing to this release! [`Span::or_current`]: https://docs.rs/tracing/0.1.27/tracing/struct.Span.html#method.or_current [`tracing-core`]: https://crates.io/crates/tracing-core [`tracing-attributes`]: https://crates.io/crates/tracing-attributes [`tracing-core`]: https://crates.io/crates/tracing-core [0.1.20]: https://github.com/tokio-rs/tracing/releases/tag/tracing-core-0.1.20 [0.1.16]: https://github.com/tokio-rs/tracing/releases/tag/tracing-attributes-0.1.16
This provides a blanket implementation of
WithSubscriber, as already implied by the docs, discussed at https://canary.discord.com/channels/500028886025895936/627649734592561152/850435247216001074, and already implemented bytracing-futures.Motivation
The current docs are confusing since they describe behaviour that is effectively unusable.