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

Allow macro instrument to accept multiple fields and skip and merge them #3001

Open
deoqc opened this issue Jun 7, 2024 · 0 comments
Open

Comments

@deoqc
Copy link

deoqc commented Jun 7, 2024

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.

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

1 participant