tracing
tracing copied to clipboard
event!(name: ...) is ignored in "full" and "json" output
Bug Report
Version
├── tracing v0.1.40
│ ├── tracing-attributes v0.1.27 (proc-macro)
│ └── tracing-core v0.1.32
└── tracing-subscriber v0.3.17
├── tracing-core v0.1.32 (*)
├── tracing-log v0.1.3
│ └── tracing-core v0.1.32 (*)
└── tracing-serde v0.1.3
└── tracing-core v0.1.32 (*)
Platform
Linux comp 5.10.0-0.deb9.24-amd64 #1 SMP Debian 5.10.179-5~deb9u1 (2023-09-01) x86_64 GNU/Linux
Crates
tracing, tracing-subscriber
Description
Name in event!(name: ..., ...)
is ignored in both "json" and "full" output in tracing-subscriber
.
tracing-subscriber
description for "json" output reads: "This is intended for production use" ( https://docs.rs/tracing-subscriber/0.3.17/tracing_subscriber/fmt/format/index.html ). So, I'm assuming that output should be complete or at least can be configured to be complete. Same for "full". Word "full" assumes that output will be full or at least can be configured to be full. Yet in both outputs name is absent. Here is my code:
fn main() {
use tracing_subscriber::layer::SubscriberExt;
use tracing_subscriber::util::SubscriberInitExt;
use tracing::Level;
use tracing::event;
tracing_subscriber::Registry::default()
.with(tracing_subscriber::fmt::layer()
// .json()
)
.init();
event!(name: "n", Level::INFO, "a");
}
Here is output ("full" mode):
2023-10-24T18:18:06.222325Z INFO trac: a
Here is output if I uncomment .json()
:
{"timestamp":"2023-10-24T18:18:45.843139Z","level":"INFO","fields":{"message":"a"},"target":"trac"}
So, in both cases name is absent. Moreover, when I search (using Ctrl-F) word "name" in https://docs.rs/tracing-subscriber/0.3.17/tracing_subscriber/fmt/struct.Layer.html , I find nothing. Same for https://docs.rs/tracing-subscriber/0.3.17/tracing_subscriber/fmt/format/struct.Json.html and https://docs.rs/tracing-subscriber/0.3.17/tracing_subscriber/fmt/format/struct.Full.html . So, nothing suggests I can somehow configure this.
This is inconsistent, because span names are printed by default. But event's - no. Why you added names at all? They should behave similar to span's names
This is probably because because the name
attribute (which is btw not a normal field, but a direct member of Metadata), is set by default in a event. If you create a simple event like this:
tracing::info!("yak shaving started");
the name
attribute will be: "event examples/examples/fmt.rs:14"
, so 'event' + the callsite.
But when using spans, the user has to specify the name, so it's more important (and when do spans get printed using the fmt layer?).
So, I'm assuming that output should be complete or at least can be configured to be complete. Same for "full". Word "full" assumes that output will be full or at least can be configured to be full.
I agree, I think this would be a good addition.
The fmt
layer does not currently include event names in its output. We should probably add an option to include names. However, when the event has the default name, we may want to ignore them, because they are verbose and likely not desired.
@kaffarell
and when do spans get printed using the fmt layer?
Add .with_span_events(FmtSpan::NEW | FmtSpan::CLOSE)
after tracing_subscriber::fmt::layer()
in my code example, and you will see span events
We should probably add an option to include names.
Yes, I agree.
However, when the event has the default name, we may want to ignore them, because they are verbose and likely not desired.
Hmm, I don't know about this one to be honest. How would we check if it's the default one or a custom provided one?
edit: @hawkw @davidbarsky what do you think?
I am applying to this issue via OnlyDust platform.
My background and how it can be leveraged
efsdvsdvsdv
I am applying to this issue via OnlyDust platform.
My background and how it can be leveraged
xzzxczc