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

Opt in to traced fields [WIP - Some open questions] #1306

Open
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

LukeMathWalker
Copy link
Contributor

Motivation

Closes #651

Solution

  • Start emitting a compiler warning if skip is used within #[tracing::instrument];
  • Remove existing skip logic, converting the annotation from opt-out to opt-in;
  • Adapt existing tests to the new behaviour

Open questions

The PR is not ready for prime-time yet (mostly because I need to update the documentation), but I wanted to clarify a few questions before moving forward:

  • Is emitting a warning when skip is used the desired behaviour? Or do we want to emit a compiler error?
  • Currently
#[tracing::instrument(fields(a))]
fn a_function(a: usize) { ... }

behaves quite surprisingly: instead of adding a to the span, using its Debug representation, it adds a new field with its value set to Empty.
To get the expected behaviour you need to use

#[tracing::instrument(fields(?a))]
fn a_function(a: usize) { ... }

This was perhaps rarely encountered in the wild when the macro worked according to an opt-out philosophy but I am sure it's going to become a very common mistake now that it's opt-in by default and developers need to spell out the fields they want to capture.

Looking at the source code, there is a comment by @hawkw on the issue

            // XXX(eliza): I don't like that fields without values produce
            // empty fields rather than local variable shorthand...but,
            // we've released a version where field names without values in
            // `instrument` produce empty field values, so changing it now
            // is a breaking change. agh.

Is this something you want to resolve as part of the set of breaking changes for the next release? Should it be part of this PR?

@LukeMathWalker LukeMathWalker requested review from davidbarsky, hawkw and a team as code owners March 17, 2021 09:23
@LukeMathWalker LukeMathWalker changed the title Opt in to traced fields Opt in to traced fields [WIP - Some open questions] Mar 17, 2021
@Stargateur
Copy link

Stargateur commented Mar 23, 2021

I don't feel like this is a good solution, then people will ask for opt-out feature.
I think there should be two mode. and default to opt-in

@LukeMathWalker
Copy link
Contributor Author

Is there an interest to progress this one (a.k.a. me bringing it up to speed with trunk and updating the docs) or should I close it? @hawkw?

@bryangarza
Copy link
Member

Thanks for working on this, unfortunately, seems we were not able to get your open questions answered (due to lack of bandwidth probably).

@hawkw thoughts on this? Something we want to merge, or should we close?

@LukeMathWalker
Copy link
Contributor Author

Happy to bring it back to a mergeable state @bryangarza if desired.

@bryangarza
Copy link
Member

Thanks, I'll follow up on the Discord about this and see if we can get some direction on if we want to move forwards or not

@cdmistman
Copy link

hey! any updates on design considerations?

@bryangarza
Copy link
Member

Hi -- this one must have fallen through the cracks. I'm no longer contributing to tracing; if anyone is interested in following up on this, you should probably reach out to the maintainers on the Tokio discord.

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

Successfully merging this pull request may close these issues.

instrument macro: omit self by default
4 participants