Skip to content
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

Lint non_structural_log #40

Open
Veetaha opened this issue Jul 27, 2023 · 0 comments
Open

Lint non_structural_log #40

Veetaha opened this issue Jul 27, 2023 · 0 comments
Labels
A-user-story Area: A user story or a related issue

Comments

@Veetaha
Copy link

Veetaha commented Jul 27, 2023

Lint explanation

Catch code that uses a tracing logging macro without using structural logging. According to the conventions that I use it is prohibited to use format arguments in tracing logging macros. This means that the message of the log event must always be a static string, and no placeholder {} syntax can be used.

The reasoning is that when we look at the logs in grafana/loki we want to see a birds-eye view of what the system does without digging into the specifics of what specific values of different variables there were when the log happened like this:

image

and then expand the log event to see the key-value pairs of the structural log to dig into the details of a particular log in time.

If developers don't use structural logging and interpolate values in the log message, then such a birds-eye view becomes very verbose and hard to navigate. Also, when no string interpolation is used in log events it's possible to easily build the metrics and statistics of how often a log event with message "foo bar" occurs, and graph that on a dashboard.

Example code

Bad

tracing::info!("The user `{username}` joined the chat `{}`", chat.id);

Good

tracing::info!(%username, chat = %chat.id, "The user joined the chat");

Notes

It would be easier to implement such kind of a lint if marker could see unexpanded macros, but I suppose it may be possible to craft a hacky version of this that operates on the expanded tracing macros, although it may break at any moment once tracing changes the way their macros are expanded.

@Veetaha Veetaha added the A-user-story Area: A user story or a related issue label Jul 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-user-story Area: A user story or a related issue
Projects
None yet
Development

No branches or pull requests

1 participant