Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fmt: Missing space between multiple values for the same key on a span #627

Closed
bazaah opened this issue Mar 10, 2020 · 2 comments
Closed
Labels
crate/subscriber Related to the `tracing-subscriber` crate good first issue Good for newcomers kind/bug Something isn't working

Comments

@bazaah
Copy link

bazaah commented Mar 10, 2020

Version

tracing v0.1.13
│ ├── tracing-attributes v0.1.7
│ └── tracing-core v0.1.10
└── tracing-subscriber v0.2.3
├── tracing-core v0.1.10 ()
├── tracing-log v0.1.1
│ └── tracing-core v0.1.10 (
)
└── tracing-serde v0.1.1
└── tracing-core v0.1.10 (*)

Platform

Linux elysium 5.5.6-arch1-1 #1 SMP PREEMPT Mon, 24 Feb 2020 12:20:16 +0000 x86_64 GNU/Linux

Crates

tracing
tracing-subscriber

Description

When repeatedly record()ing values to the same span key, a space between each KV pair is missing.
MVP:

use {
    tracing::{info, info_span},
    tracing_subscriber::FmtSubscriber,
};

fn main() {
    let subscriber = FmtSubscriber::builder().finish();
    tracing::subscriber::set_global_default(subscriber).expect("setting default subscriber failed");

    let span = info_span!("debug", happy = true);
    let _grd = span.enter();
    span.record("happy", &false);

    info!("hello world");
}

The expected result: <DATE> INFO debug{happy=true happy=false}: <FILE>: hello world

The actual output: <DATE> INFO debug{happy=truehappy=false}: <FILE>: hello world

Note the lack of a space between 'true' and 'happy'

@hawkw
Copy link
Member

hawkw commented Mar 10, 2020

Thanks for reporting & providing a minimal reproduction! This definitely looks like a bug.

@hawkw hawkw added crate/subscriber Related to the `tracing-subscriber` crate kind/bug Something isn't working labels Mar 10, 2020
@hawkw
Copy link
Member

hawkw commented Mar 10, 2020

I think fixing this should be relatively straight-forward. Here is the code where we are recording a new value into a span that already has formatted fields:

if let Some(FormattedFields { ref mut fields, .. }) =
extensions.get_mut::<FormattedFields<N>>()
{
let _ = self.fmt_fields.format_fields(fields, values);

We can check here if the formatted fields string is non-empty. If it is, we can append a ' ' before recording the field.

If anyone is interested in looking into this, it's probably a pretty good first issue. I'm happy to provide further advice, too!

@hawkw hawkw added the good first issue Good for newcomers label Mar 10, 2020
bnjjj added a commit to bnjjj/tracing that referenced this issue Apr 2, 2020
… a span tokio-rs#627

Signed-off-by: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com>
@hawkw hawkw closed this as completed in ee675a2 Apr 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
crate/subscriber Related to the `tracing-subscriber` crate good first issue Good for newcomers kind/bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants