tracing
tracing copied to clipboard
Prepend label to field names used with `#[instrument]`
Feature Request
Add the ability to prepend a string scope to field labels when using the #[instrument]
attribute macro.
Motivation
When using the #[instrument]
macro on functions, the field names are taken verbatim from the argument names, so common or short names can become difficult to identify among other fields included in a trace, e.g. a function that uses id
, name
, or target
as argument names. Having the option to prepend a field label to the argument names will allow for easier search and identification, and a way to avoid conflicts with other fields on the span.
Proposal
This could look something like this for instance:
#[instrument(label = "params")]
fn foo(name: &str, target: &str) -> bool {
// Do the foo things.
}
which would yield trace fields like params.name
and params.target
.
Alternatives
I don't believe there are any alternative solutions to this while using the #[instrument]
attribute macro other than to explicitly skip_all
and include the fields(...)
with desired names.