-
Notifications
You must be signed in to change notification settings - Fork 884
Open
Description
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_spanis the span name andBobbyis an actual name field. r#get's removed fromr#name, but not fromr#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_nameinstead of very common ones likename. - be consistent in removing
r#from all keys the same.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels