Skip to content

tracing-subscriber: span events don't include span fields with json formatter #1032

Open
@kbleeke

Description

@kbleeke

Bug Report

Version

tracing = "0.1.21"
tracing-subscriber = "0.2.13"

Platform

Linux saren 5.8.14-arch1-1 #1 SMP PREEMPT Wed, 07 Oct 2020 23:59:46 +0000 x86_64 GNU/Linux

Crates

tracing-subscriber

Description

Span events that are enabled by SubscriberBuilder::with_span_events include the span's fields when the default formatter (that prints human-friendly logs) is used. I also expected this to be the case when the json formatter is used (SubscriberBuilder::json) but no span fields are included in the json.

Without json:

❯ RUST_LOG="info" cargo r
   Compiling tracingtest v0.1.0 (/home/pluth/rust/tracingbug)
    Finished dev [unoptimized + debuginfo] target(s) in 0.33s
     Running `target/debug/tracingtest`
Oct 13 12:56:15.904  INFO testspan{data="somedata"}: tracingtest: new
Oct 13 12:56:15.905  INFO testspan{data="somedata"}: tracingtest: close time.busy=0.00ns time.idle=234µs

Field data is shown here.

With json:

❯ RUST_LOG="info" cargo r
   Compiling tracingtest v0.1.0 (/home/pluth/rust/tracingbug)
    Finished dev [unoptimized + debuginfo] target(s) in 0.43s
     Running `target/debug/tracingtest`
{"timestamp":"Oct 13 12:56:40.641","level":"INFO","fields":{"message":"new"},"target":"tracingtest"}
{"timestamp":"Oct 13 12:56:40.641","level":"INFO","fields":{"message":"close","time.busy":"0.00ns","time.idle":"140µs"},"target":"tracingtest"}

Field data is not shown here.

Code:

use tracing_subscriber::fmt::format::FmtSpan;

fn main() {
    tracing_subscriber::fmt::fmt()
    .json()
    .with_span_events(FmtSpan::FULL)
    .init();

    tracing::info_span!("testspan", data="somedata");
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    crate/subscriberRelated to the `tracing-subscriber` cratekind/bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions