-
Notifications
You must be signed in to change notification settings - Fork 847
Description
Feature Request
Crates
- tracing-attributes
Motivation
Currently instrument attribute macro's err meta item makes the expanded code to print the Err result only using its Display implementation. Some Error types could be more beneficial to be printed using their Debug implementation. For example eyre::Result contains an error chain. When printed in via Display, it shows the most recent error message. But if you print it via the Debug implementation it shows the error with the error chain.
Proposal
Being able to write #[insturment(?err, ...)] would be in line with trace! et. al macro's fields, but it appears this isn't compatible with meta item syntax. Maybe two alternatives can be provided as:
#[instrument(err, ...)]: print theErrorusingDisplayimplementation so that existing codes aren't affected.#[instrument(err_dbg, ...)]: print theErrorusingDebugimplementation.
I am willing to work on this and open a PR. Let me know if you can think of a better alternative syntax.
Alternatives
The only alternative I can think of is to remove err meta item from the attribute, catch the error somehow and print manually with "{:?}" format string. But this defeats the purpose of #[instrument] attribute (ergonomy) as it could easily implement this behavior.