Skip to content
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

Unexpected side-effect in Dispatch::new #2976

Open
JakkuSakura opened this issue May 20, 2024 · 1 comment
Open

Unexpected side-effect in Dispatch::new #2976

JakkuSakura opened this issue May 20, 2024 · 1 comment

Comments

@JakkuSakura
Copy link

Dispatch::new is not side-effect-free.

impl Dispatch {
    /// Returns a `Dispatch` that forwards to the given [`Subscriber`].
    ///
    /// [`Subscriber`]: super::subscriber::Subscriber
    pub fn new<S>(subscriber: S) -> Self
    where
        S: Subscriber + Send + Sync + 'static,
    {
        let me = Dispatch {
            subscriber: Kind::Scoped(Arc::new(subscriber)),
        };
        callsite::register_dispatch(&me);
        me
    }
}

It should be moved to a new function like register_dispatch and get called in dispatcher::set_global_default
and similar functions
Not hidden in self.into() like in tracing_susbcriber

        dispatcher::set_global_default(self.into()).map_err(TryInitError::new)?;

https://github.com/tokio-rs/tracing/blame/690a9a68098aa1eb86d1c5c4aad085ef12245bca/tracing-core/src/dispatch.rs#L545

JakkuSakura/tracing-shared-rs#2

@JakkuSakura
Copy link
Author

Above "close" was misclicked

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant