Skip to content

Calling SpanTrace::capture() before creating a dispatcher prevents further events from being logged #2436

@alcroito

Description

@alcroito

Bug Report

Version

├── tracing v0.1.37
│ ├── tracing-attributes v0.1.23 (proc-macro)
│ └── tracing-core v0.1.30
├── tracing-error v0.2.0
│ ├── tracing v0.1.37 ()
│ └── tracing-subscriber v0.3.16
│ ├── tracing-core v0.1.30 (
)
│ └── tracing-log v0.1.3
│ └── tracing-core v0.1.30 ()
├── tracing-log v0.1.3 (
)
└── tracing-subscriber v0.3.16 (*)

Platform

macos 12.4
Darwin xyz 21.5.0 Darwin Kernel Version 21.5.0: Tue Apr 26 21:08:22 PDT 2022; root:xnu-8020.121.3~4/RELEASE_X86_64 x86_64

Description

As described in the subject, calling SpanTrace::capture() before creating a dispatcher prevents further events from being logged after installing a global subscriber.

Repro

fn main() {
    tracing_error::SpanTrace::capture();
    tracing_subscriber::fmt::init();
    tracing::event!(tracing::Level::ERROR, "this is not shown");
}

This is a minimal repro of an issue in color-eyre which captures span traces
eyre-rs/color-eyre#110 (comment)

As described in the linked comment, the issue appears to be thread-local-caching of a NoSubscriber dispatcher which gets used during callsite interest evaluation, instead of using the real subscriber.

Metadata

Metadata

Assignees

No one assigned

    Labels

    crate/coreRelated to the `tracing-core` cratekind/bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions