Skip to content

Conversation

CreditWorthy
Copy link

Fixes #2774

Motivation

Event names set with event!(name: "...", ...) are currently not shown in the output. Users sometimes want to see custom event names, like how span names are displayed.

Solution

Added with_event_name() option to control display of event name:

  • Shows custom event name when enabled
  • Hides verbose default names like "event src/main.rs:123"
  • Disabled by default

Example:

tracing_subscriber::fmt()
    .with_event_name(true)
    .init();

event!(name: "user_login", Level::INFO, "User logged in");
// Output: 2024-01-01 INFO app: user_login: User logged in

event!(Level::INFO, "Regular event");
// Output: 2024-01-01 INFO app: Regular event (no event name shown)

Adds with_event_name() to control display of event names in formatted
output. Filters out verbose default names like "event src/main.rs:123",
showing only custom event names when enabled.

Closes tokio-rs#2774
@CreditWorthy CreditWorthy requested review from hawkw and a team as code owners August 13, 2025 03:39
Copy link
Contributor

@kaffarell kaffarell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I find it a bit weird that enabling the option can still cause the name field to not be shown. Maybe as an alternative to this PR we could consider always showing the name field in the Full format when it is not the default value?

@CreditWorthy
Copy link
Author

CreditWorthy commented Aug 13, 2025

Hey, thank you for the feedback! :D

Just to wanted to make sure I understand correctly - you're suggesting that in the Full formatter, we should automatically show custom event names (when they're different from the default), without requiring a configuration option? This would be only in the full formatter not the compact?

So:

  • event!(name: "user_login", ...) → shows "user_login:"
  • tracing::info!(...) → shows nothing (hides default name)
  • Then we can just remove with_event_name() method

@kaffarell

@kaffarell
Copy link
Contributor

Yep, that's what I thought. But maybe someone else wants to chime in -- @davidbarsky what do you think?

@CreditWorthy
Copy link
Author

Hey, just wondering what am post to do now? I would like to contribute more

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

event!(name: ...) is ignored in "full" and "json" output
2 participants