Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Feature: instrument(skip_all)] / instrument(only(foo.bar, foo.baz)) #1273

Open
d4h0 opened this issue Mar 1, 2021 · 3 comments
Open

Feature: instrument(skip_all)] / instrument(only(foo.bar, foo.baz)) #1273

d4h0 opened this issue Mar 1, 2021 · 3 comments

Comments

@d4h0
Copy link

d4h0 commented Mar 1, 2021

Feature Request

A new argument to instrument, that skips all arguments to the function, that the attribute macro is applied to. Similarly, a instrument argument that only shows certain parts of a value (basically, a combination of skip_all and fields).

Crates

tracing

Motivation

Often, the arguments that I pass to functions are complex/verbose. It would be nice, if it was possible to skip all arguments in one go. Then we could use fields to select only the data that is relevant.

Similarly, an only / extract / include argument could skip everything, and select/transform what is wanted (as mentioned, a combination of skip_all and fields).

With my proposal this:

#[skip(argument_that_is_verbose, another_argument, skip_completly), fields(?argument_that_is_verbose.field1, ?argument_that_is_verbose.field2, ?argument_that_is_verbose.field3, %another_argument.field1,  %another_argument.field2)

... would become:

#[only(?argument_that_is_verbose.field1, ?argument_that_is_verbose.field2, ?argument_that_is_verbose.field3, %another_argument.field1, %another_argument.field2)

Even better would something like this:

#[extract(argument_that_is_verbose{?field1, ?field2, ?field3}, another_argument{%field1, %field2})

...but I don't know if it would be possible to implement something like this in a generic way (without being tied to only structs).

Proposal

How should the new feature be implemented, and why? Add any considered
drawbacks.

I have no idea. Unfortunately, at the moment, I have not learned how to use procedural macros yet (which also means, that I couldn't implement this myself, at the moment).

Alternatives

Currently, arguments to skip have to be specified via skip and then fields to include have to be defined via fields, which is more cumbersome than what I propose.

@d4h0 d4h0 changed the title Feature: #[instrumen(skip_all)] / #[instrument(only(foo.bar, foo.baz))] Feature: instrument(skip_all)] / instrument(only(foo.bar, foo.baz)) Mar 1, 2021
@d4h0
Copy link
Author

d4h0 commented Mar 3, 2021

The following is a better example:

This:

#[instrument(
    skip(req, static_files, default_extension, cmd_channel),
    fields(uri=req.uri().path())
)]
async fn handle_request(
    mut req: Request<Body>,
    static_files: Static,
    default_extension: Arc<Option<String>>,
    cmd_channel: mpsc::UnboundedSender<Cmd>,
) -> Result<Response<Body>, io::Error> { .. }

...would become this:

#[instrument(only(uri=req.uri().path()))]
async fn handle_request(
    mut req: Request<Body>,
    static_files: Static,
    default_extension: Arc<Option<String>>,
    cmd_channel: mpsc::UnboundedSender<Cmd>,
) -> Result<Response<Body>, io::Error> { .. }

@Stargateur
Copy link

very related: #754
related: #651

@d4h0
Copy link
Author

d4h0 commented Mar 23, 2021

Thanks, @Stargateur! Yes, #1306 (mentioned in #651) would make my proposal unnecessary (and would be ideal, in my opinion).

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants