refactor(telemetry): ledger.acquire uses thread-free SpanGuard (no detach)

acquireSpan_ is emplaced on the acquiring thread and reset() on a JtLedgerData
worker. SpanGuard is now thread-free (owns no thread-local Scope), so it can be
created here and destroyed on the worker with no scope to strip — dropping the
.detached() call the old scoped SpanGuard required.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Pratik Mankawde
2026-07-22 13:30:50 +01:00
parent dd96d8ad34
commit 5150159ca2

View File

@@ -103,12 +103,11 @@ InboundLedger::init(ScopedLockType& collectionLock)
// observable. Finalized in done() with the outcome and timeout count.
{
using namespace telemetry;
// Detach the Scope: this guard is emplaced here but reset() on a
// JtLedgerData worker thread. Detaching strips the thread-local Scope
// so its destruction there does not corrupt this thread's context stack.
// acquireSpan_ is emplaced here but reset() on a JtLedgerData worker
// thread. A SpanGuard is thread-free (owns no thread-local Scope), so it
// can be created here and destroyed on the worker with no scope to strip.
acquireSpan_.emplace(
SpanGuard::span(TraceCategory::Ledger, seg::ledger, ledger_span::op::acquire)
.detached());
SpanGuard::span(TraceCategory::Ledger, seg::ledger, ledger_span::op::acquire));
if (*acquireSpan_)
{
acquireSpan_->setAttribute(ledger_span::attr::ledgerSeq, static_cast<int64_t>(seq_));