tracing icon indicating copy to clipboard operation
tracing copied to clipboard

instrument macro: add skip-all-except option

Open rusty-objects opened this issue 5 years ago • 4 comments

Feature Request

Add an ability to skip all arguments in the instrument macro.

Motivation

Currently, instrument requires explicit opt-out to avoid capturing arguments in a span. For some use cases, like those where arguments might contain sensitive data (e.g. passwords) that authors don't want to leak into logs, an opt-out model presents a risk where authors need to be diligent to include every sensitive argument in the opt-out list. A more manageable option would be to suppress all arguments and allow explicit opt-in for insensitive arguments.

Proposal

Add another option such as skip-all-except (or a more suitable name), which can take as its nested fields the arguments that the span should capture. When both skip and skip-all-except are present, the compiler could error.

Alternatives

An alternative would be to add a feature flag that sets the default behavior of the instrument macro to be to suppress all, but then there'd still need to be an option to opt into arguments to unsuppress.

rusty-objects avatar Jun 16 '20 07:06 rusty-objects

The plan is that in tracing-attributes v0.2, fields in instrument will be opt-in rather than opt-out. Since #672 added support for arbitrary expressions as fields to instrument, you will be able to specify what fields you want to include using the same syntax as the span! and event! macros (including local variable shorthand). This should make skipping fields unnecessary.

hawkw avatar Jun 30 '20 21:06 hawkw

Is there any roadmap for when tracing-attributes 0.2 will come out?

I'm starting to add #[instrument] to my crate and having to skip fields manually is a big pain point.

PoignardAzur avatar Feb 24 '21 19:02 PoignardAzur

I just blew up a service's logs by missing a skip on a newly added field. That argument was very very large, and increased the size of error log lines by more than one order of magnitudes.

This is in my opinion one of the biggest landmines in the rust ecosystem. :(

chamons avatar Mar 06 '25 22:03 chamons

Hey @hawkw are there any plans on expanding fields? They support debug printing of values but unfortunately not so much for types with custom display. Using to_string() is possible but produces unfortunate quotes.

Pzixel avatar Sep 12 '25 05:09 Pzixel