Repository navigation
User span discard - #276
Merged
Merged
Conversation
mar-cf
force-pushed
the
user-span-discard
branch
from
October 9, 2026 11:47
5c6868a to
2bcb1da
Compare
Discarding user spans needs `Span::discard`, which cf-rustracing 1.4.1 adds. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Some user spans only turn out to be uninteresting after the work they measure, e.g. a routing span when nothing matched. Creating them lazily would lose the real start time, and there was no way to drop a span once created. Add `UserSpan::discard` and the ambient `user_tracing::discard_span`. Discarding replaces the span with an inactive one under its write lock, using `Span::discard`, so every handle stops recording and nothing is reported. The sampling flag is cached per handle, so only the discarding handle's cache is reset; other handles may still report being sampled while recording nothing. A deferred root that wasn't activated yet is unaffected and can still be activated. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
TheJokr
reviewed
Oct 9, 2026
`SharedSpan` cached whether a span is sampled in each handle, and cloning a handle copied the cache. Discarding a user span only reset the handle it was called on, so other handles kept reporting it as sampled through `UserSpan::is_sampled`. `discard_span` discards through a clone taken from the scope stack, which left even the caller's `UserSpan` reporting the span as sampled. Deferred roots avoided stale copies with a sentinel that made every check take the span's lock until the root was activated. Keep the flag next to the span instead, in a `UserSpanSlot` shared by every handle to a user span. Activation and discard update it under the span's write lock, and reading it never takes the lock. Internal spans never change after creation, so the handle variant implies their flag, or `Tracked` stores it for `track_all_spans`. Internal handles keep their `Arc<RwLock<Span>>`, which `rustracing_span` returns. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
mar-cf
force-pushed
the
user-span-discard
branch
from
October 9, 2026 14:09
2bcb1da to
34ef259
Compare
mar-cf
commented
Oct 9, 2026
| } | ||
| } | ||
|
|
||
| pub(crate) fn with_read<R>(&self, f: impl FnOnce(&Span) -> R) -> R { |
Contributor
Author
There was a problem hiding this comment.
Should we check sampling in with_read and with_write to avoid taking the span's lock when it isn't sampled?
Collaborator
There was a problem hiding this comment.
wouldn't hurt but lets do that in a separate PR
Collaborator
There was a problem hiding this comment.
i can do this as part of the release PR
TheJokr
approved these changes
Oct 9, 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.
cloudflare/rustracing#13
Some user spans only turn out to be uninteresting after the work they measure, e.g. a routing
span when nothing matched. Creating them lazily would lose the real start time, and there was no
way to drop a span once created.
Add
UserSpan::discardand the ambientuser_tracing::discard_span. Discarding replaces the spanwith an inactive one under its write lock, using
Span::discard, so every handle stops recordingand nothing is reported. The sampling flag is cached per handle, so only the discarding handle's
cache is reset; other handles may still report being sampled while recording nothing. A deferred
root that wasn't activated yet is unaffected and can still be activated.