Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

implement enabled_span and enabled_event #1900

Merged
merged 10 commits into from Mar 31, 2022
Merged

Conversation

guswynn
Copy link
Contributor

@guswynn guswynn commented Feb 4, 2022

Motivation

Closes #1892

Solution

I went with sharing as much of the macro as possible. This means in the docs, the macro only shows the ($($rest:tt)*)=> (...) variant, but I think linking to the enabled! docs should be fine. Also, I find the macro pattern part of rustdoc to be very hard to understand, and I think many people dont look at it

@hawkw I went ahead and put this pr against the v0.1 branch, let me know if you prefer master and backporting

@hawkw
Copy link
Member

hawkw commented Feb 4, 2022

@hawkw I went ahead and put this pr against the v0.1 branch, let me know if you prefer master and backporting

in general, please prefer to open PRs against master and backporting them to v0.1.x, rather than the other way around. normally, I backport large numbers of PRs from master in one go as part of the release prep process.

Copy link
Member

@hawkw hawkw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

overall, this seems like a good direction. i'm unconvinced about the benefits of making a separate internal macro, versus just making all the cases with kinds be part of the main enabled! macro and have the event- and span-specific versions call into that --- open to discussion on that, though.

also, I had some minor naming and documentation suggestions.

thanks for working on this!

tracing/src/macros.rs Outdated Show resolved Hide resolved
tracing/src/macros.rs Outdated Show resolved Hide resolved
tracing/src/macros.rs Outdated Show resolved Hide resolved
tracing/src/macros.rs Outdated Show resolved Hide resolved
tracing/src/macros.rs Outdated Show resolved Hide resolved
tracing/src/macros.rs Outdated Show resolved Hide resolved
tracing/src/macros.rs Outdated Show resolved Hide resolved
tracing/src/macros.rs Outdated Show resolved Hide resolved
tracing/src/macros.rs Outdated Show resolved Hide resolved
tracing/src/macros.rs Outdated Show resolved Hide resolved
@guswynn
Copy link
Contributor Author

guswynn commented Feb 4, 2022

@hawkw I think all review is covered now.
I had some trouble with the macro branch ordering, for reasons I dont understand, but I got it working

currently, I pass through $kind:expr in the main enabled! macro, and span_enabled! and event_enabled! pass through the correct expression

this could be 1. left as is 2. or switched to allow users to pass kind: span and kind: event as optional parameters in front, if you prefer that over the specific macros. I like the simplicity of this impl, and the parallel with the event! and span! macros tho

I think #2 could be done backwards-compatibly in the future, as those parameters on the macro are un-documented as is

Copy link
Member

@hawkw hawkw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

overall, this seems good; i had some minor comments

tracing/tests/macros.rs Outdated Show resolved Hide resolved
tracing/tests/enabled.rs Outdated Show resolved Hide resolved
tracing/src/macros.rs Outdated Show resolved Hide resolved
tracing/src/macros.rs Outdated Show resolved Hide resolved
tracing/src/macros.rs Outdated Show resolved Hide resolved
tracing/src/macros.rs Outdated Show resolved Hide resolved
tracing/src/macros.rs Outdated Show resolved Hide resolved
tracing/src/macros.rs Outdated Show resolved Hide resolved
tracing/src/macros.rs Outdated Show resolved Hide resolved
@davidbarsky
Copy link
Member

I only just saw this PR; sorry about that. To quote @hawkw from the issue:

Alternatively, we could add this to the existing enabled! macro, like enabled!(span, ...) and enabled!(event, ...). IMO, just making separate macros is a bit more obvious from a UX perspective, but I'm open to being convinced otherwise.

I think I'd prefer to add this to the existing enabled! macro for the following reasons:

  • There's already a large amount of macros in tracing, and I'd prefer to avoid adding new ones that might overwhelm newcomers.
  • enabled! feels like a relatively niche tool—tracing was able to get away without adding it for years. By the time a user knows they'd benefit from using enabled!, I think that they'd check enabled!'s documentation to see if they can pass event/span data. I don't think that enabled! needs the additional discoverability that enabled_span! and enabled_event! will implicitly add.
    • While I don't really use span macros like info_span!, I can see their value. I worry that increasing the prominence of enabled! (by having more enabled!-like macros in the top-level macros section of the Rustdoc) will lead people to over-rely on enabled! instead of leaning on filters such as, e.g., Targets (I made this point last since I have the least amount of data to support this assertion and I might be the most wrong on this).

That being said, I don't feel too strongly about these points, but I should've mentioned it before @guswynn implemented it.

@hawkw
Copy link
Member

hawkw commented Feb 8, 2022

I only just saw this PR; sorry about that. To quote @hawkw from the issue:

Alternatively, we could add this to the existing enabled! macro, like enabled!(span, ...) and enabled!(event, ...). IMO, just making separate macros is a bit more obvious from a UX perspective, but I'm open to being convinced otherwise.

I think I'd prefer to add this to the existing enabled! macro for the following reasons:

This PR already does that, it just also adds span_enabled! and event_enabled! macros that expand to invoke the enabled! macro. I think this is correct because it's (a) consistent with the general design of other macros, and (b) makes it very clear that there is the possibility that the result of asking if a span is enabled and if an event is enabled may differ.

  • enabled! feels like a relatively niche tool—tracing was able to get away without adding it for years. By the time a user knows they'd benefit from using enabled!, I think that they'd check enabled!'s documentation to see if they can pass event/span data. I don't think that enabled! needs the additional discoverability that enabled_span! and enabled_event! will implicitly add.

    • While I don't really use span macros like info_span!, I can see their value. I worry that increasing the prominence of enabled! (by having more enabled!-like macros in the top-level macros section of the Rustdoc) will lead people to over-rely on enabled! instead of leaning on filters such as, e.g., Targets (I made this point last since I have the least amount of data to support this assertion and I might be the most wrong on this).

Is your argument here essentially that because you don't think that people should use the API, you don't think it should be easy to use? I don't think this is a good approach. If we're going to provide something, we should make it straightforward and easy to use. If we don't think it should exist at all, we shouldn't provide the API, but if we've made the decision to have it, we shouldn't intentionally make it worse in order to discourage its use. If we commit to providing an API, stopping people from using it is solely a documentation problem.

As a side note, I still don't understand where the idea that using enabled! is somehow in competition with "using filters such as e.g., Targets", when the only thing the macro does is ask the filter if it would enable something.

My final argument in favor of separate macros is that they ensure that the callsite kind always has its HINT bit set. If we just accept an arbitrary callsite kind, we can't stop the user from calling enabled! with a callsite that isn't a hint.

tracing/src/macros.rs Outdated Show resolved Hide resolved
@guswynn
Copy link
Contributor Author

guswynn commented Feb 8, 2022

all review should be handled!
cleaned up the tests, moved the .hint (but left $kind as :expr not :ident, left it as separate macros

Copy link
Member

@hawkw hawkw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this seems fine to me. i have a slight preference for putting all the tests in one file, but it's not a big deal

.done()
.run();

tracing::collect::set_global_default(collector).unwrap();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i would probably use the local default (set_default) in these tests, so they can all be in the same file...having to put it in a separate file is kind of annoying. not a hard blocker though.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ill clean this up then merge!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rather, ill clean this up, then yall can squash-and-merge

@davidbarsky
Copy link
Member

As a side note, I still don't understand where the idea that using enabled! is somehow in competition with "using filters such as e.g., Targets", when the only thing the macro does is ask the filter if it would enable something.

Spoke to Eliza on Discord. Quick summary:

  • this PR is reasonable and tracing should require users of enabled! to specify whether they're querying over a span or event. enabled! should've either required a kind parameter (with the downside that a caller can provide an invalid bitset) or not have shipped, meaning that enabled_span! or enabled_event! should be the primary API. This can be revisited in tracing 0.2, but it won't be figured out on this PR.
  • I over-indexed on my fear that people would incorrectly rely on/misuse enabled! instead of realizing a deactivated span or event's field values are not evaluated.

@guswynn
Copy link
Contributor Author

guswynn commented Feb 9, 2022

I cant recreate that compilation failure, locally, on the same nightly...

@hawkw
Copy link
Member

hawkw commented Feb 9, 2022

I cant recreate that compilation failure, locally, on the same nightly...

it appears to be a compiler regression, i've already opened rust-lang/rust#93821 for it. we can move forward with this PR regardless, since it's not our fault.

@hawkw hawkw enabled auto-merge (squash) March 31, 2022 18:22
@hawkw hawkw merged commit 16577e1 into tokio-rs:master Mar 31, 2022
hawkw added a commit that referenced this pull request Apr 1, 2022
## Motivation

Closes #1892

## Solution

This branch adds new `span_enabled!` and `event_enabled!` macros.

I went withe sharing as much of the macro as possible. The new macros
were implemented by adding a `kind:` parameter to `enabled!`, and invoking
`enabled!` with the appropriate `kind:` argument. This means in the
docs, the macro only shows the `($($rest:tt)*)=> (...)` variant, but I
think linking to the `enabled!` docs should be fine. Also, I find the
macro pattern part of rustdoc to be very hard to understand, and I think
many people dont look at it.

Co-authored-by: Eliza Weisman <eliza@buoyant.io>
hawkw added a commit that referenced this pull request Apr 1, 2022
## Motivation

Closes #1892

## Solution

This branch adds new `span_enabled!` and `event_enabled!` macros.

I went withe sharing as much of the macro as possible. The new macros
were implemented by adding a `kind:` parameter to `enabled!`, and invoking
`enabled!` with the appropriate `kind:` argument. This means in the
docs, the macro only shows the `($($rest:tt)*)=> (...)` variant, but I
think linking to the `enabled!` docs should be fine. Also, I find the
macro pattern part of rustdoc to be very hard to understand, and I think
many people dont look at it.

Co-authored-by: Eliza Weisman <eliza@buoyant.io>
hawkw added a commit that referenced this pull request Apr 1, 2022
## Motivation

Closes #1892

## Solution

This branch adds new `span_enabled!` and `event_enabled!` macros.

I went withe sharing as much of the macro as possible. The new macros
were implemented by adding a `kind:` parameter to `enabled!`, and invoking
`enabled!` with the appropriate `kind:` argument. This means in the
docs, the macro only shows the `($($rest:tt)*)=> (...)` variant, but I
think linking to the `enabled!` docs should be fine. Also, I find the
macro pattern part of rustdoc to be very hard to understand, and I think
many people dont look at it.

Co-authored-by: Eliza Weisman <eliza@buoyant.io>
hawkw added a commit that referenced this pull request Apr 1, 2022
## Motivation

Closes #1892

## Solution

This branch adds new `span_enabled!` and `event_enabled!` macros.

I went withe sharing as much of the macro as possible. The new macros
were implemented by adding a `kind:` parameter to `enabled!`, and invoking
`enabled!` with the appropriate `kind:` argument. This means in the
docs, the macro only shows the `($($rest:tt)*)=> (...)` variant, but I
think linking to the `enabled!` docs should be fine. Also, I find the
macro pattern part of rustdoc to be very hard to understand, and I think
many people dont look at it.

Co-authored-by: Eliza Weisman <eliza@buoyant.io>
hawkw added a commit that referenced this pull request Apr 1, 2022
## Motivation

Closes #1892

## Solution

This branch adds new `span_enabled!` and `event_enabled!` macros.

I went withe sharing as much of the macro as possible. The new macros
were implemented by adding a `kind:` parameter to `enabled!`, and invoking
`enabled!` with the appropriate `kind:` argument. This means in the
docs, the macro only shows the `($($rest:tt)*)=> (...)` variant, but I
think linking to the `enabled!` docs should be fine. Also, I find the
macro pattern part of rustdoc to be very hard to understand, and I think
many people dont look at it.

Co-authored-by: Eliza Weisman <eliza@buoyant.io>
hawkw added a commit that referenced this pull request Apr 9, 2022
# 0.1.33 (April 9, 2022)

This release adds new `span_enabled!` and `event_enabled!` variants of
the `enabled!` macro, for testing whether a subscriber would
specifically enable a span or an event.

### Added

- `span_enabled!` and `event_enabled!` macros ([#1900])
- Several documentation improvements ([#2010], [#2012])

### Fixed

- Compilation warning when compiling for <=32-bit targets (including
  `wasm32`) ([#2060])

Thanks to @guswynn, @arifd, @hrxi, @CAD97, and @name1e5s for
contributing to this release!

[#1900]: #1900
[#2010]: #2010
[#2012]: #2012
[#2060]: #2060
hawkw added a commit that referenced this pull request Apr 9, 2022
# 0.1.33 (April 9, 2022)

This release adds new `span_enabled!` and `event_enabled!` variants of
the `enabled!` macro, for testing whether a subscriber would
specifically enable a span or an event.

### Added

- `span_enabled!` and `event_enabled!` macros ([#1900])
- Several documentation improvements ([#2010], [#2012])

### Fixed

- Compilation warning when compiling for <=32-bit targets (including
  `wasm32`) ([#2060])

Thanks to @guswynn, @arifd, @hrxi, @CAD97, and @name1e5s for
contributing to this release!

[#1900]: #1900
[#2010]: #2010
[#2012]: #2012
[#2060]: #2060
@guswynn guswynn deleted the span_enabled branch June 23, 2022 18:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

tracing: Add span- and event-specific enabled! variants
3 participants