tracing
tracing copied to clipboard
Allow macro `instrument` to accept multiple `fields` and `skip` and merge them
Feature Request
Crates
https://docs.rs/tracing-attributes/0.1.27/src/tracing_attributes/lib.rs.html#563-566
Motivation
I'm using a custom macro that creates some functions and optionally also instrument theses functions with the instrument
macro.
Proposal
It would be better to the macro instrument
already accept multiple fields
and skip
and merge them than doing this in the custom macro.
Also, other fields could also allow being defined multiple times, and only the last be valid.
This could be a feat turned on by another attribute like "allow_multiple" so that by default the current behaviour remains, but macro writers could have a more flexible instrument
Ex:
#[instrument(allow_multiple, skip(self), skip(x), name="x", name="y")]
// same as
#[instrument(skip(self, x), name="y")]
// anything without allow_multiple would already be equal to how instrument works know
// allow_multiple would be in effect only since it appeared, so position would matter
PS: If this is approved, I could send a pull request. PS2: I would implement any variation of this main idea, even if this specific proposal is not the chosen one.
Alternatives
I didn't found other ways in the tracing code to do it, I'm doing this by hand in my custom macro.
But I assume that could be a reasonably general problem, and better not to have the external macro writers like myself reinvent the wheel.