Skip to content

Naming issues for span structured data. #1423

@najamelan

Description

@najamelan

Bug Report

Version

test_tracing v0.1.0 (/data/doc/code/test_tracing)
├── tracing v0.1.26
│ ├── tracing-attributes v0.1.15 (proc-macro)
│ └── tracing-core v0.1.18
└── tracing-subscriber v0.2.18
├── tracing v0.1.26 ()
├── tracing-core v0.1.18 (
)
├── tracing-log v0.1.2
│ └── tracing-core v0.1.18 ()
└── tracing-serde v0.1.2
└── tracing-core v0.1.18 (
)

Platform

Linux desktop.home 5.12.8-arch1-1 #1 SMP PREEMPT Fri, 28 May 2021 15:10:20 +0000 x86_64 GNU/Linux

Description

Some of the first field names for structured data where type and name. I ran into some quirky issues with both, so I wanted to report those here and raise the question as to whether this is desired behavior.

Since type is a reserved keyword, my first attempt was r#type.

use tracing::* ;

fn main()
{
    let _sub = tracing_subscriber::fmt::Subscriber::builder()

        .json()
        .init()
   ;


   let _span = error_span!( "my_span", r#type = "i32", r#name = "Bobby" ).entered();

   info!( "shak yaving?" );
}

Produces:

{"timestamp":"Jun 06 21:39:20.690","level":"INFO","fields":{"message":"shak yaving?"},"target":"test_tracing","span":{"name":"Bobby","r#type":"i32","name":"my_span"},"spans":[{"name":"Bobby","r#type":"i32","name":"my_span"}]}

without json:

Jun 06 21:53:26.825  INFO my_span{type="i32" name="Bobby"}: test_tracing: shak yaving?

NOTES:

  • name field exists twice on the span. Turns out it's legal json, but what to make of it. Are there instructions for consumers of such data on what this means? It seems like the default formatter has some magic knowledge, as it figures out that my_span is the span name and Bobby is an actual name field.
  • r# get's removed from r#name, but not from r#type???

Using quotes

   let _span = error_span!( "my_span", "type" = "i32", "name" = "Bobby" ).entered();

Json:

{"timestamp":"Jun 06 22:03:06.993","level":"INFO","fields":{"message":"shak yaving?"},"target":"test_tracing","span":{"name":"Bobby","type":"i32","name":"my_span"},"spans":[{"name":"Bobby","type":"i32","name":"my_span"}]}

default fmt:

Jun 06 22:02:52.920  INFO my_span{type="i32" name="Bobby"}: test_tracing: shak yaving?

NOTES:

  • overall quotes seem better than r#, and it's what's suggested in the docs, fair play. It still has duplicate fields.

I would like to suggest:

  • for metadata, use reserved field names like __span_name instead of very common ones like name.
  • be consistent in removing r# from all keys the same.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions