subscriber: change registry exit to decrement local span ref only#3331
subscriber: change registry exit to decrement local span ref only#3331hds merged 4 commits intotokio-rs:mainfrom
Conversation
|
Note that changing |
|
FWIW I can also confirm this fixes the issue I've seen in real-world situations so this seems like a very simple fix that also improves performance. Great job! |
|
@jplatte are you able to review this change? |
|
Hey, I'm sorry but I don't actually have a good understanding of tracing internals at all. I've just been reviewing and merging PRs that do not need much knowledge of the internals. I'm afraid this will have to wait for @hds. |
|
Hey everyone. Just to let you know that I'm looking at this PR now. Hopefully get through it in the next couple of days. |
hds
left a comment
There was a problem hiding this comment.
Thank you very much for your PR! I think it makes sense, I a couple of comments on the test.
|
Thanks will try to get feedback addressed later today 👍 |
Co-authored-by: Hayden Stainsby <hds@caffeineconcepts.com>
hds
left a comment
There was a problem hiding this comment.
Thanks for your work on this PR!
# 0.3.21 (November 30, 2025) ### Fixed - Change registry exit to decrement local span ref only ([#3331]) - Make Layered propagate `on_register_dispatch` ([#3379]) ### Performance - Remove `clone_span` on enter (#3289) ### Documented - Fix a few small things in the format module ([#3339]) - Fix extra closing brace in layer docs ([#3350]) - Fix link in `FmtSpan` docs ([#3411]) [#3331]: https://github.com/tokio-rs/tracing/pull/#3331 [#3339]: https://github.com/tokio-rs/tracing/pull/#3339 [#3350]: https://github.com/tokio-rs/tracing/pull/#3350 [#3379]: https://github.com/tokio-rs/tracing/pull/#3379 [#3411]: https://github.com/tokio-rs/tracing/pull/#3411
# 0.3.21 (November 30, 2025) ### Fixed - Change registry exit to decrement local span ref only ([#3331]) - Make Layered propagate `on_register_dispatch` ([#3379]) ### Performance - Remove `clone_span` on enter ([#3289]) ### Documented - Fix a few small things in the format module ([#3339]) - Fix extra closing brace in layer docs ([#3350]) - Fix link in `FmtSpan` docs ([#3411]) [#3289]: https://github.com/tokio-rs/tracing/pull/#3289 [#3331]: https://github.com/tokio-rs/tracing/pull/#3331 [#3339]: https://github.com/tokio-rs/tracing/pull/#3339 [#3350]: https://github.com/tokio-rs/tracing/pull/#3350 [#3379]: https://github.com/tokio-rs/tracing/pull/#3379 [#3411]: https://github.com/tokio-rs/tracing/pull/#3411
# 0.3.21 (November 30, 2025) ### Fixed - Change registry exit to decrement local span ref only ([#3331]) - Make Layered propagate `on_register_dispatch` ([#3379]) ### Performance - Remove `clone_span` on enter ([#3289]) ### Documented - Fix a few small things in the format module ([#3339]) - Fix extra closing brace in layer docs ([#3350]) - Fix link in `FmtSpan` docs ([#3411]) [#3289]: https://github.com/tokio-rs/tracing/pull/#3289 [#3331]: https://github.com/tokio-rs/tracing/pull/#3331 [#3339]: https://github.com/tokio-rs/tracing/pull/#3339 [#3350]: https://github.com/tokio-rs/tracing/pull/#3350 [#3379]: https://github.com/tokio-rs/tracing/pull/#3379 [#3411]: https://github.com/tokio-rs/tracing/pull/#3411
# 0.3.21 (November 26, 2025) ### Fixed - Change registry exit to decrement local span ref only ([#3331]) - Make Layered propagate `on_register_dispatch` ([#3379]) ### Changed - `tracing`: updated to 0.1.42 ([#3418]) ### Performance - Remove `clone_span` on enter ([#3289]) ### Documented - Fix a few small things in the format module ([#3339]) - Fix extra closing brace in layer docs ([#3350]) - Fix link in `FmtSpan` docs ([#3411]) [#3289]: https://github.com/tokio-rs/tracing/pull/#3289 [#3331]: https://github.com/tokio-rs/tracing/pull/#3331 [#3339]: https://github.com/tokio-rs/tracing/pull/#3339 [#3350]: https://github.com/tokio-rs/tracing/pull/#3350 [#3379]: https://github.com/tokio-rs/tracing/pull/#3379 [#3411]: https://github.com/tokio-rs/tracing/pull/#3411 [#3418]: https://github.com/tokio-rs/tracing/pull/#3418
# 0.3.21 (November 26, 2025) ### Fixed - Change registry exit to decrement local span ref only ([#3331]) - Make Layered propagate `on_register_dispatch` ([#3379]) ### Changed - `tracing`: updated to 0.1.42 ([#3418]) ### Performance - Remove `clone_span` on enter ([#3289]) ### Documented - Fix a few small things in the format module ([#3339]) - Fix extra closing brace in layer docs ([#3350]) - Fix link in `FmtSpan` docs ([#3411]) [#3289]: https://github.com/tokio-rs/tracing/pull/#3289 [#3331]: https://github.com/tokio-rs/tracing/pull/#3331 [#3339]: https://github.com/tokio-rs/tracing/pull/#3339 [#3350]: https://github.com/tokio-rs/tracing/pull/#3350 [#3379]: https://github.com/tokio-rs/tracing/pull/#3379 [#3411]: https://github.com/tokio-rs/tracing/pull/#3411 [#3418]: https://github.com/tokio-rs/tracing/pull/#3418
* also ensure that 'tracing-subscriber' has been updated to 0.3.21, which should include their attempt at fixing this bug * cf. tokio-rs/tracing#3331
* also ensure that 'tracing-subscriber' has been updated to 0.3.21, which should include their attempt at fixing this bug * cf. tokio-rs/tracing#3331
* also ensure that 'tracing-subscriber' has been updated to 0.3.21, which should include their attempt at fixing this bug * cf. tokio-rs/tracing#3331
This updates dependencies within semver bounds. In particular, it pulls in this change which unblocks support for exporting OpenTelemetry spans from `tracing`: - tokio-rs/tracing#3331
* also ensure that 'tracing-subscriber' has been updated to 0.3.21, which should include their attempt at fixing this bug * cf. tokio-rs/tracing#3331
Motivation
Fixes #3223
Solution
From my understanding, it's sufficient for
Registry::exitjust to callself.try_close()and do local bookkeeping:try_closeon the wholeLayerstack at this point anyway, a span being exited is not yet ready to close. All that is needed is to decrement the reference count within the current registry.I've added a test which spawns a thread and enters (and exits, and drops) a span created on a dispatcher not registered to that thread.
Before this patch, the test fails with the span never being closed (because there is no thread dispatcher when the span is exited, and so a reference is leaked in
Registry::exit).With this patch, the bookkeeping demonstrated in the test seems correct to me.