tokio-rs / tracing

Application level tracing for Rust.
https://tracing.rs
MIT License
5.15k stars 673 forks source link

fix: make `reload::Subscriber` compatible with per-subscriber filters #2965

Open mladedav opened 2 months ago

mladedav commented 2 months ago

Motivation

If the reload::Subscriber was used with a filtered Subscribe, the filters panicked with debug_assertions because nothing cleared interests of the filters. This is because on_subscribe was not called and so the Registry didn't know there were filters involved.

See the new test for an example of what currently panics on master.

downcast_raw also did not special-case the magic filter marker so even if the inner subscriber was filtered, other layers could never find out.

Solution

I've added an implementation for on_subscribe in reload::Subscriber so that filters are properly registered within the Registry.

I've also added an unsafe implementation to downcasting to special-case the magic marker. I've tried to make sure for this to be completely safe even if the caller decides to dereference the returned pointer. This implementation is needed so that Layered and others can tell whether the reload::Subscriber uses psf or not.