davidbarsky / tracing-tree

Apache License 2.0
123 stars 31 forks source link

Don't crash if ctx is in a span but event isn't #55

Closed CAD97 closed 1 year ago

CAD97 commented 1 year ago

This can occur when there are active spans, but all of the active spans are filtered out by a per-layer filter, so don't show up to us.

I'm not sure if this is considered more a tracing bug or a tracing-tree bug, but this fixed the crash for me, so I'm submitting it here for discussion.

CAD97 commented 1 year ago

My stack setup:

    use tracing_filter::legacy::Filter;

    color_eyre::install()?;

    let (filter, diagnostics) = Filter::parse("info,crate=debug");
    assert!(diagnostics.is_none());

    let fmt = tracing_tree::HierarchicalLayer::default()
        .with_ansi(supports_color::on(supports_color::Stream::Stderr).is_some())
        .with_targets(true);

    tracing_subscriber::registry()
        .with(fmt.with_filter(filter))
        .with(tracing_error::ErrorLayer::default())
        .try_init()?;
davidbarsky commented 1 year ago

I think this behavior is partly a bug inside of tracing-subscriber, but given this causes issues, then let's fix it here.

CAD97 commented 1 year ago
codebling commented 1 year ago

Thanks for the fix. To make this show up in search results, I'm just going to put the error text right here: Unable to get span scope; this is a bug