Skip to content

event!(name: ...) is ignored in "full" and "json" output #2774

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

Open
safinaskar opened this issue Oct 24, 2023 · 4 comments
Open

event!(name: ...) is ignored in "full" and "json" output #2774

safinaskar opened this issue Oct 24, 2023 · 4 comments
Labels
crate/subscriber Related to the `tracing-subscriber` crate good first issue Good for newcomers kind/feature New feature or request

Comments

@safinaskar
Copy link

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

@kaffarell
Copy link
Contributor

kaffarell commented Oct 25, 2023

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.

@hawkw
Copy link
Member

hawkw commented Oct 25, 2023

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.

@hawkw hawkw added kind/feature New feature or request good first issue Good for newcomers crate/subscriber Related to the `tracing-subscriber` crate labels Oct 25, 2023
@safinaskar
Copy link
Author

@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

@kaffarell
Copy link
Contributor

kaffarell commented Oct 26, 2023

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?

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/feature New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants