tokio-rs / tracing

Application level tracing for Rust.
https://tracing.rs
MIT License
5.48k stars 720 forks source link

instrument macro: omit `self` by default #651

Open carllerche opened 4 years ago

carllerche commented 4 years ago

Feature Request

The #[instrument] proc macro should probably omit self by default as it is pretty noisy.

If #650 happens, this could be used as a way to get access to self again.

hawkw commented 4 years ago

I'm definitely open to this --- skipping big self arguments was one of the main motivations behind adding skip in #11.

I'd like to get input from others currently using instrument, though; ideally, the default should be whatever a majority of users want. cc @davidbarsky, @anp, @Ralith, @LucioFranco, @yaahc; I'm sure at least some of you have opinions.

Also, I think we'd need to work out whether or not this should be considered a breaking change. Existing code will still compile, but it won't behave as it did previously. Is this okay to do in a point release?

davidbarsky commented 4 years ago

I'd like to get input from others currently using instrument, though; ideally, the default should be whatever a majority of users want. cc @davidbarsky, @anp, @Ralith, @LucioFranco, @yaahc; I'm sure at least some of you have opinions.

I'm also in favor of this change. I think that, especially in Chalk, including &self is far too noisy. On a different note, I think this is where per-field levels might come in handy.

Also, I think we'd need to work out whether or not this should be considered a breaking change. Existing code will still compile, but it won't behave as it did previously. Is this okay to do in a point release?

I think this should be treated as a breaking change. I think (@hawkw and I) discussed that format changes should be considered breaking changes, regardless if they're additive.

LucioFranco commented 4 years ago

I am +1 on this as well.

yaahc commented 4 years ago

big +1, i skip self constantly.

What would the syntax for unskipping it be though? Ideas I can imagine

hawkw commented 4 years ago

What would the syntax for unskipping it be though?

@yaahc I think the ideal solution would just be adding self as something that can be added to the fields() argument, as in

#[instrument(fields(self))]

This could be implemented by special-casing self in particular, or by allowing arbitrary expressions to be evaluated in fields(...), as described in https://github.com/tokio-rs/tracing/issues/650.

yaahc commented 4 years ago

So there would be fields and skip, and every arg other than self is automatically a field, and can be disabled with skip, and anything in fields is added to the existing fields from the non skipped args? (sgtm)

anp commented 4 years ago

+1 from me, I tend to think of methods happening "within the span" of self. A way to opt back in sgtm as well.

hawkw commented 4 years ago

Seems like most folks agree that this is the right thing, so we should probably move forwards with it.

Re: whether or not to consider it a breaking change

I think this should be treated as a breaking change. I think (@hawkw and I) discussed that format changes should be considered breaking changes, regardless if they're additive.

@davidbarsky IIRC, this conversation was largely in re: fmt::Subscriber's JSON output and other formats intended to be machine-readable. I'm not sure if I think changes in what data is recorded ought to be considered breaking; only changes in the shape of the output data (that might break parsers etc). Otherwise, if we expected libraries using tracing to uphold the same stability policy, any time you add or remove a field from an event, you would be making a breaking change, which seems nonsensical...

anp commented 4 years ago

We think of structured diagnostics data as an ad-hoc ABI whenever you take dependencies on it. I’m not sure that means it’s a semver breaking change to do this but it’s definitely something which (in a future with more usage) could cause broken tests when rolling versions.

yaahc commented 4 years ago

I personally think that its okay to expect the library that implements the logging format to have a different stability policy for log output than the applications/libraries that consume and expose it.

But I also want this asap so if making it a breaking change means its gonna take a while because we will need to batch the change with other upcoming breakages then I'd vote we just treat it as irrelevant to semver.

hawkw commented 4 years ago

Another thing we could do is release an 0.2x version of tracing-attributes while continuing to export 0.1 from tracing. This would mean that users who want the new "skip self by default" behavior could opt-in to it by depending on tracing-attributes 0.2 explicitly, while the re-exported version in tracing-subscriber wouldn't change its default behavior until we have other breaking changes to make.

I'm not sure if this is worth the effort.

yaahc commented 4 years ago

Assigning this to myself and starting to work on this now. Based on discussions with @hawkw I think we're going to try just skipping all fields by default and make logging of function parameters entirely opt in as of tracing 0.2.

Plan description

Questions

LukeMathWalker commented 3 years ago

This issue is particularly relevant for us at TrueLayer (for reasons along the same line of those expressed in #1089).
I'd be happy to work on this if you didn't have the time to pick it up in the end @yaahc.

yaahc commented 3 years ago

I'd be happy to work on this if you didn't have the time to pick it up in the end @yaahc.

That would be lovely actually, let me know if you have any questions about where I left it.

LukeMathWalker commented 3 years ago

I have a first draft in #1306 - there are a couple of open questions to resolve, then I can start the big piece work of updating documentation/examples/etc.

Kinrany commented 1 year ago

Agree that skipping everything by default is better. The issue should be renamed perhaps?