fix: Avoid constructing events when telemetry is disabled#332
Merged
Conversation
The `enabled()` callback pattern now structurally prevents event construction when disabled, making the counter-based test redundant. Removes the static counter, the two helper functions, the four `#[cfg(test)] fetch_add` calls in make_* helpers, and the `hooks_skip_event_construction_when_disabled` test.
- Fix 3 broken rustdoc links: Self::enabled → Self::if_enabled, SharedState::enabled → SharedState::if_enabled - Use is_enabled() instead of if_enabled(|_buf|) in flush_once CPU profiling path, since the EventBuffer token is unused and this is a control-flow decision, not an event-recording path
jlizen
reviewed
May 1, 2026
Member
jlizen
left a comment
There was a problem hiding this comment.
Change seems fine but some somewhat load-bearing bike shedding about naming since there is an overlap with #256 .
Also, was there any good way to test these events never land in the buffer? Not seeing anything obvious that wouldn't involve adding a lot more machinery, which I don't think is worth it, but just asking
| } | ||
|
|
||
| /// Returns whether telemetry is enabled | ||
| pub fn enabled() -> bool { |
Member
There was a problem hiding this comment.
Contributor
Author
There was a problem hiding this comment.
yeah is_enabled is fine
Member
There was a problem hiding this comment.
Ok, you should be good to rebase on top of main and unify with #256 shortly, ping when ready for a new review
Unify PR #332 (if_enabled callback pattern) with PR #256 (Option<HandleInner> structure): - TelemetryHandle methods delegate through inner.shared.if_enabled() to avoid event construction when disabled - Replace static TelemetryHandle::enabled() with TelemetryHandle::current().is_enabled() (equivalent after #256) - Keep all work inside with_encoder closures in tracing_layer (the core optimization from #332)
jlizen
approved these changes
May 2, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
To help ensure we don't regress on this, I extracted an
if_enabledwrapper that can be used as well