Skip to content

Conversation

@bantonsson
Copy link

Motivation

The Layered implementation of Subscriber does not implement and propagate the on_register_dispatch callback. This means that combined layers will never have their on_register_dispatch methods called.

Solution

Implement the missing on_register_dispatch method.

@bantonsson bantonsson requested review from a team and hawkw as code owners September 19, 2025 12:00
@bantonsson
Copy link
Author

It seems like this was overlooked in #2269

Copy link
Contributor

@hds hds left a comment

Choose a reason for hiding this comment

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

Thanks for your PR! I've got a couple of comments.

}
}

impl Subscriber for TestLayer {
Copy link
Contributor

Choose a reason for hiding this comment

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

What do you think about extending the MockSubscriebr and MockLayer in tracing-mock to allow expecting on_register_dispatch?

S: Subscriber,
{
fn on_register_dispatch(&self, subscriber: &Dispatch) {
self.layer.on_register_dispatch(subscriber);
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we probably want to switch the order here, so that the actual subscriber gets the chance to register first.

@hds hds added kind/bug Something isn't working crate/subscriber Related to the `tracing-subscriber` crate labels Nov 20, 2025
@bantonsson bantonsson force-pushed the ban/make-layered-propagate-on-register-dispatch branch from a86f408 to 77aedec Compare November 21, 2025 14:57
Copy link
Contributor

@hds hds left a comment

Choose a reason for hiding this comment

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

Looking great. Thank you! I've got one Question.

/// [`tracing::subscriber::set_global_default`], so explicitly expecting
/// this is not usually necessary. However, it may be useful when testing
/// custom layer implementations that manually call `on_register_dispatch`.
///
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it possible to add a negative case here?

If not (or not easily) that's fine. Thank you for enhancing tracing-mock!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

crate/subscriber Related to the `tracing-subscriber` crate kind/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants