handle gTlDiscardCurrentSpan change

Signed-off-by: Pratik Mankawde <3397372+pratikmankawde@users.noreply.github.com>
This commit is contained in:
Pratik Mankawde
2026-06-10 14:00:52 +01:00
parent 38fbab1d18
commit e205d0ef8e
4 changed files with 13 additions and 6 deletions

View File

@@ -344,6 +344,14 @@ SpanGuard::discard()
{
gTlDiscardCurrentSpan = true;
impl_->span->End();
// Clear here so discard() owns the flag's whole lifetime
// (set -> End -> clear) in one scope, rather than relying on
// FilteringSpanProcessor::OnEnd() to clear it. Today every valid guard
// wraps a recording span (head sampling is 1.0), so OnEnd() always runs
// and clearing here is equivalent — but colocating set and clear keeps
// the flag leak-proof if a later phase can hand back a non-recording
// span (e.g. honoring a non-sampled remote parent during propagation).
gTlDiscardCurrentSpan = false;
impl_->span = nullptr; // prevent ~Impl from calling End() again
impl_.reset();
}

View File

@@ -122,8 +122,7 @@ public:
{
// SpanGuard::discard() set the flag on this thread just before
// calling Span::End(), which invokes OnEnd() synchronously.
// Clear the flag and drop the span.
gTlDiscardCurrentSpan = false;
// Drop the span.
return;
}
delegate_->OnEnd(std::move(span));