tokio-rs / tracing

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

`parent: None` is not respected by `json()` format #2973

Open howardjohn opened 4 months ago

howardjohn commented 4 months ago

Bug Report

Version

tracing v0.1.40 (head of master)

Platform

Linux

Crates

tracing_subscriber

Description

Reproducer:

    tracing_subscriber::fmt()
        // .json()
        .with_max_level(tracing::Level::TRACE)
        // .with_current_span(false)
        .init();

    let span1 = tracing::info_span!("this should never be seen", xyz = "123");
    span1.in_scope(|| {
        tracing::event!(target: "tgt", parent: None, tracing::Level::ERROR, foo="bar", "hello");
    });

Output with/without json:

{"timestamp":"2024-05-17T17:09:37.232034Z","level":"ERROR","fields":{"message":"hello","foo":"bar"},"target":"tgt","spans":[{"xyz":"123","name":"this should never be seen"}]}
2024-05-17T17:09:43.082169Z ERROR tgt: hello foo="bar"

Same removing parent: None:

{"timestamp":"2024-05-17T17:11:23.804525Z","level":"ERROR","fields":{"message":"hello","foo":"bar"},"target":"tgt","spans":[{"xyz":"123","name":"this should never be seen"}]}
2024-05-17T17:11:20.205478Z ERROR this should never be seen{xyz="123"}: tgt: hello foo="bar"

You can see while the plain formater respects parent: None, the json one seems to ignore it.