-
Notifications
You must be signed in to change notification settings - Fork 726
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
tracing-core: Add Dispatch::downgrade()
and WeakDispatch
#2293
Conversation
@jswrenn if this won't get merged soon, let's point the PR (or make a separate one) for the |
why does this need to be pointed at the |
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.
overall, this seems good to me! i had a couple minor thoughts that i commented on.
@jswrenn any updates on this? |
Allows collectors and subscribers to stash their own `Dispatch` without causing a memory leak.
d50d6f8
to
03786ca
Compare
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.
some minor suggestions (mostly docs tweaks). once those are addressed, though, this looks good to me!
I'd like to get this one merged before cutting another |
Thanks! I agree with all your suggestions! |
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.
okay, i've addressed the remaining documentation suggestions, so this looks good to me!
This was creating an `&&'static (dyn Collect + ...)` rather than copying the `&'static (dyn Collect + ...)` into the `WeakDispatch` struct, and the reference to a static reference to a `dyn Collect + ...` doesn't forward trait impls. Removing the `&` un-breaks this.
Allows `Subscriber`s and `Layer`s to stash their own `Dispatch` without causing a memory leak. ## Motivation Resolves a shortcoming of #2269: that it's impossible for `Subscriber`s or `Layer`s to stash a copy of their own `Dispatch` without creating a reference cycle that would prevent them from being dropped. ## Solution Introduces `WeakDispatch` (analogous to `std::sync::Weak`) that holds a weak pointer to a `Subscriber`. `WeakDispatch` can be created via `Dispatch::downgrade`, and can be transformed into a `Dispatch` via `WeakDispatch::upgrade`. Co-authored-by: Eliza Weisman <[email protected]>
Allows `Subscriber`s and `Layer`s to stash their own `Dispatch` without causing a memory leak. ## Motivation Resolves a shortcoming of #2269: that it's impossible for `Subscriber`s or `Layer`s to stash a copy of their own `Dispatch` without creating a reference cycle that would prevent them from being dropped. ## Solution Introduces `WeakDispatch` (analogous to `std::sync::Weak`) that holds a weak pointer to a `Subscriber`. `WeakDispatch` can be created via `Dispatch::downgrade`, and can be transformed into a `Dispatch` via `WeakDispatch::upgrade`. Co-authored-by: Eliza Weisman <[email protected]>
Allows `Subscriber`s and `Layer`s to stash their own `Dispatch` without causing a memory leak. ## Motivation Resolves a shortcoming of #2269: that it's impossible for `Subscriber`s or `Layer`s to stash a copy of their own `Dispatch` without creating a reference cycle that would prevent them from being dropped. ## Solution Introduces `WeakDispatch` (analogous to `std::sync::Weak`) that holds a weak pointer to a `Subscriber`. `WeakDispatch` can be created via `Dispatch::downgrade`, and can be transformed into a `Dispatch` via `WeakDispatch::upgrade`. Co-authored-by: Eliza Weisman <[email protected]>
Allows `Subscriber`s and `Layer`s to stash their own `Dispatch` without causing a memory leak. ## Motivation Resolves a shortcoming of #2269: that it's impossible for `Subscriber`s or `Layer`s to stash a copy of their own `Dispatch` without creating a reference cycle that would prevent them from being dropped. ## Solution Introduces `WeakDispatch` (analogous to `std::sync::Weak`) that holds a weak pointer to a `Subscriber`. `WeakDispatch` can be created via `Dispatch::downgrade`, and can be transformed into a `Dispatch` via `WeakDispatch::upgrade`. Co-authored-by: Eliza Weisman <[email protected]>
# 0.1.30 (October 6, 2022) This release of `tracing-core` adds a new `on_register_dispatch` method to the `Subscriber` trait to allow the `Subscriber` to perform initialization after being registered as a `Dispatch`, and a `WeakDispatch` type to allow a `Subscriber` to store its own `Dispatch` without creating reference count cycles. ### Added - `Subscriber::on_register_dispatch` method ([#2269]) - `WeakDispatch` type and `Dispatch::downgrade()` function ([#2293]) Thanks to @jswrenn for contributing to this release! [#2269]: #2269 [#2293]: #2293
# 0.1.30 (October 6, 2022) This release of `tracing-core` adds a new `on_register_dispatch` method to the `Subscriber` trait to allow the `Subscriber` to perform initialization after being registered as a `Dispatch`, and a `WeakDispatch` type to allow a `Subscriber` to store its own `Dispatch` without creating reference count cycles. ### Added - `Subscriber::on_register_dispatch` method ([#2269]) - `WeakDispatch` type and `Dispatch::downgrade()` function ([#2293]) Thanks to @jswrenn for contributing to this release! [#2269]: #2269 [#2293]: #2293
# 0.1.37 (October 6, 2022) This release of `tracing` incorporates changes from `tracing-core` [v0.1.30][core-0.1.30] and `tracing-attributes` [v0.1.23][0.1.23], including the new `Subscriber::on_register_dispatch` method for performing late initialization after a `Subscriber` is registered as a `Dispatch`, and bugfixes for the `#[instrument]` attribute. Additionally, it fixes instances of the `bare_trait_objects` lint, which is now a warning on `tracing`'s MSRV and will become an error in the next edition. ### Fixed - **attributes**: Incorrect handling of inner attributes in `#[instrument]`ed functions (#2307) - **attributes**: Incorrect location of compiler diagnostic spans generated for type errors in `#[instrument]`ed `async fn`s (#2270) - **attributes**: Updated `syn` dependency to fix compilation with `-Z minimal-versions` (#2246) - `bare_trait_objects` warning in `valueset!` macro expansion (#2308) ### Added - **core**: `Subscriber::on_register_dispatch` method (#2269) - **core**: `WeakDispatch` type and `Dispatch::downgrade()` function (#2293) ### Changed - `tracing-core`: updated to [0.1.30][core-0.1.30] - `tracing-attributes`: updated to [0.1.23][attrs-0.1.23] ### Documented - Added [`tracing-web`] and [`reqwest-tracing`] to related crates (#2283], [#2331) Thanks to new contributors @compiler-errors, @e-nomem, @WorldSEnder, @Xiami2012, and @tl-rodrigo-gryzinski, as well as @jswrenn and @CAD97, for contributing to this release! [core-0.1.30]: https://github.com/tokio-rs/tracing/releases/tag/tracing-core-0.1.30 [attrs-0.1.23]: https://github.com/tokio-rs/tracing/releases/tag/tracing-attributes-0.1.23 [`tracing-web`]: https://crates.io/crates/tracing-web/ [`reqwest-tracing`]: https://crates.io/crates/reqwest-tracing/
# 0.1.37 (October 6, 2022) This release of `tracing` incorporates changes from `tracing-core` [v0.1.30][core-0.1.30] and `tracing-attributes` [v0.1.23][attrs-0.1.23], including the new `Subscriber::on_register_dispatch` method for performing late initialization after a `Subscriber` is registered as a `Dispatch`, and bugfixes for the `#[instrument]` attribute. Additionally, it fixes instances of the `bare_trait_objects` lint, which is now a warning on `tracing`'s MSRV and will become an error in the next edition. ### Fixed - **attributes**: Incorrect handling of inner attributes in `#[instrument]`ed functions (#2307) - **attributes**: Incorrect location of compiler diagnostic spans generated for type errors in `#[instrument]`ed `async fn`s (#2270) - **attributes**: Updated `syn` dependency to fix compilation with `-Z minimal-versions` (#2246) - `bare_trait_objects` warning in `valueset!` macro expansion (#2308) ### Added - **core**: `Subscriber::on_register_dispatch` method (#2269) - **core**: `WeakDispatch` type and `Dispatch::downgrade()` function (#2293) ### Changed - `tracing-core`: updated to [0.1.30][core-0.1.30] - `tracing-attributes`: updated to [0.1.23][attrs-0.1.23] ### Documented - Added [`tracing-web`] and [`reqwest-tracing`] to related crates (#2283, #2331) Thanks to new contributors @compiler-errors, @e-nomem, @WorldSEnder, @Xiami2012, and @tl-rodrigo-gryzinski, as well as @jswrenn and @CAD97, for contributing to this release! [core-0.1.30]: https://github.com/tokio-rs/tracing/releases/tag/tracing-core-0.1.30 [attrs-0.1.23]: https://github.com/tokio-rs/tracing/releases/tag/tracing-attributes-0.1.23 [`tracing-web`]: https://crates.io/crates/tracing-web/ [`reqwest-tracing`]: https://crates.io/crates/reqwest-tracing/
)" This reverts commit a0824d3 (PR #2247). As discussed in [this comment][1], the implementation for `Arc`s may cause subtly incorrect behavior if actually used, due to the `&mut self` receiver of the `LookupSpan::register_filter` method, since the `Arc` cannot be mutably borrowed if any clones of it exist. The APIs added in PRs #2269 and #2293 offer an alternative solution to the same problems this change was intended to solve, and --- since this change hasn't been published yet --- it can safely be reverted. [1]: https://giethub.com/tokio-rs/tracing/pull/2247#issuecomment-1199924876
how to use |
Allows `Subscriber`s and `Layer`s to stash their own `Dispatch` without causing a memory leak. ## Motivation Resolves a shortcoming of tokio-rs#2269: that it's impossible for `Subscriber`s or `Layer`s to stash a copy of their own `Dispatch` without creating a reference cycle that would prevent them from being dropped. ## Solution Introduces `WeakDispatch` (analogous to `std::sync::Weak`) that holds a weak pointer to a `Subscriber`. `WeakDispatch` can be created via `Dispatch::downgrade`, and can be transformed into a `Dispatch` via `WeakDispatch::upgrade`. Co-authored-by: Eliza Weisman <[email protected]>
# 0.1.30 (October 6, 2022) This release of `tracing-core` adds a new `on_register_dispatch` method to the `Subscriber` trait to allow the `Subscriber` to perform initialization after being registered as a `Dispatch`, and a `WeakDispatch` type to allow a `Subscriber` to store its own `Dispatch` without creating reference count cycles. ### Added - `Subscriber::on_register_dispatch` method ([tokio-rs#2269]) - `WeakDispatch` type and `Dispatch::downgrade()` function ([tokio-rs#2293]) Thanks to @jswrenn for contributing to this release! [tokio-rs#2269]: tokio-rs#2269 [tokio-rs#2293]: tokio-rs#2293
# 0.1.37 (October 6, 2022) This release of `tracing` incorporates changes from `tracing-core` [v0.1.30][core-0.1.30] and `tracing-attributes` [v0.1.23][attrs-0.1.23], including the new `Subscriber::on_register_dispatch` method for performing late initialization after a `Subscriber` is registered as a `Dispatch`, and bugfixes for the `#[instrument]` attribute. Additionally, it fixes instances of the `bare_trait_objects` lint, which is now a warning on `tracing`'s MSRV and will become an error in the next edition. ### Fixed - **attributes**: Incorrect handling of inner attributes in `#[instrument]`ed functions (tokio-rs#2307) - **attributes**: Incorrect location of compiler diagnostic spans generated for type errors in `#[instrument]`ed `async fn`s (tokio-rs#2270) - **attributes**: Updated `syn` dependency to fix compilation with `-Z minimal-versions` (tokio-rs#2246) - `bare_trait_objects` warning in `valueset!` macro expansion (tokio-rs#2308) ### Added - **core**: `Subscriber::on_register_dispatch` method (tokio-rs#2269) - **core**: `WeakDispatch` type and `Dispatch::downgrade()` function (tokio-rs#2293) ### Changed - `tracing-core`: updated to [0.1.30][core-0.1.30] - `tracing-attributes`: updated to [0.1.23][attrs-0.1.23] ### Documented - Added [`tracing-web`] and [`reqwest-tracing`] to related crates (tokio-rs#2283, tokio-rs#2331) Thanks to new contributors @compiler-errors, @e-nomem, @WorldSEnder, @Xiami2012, and @tl-rodrigo-gryzinski, as well as @jswrenn and @CAD97, for contributing to this release! [core-0.1.30]: https://github.com/tokio-rs/tracing/releases/tag/tracing-core-0.1.30 [attrs-0.1.23]: https://github.com/tokio-rs/tracing/releases/tag/tracing-attributes-0.1.23 [`tracing-web`]: https://crates.io/crates/tracing-web/ [`reqwest-tracing`]: https://crates.io/crates/reqwest-tracing/
…kio-rs#2247)" This reverts commit a0824d3 (PR tokio-rs#2247). As discussed in [this comment][1], the implementation for `Arc`s may cause subtly incorrect behavior if actually used, due to the `&mut self` receiver of the `LookupSpan::register_filter` method, since the `Arc` cannot be mutably borrowed if any clones of it exist. The APIs added in PRs tokio-rs#2269 and tokio-rs#2293 offer an alternative solution to the same problems this change was intended to solve, and --- since this change hasn't been published yet --- it can safely be reverted. [1]: https://giethub.com/tokio-rs/tracing/pull/2247#issuecomment-1199924876
Allows collectors and subscribers to stash their own
Dispatch
without causing a memory leak.Motivation
Resolves a shortcoming of #2269: that it's impossible for collectors or subscribers to stash a copy of their own
Dispatch
without creating a reference cycle that would prevent them from being dropped.Solution
Introduces
WeakDispatch
(analogous tostd::sync::Weak
) that holds a weak pointer to a collector.WeakDispatch
can be created viaDispatch::downgrade
, and can be transformed into aDispatch
viaWeakDispatch::upgrade
.