Skip to content

Tree layers with different filters cause unnecessary span exits to be printed #92

@tmandry

Description

@tmandry

If I have multiple tree layers and one of them has a filter, e.g.

pub fn init_logging() {
    let logfile = File::create(format!("/tmp/glide.log")).unwrap();
    tracing_subscriber::registry()
        .with(tree_layer().with_filter(EnvFilter::from_default_env()))
        .with(tree_layer().with_writer(Mutex::new(logfile)))
        .init();
}

pub fn tree_layer() -> tracing_tree::HierarchicalLayer<fn() -> Stderr, UtcDateTime> {
    tracing_tree::HierarchicalLayer::default()
        .with_indent_amount(2)
        .with_indent_lines(true)
        .with_deferred_spans(true)
        .with_span_retrace(true)
        .with_targets(true)
        .with_timer(UtcDateTime::default())
}

I see span exits for all spans on the filtered output:

┐glide_wm::actor::wm_controller::handle_event event=ScreenParametersChanged([CGRect { origin: CGPoint { x: 0.0, y: 45.0 }, size: CGSize { width: 2048.0, height: 1285.0 } }], [ScreenId(1)], CoordinateConverter { screen_height: 1330.0 }, [Some(SpaceId(7))])
├─2025-12-30 2:22:46.577527  16ms  INFO glide_wm::actor::reactor screen parameters changed
┌─┘
2025-12-30 2:22:46.578139  INFO glide_wm::actor::app Filtering out XPC process, pid=627, bundle_id=Some("com.apple.ViewBridgeAuxiliary")
┘
┘
┘
2025-12-30 2:22:46.608601  INFO glide_wm::actor::app Filtering out XPC process, pid=21555, bundle_id=Some("com.apple.appkit.xpc.openAndSavePanelService")
2025-12-30 2:22:46.60865  INFO glide_wm::actor::app Filtering out XPC process, pid=21556, bundle_id=Some("com.apple.quicklook.QuickLookUIService")
2025-12-30 2:22:46.609297  INFO glide_wm::actor::app Filtering out XPC process, pid=36288, bundle_id=Some("com.apple.intents.intents-helper")
┘
2025-12-30 2:22:46.609531  INFO glide_wm::actor::app Filtering out XPC process, pid=36287, bundle_id=Some("com.apple.WorkflowKit.BackgroundShortcutRunner")
┌─┘
┘
┌─┘
┘
┌─┘
┘
┌─┘
┘
┌─┘
┘
┘
┘
┘
┘

This is because tracing-tree uses span extension data to track whether the span was written, but the data isn't keyed by the layer. It assumes there is only ever one tracing-tree layer.

tracing-tree/src/lib.rs

Lines 578 to 583 in 79627fc

// Span was not printed, so don't print an exit
if self.config.deferred_spans
&& span.extensions().get::<Data>().map(|v| v.written) != Some(true)
{
return;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions