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

Can #[instrument] macro offer default format specifier #1312

Open
bobyangyf opened this issue Mar 18, 2021 · 1 comment
Open

Can #[instrument] macro offer default format specifier #1312

bobyangyf opened this issue Mar 18, 2021 · 1 comment

Comments

@bobyangyf
Copy link

bobyangyf commented Mar 18, 2021

Feature Request:

Crates

tracing_attributes

Motivation

Currently, instrument macro uses debug format for all arguments on the function annotated.
However, sometimes the display version of the arguments is preferred as it's often more human friendly. The only current way to do so is to manually add each one to the fields argument with the display format specified. This is verbose, and error prone when modifying the function arguments.
e.g.

#[instrument(fields(a = %a, b = %b, c = %c, d = %d, ...)]
fn foo(a: Box<dyn Display>, b: Box<dyn Display>, ...) { ... }

Proposal

Add a new argument to instrument macro that allows specifies the format of the function arguments.
Example

#[instrument(fmt = tracing::value::display)
fn foo(a: Box<dyn Display>, b: Box<dyn Display>, ...) { ... }

We can change this line. https://docs.rs/tracing-attributes/0.1.15/src/tracing_attributes/lib.rs.html#652
to not hard-code debug format.

Open to implementing this change if there's no objections to this feature.

Alternatives

  1. Leave as is. => :(
  2. introduce a separate macro like display_instrument
@ActuallyHappening
Copy link

I would like this change also, for me display formatting produces a more readable output

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

No branches or pull requests

2 participants