mirror of
https://github.com/XRPLF/rippled.git
synced 2026-07-23 15:10:34 +00:00
Merge branch 'pratik/otel-phase1c-rpc-integration' into pratik/otel-phase2-rpc-tracing
Brings review fixes: no-alloc GetCurrent hot path, activateIfLive helper, non-copyable storage, accurate drop-counter doc. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -86,6 +86,17 @@ class CoroAwareContextStorage : public opentelemetry::context::RuntimeContextSto
|
||||
public:
|
||||
CoroAwareContextStorage() = default;
|
||||
|
||||
// Non-copyable and non-movable: the LocalValue store is keyed by the
|
||||
// address of stack_, so copying or moving would mis-key the store and
|
||||
// strand its entries. Only ever new-ed once and installed on the SDK, so
|
||||
// these are for intent/safety rather than a live bug.
|
||||
CoroAwareContextStorage(CoroAwareContextStorage const&) = delete;
|
||||
CoroAwareContextStorage&
|
||||
operator=(CoroAwareContextStorage const&) = delete;
|
||||
CoroAwareContextStorage(CoroAwareContextStorage&&) = delete;
|
||||
CoroAwareContextStorage&
|
||||
operator=(CoroAwareContextStorage&&) = delete;
|
||||
|
||||
/**
|
||||
* @return the current (top-of-stack) context for this coro/thread.
|
||||
*/
|
||||
|
||||
@@ -814,6 +814,24 @@ public:
|
||||
operator=(ScopedActivation const&) = delete;
|
||||
};
|
||||
|
||||
/**
|
||||
* Activate a span guard as the ambient context if it is live, else return a
|
||||
* no-op activation. Accepts any handle (shared_ptr / optional) that is
|
||||
* contextually convertible to bool and dereferences to a SpanGuard. Non-owning:
|
||||
* the handle still owns/ends the span. Returns a null ScopedActivation when the
|
||||
* handle is empty or the span is inactive (e.g. telemetry disabled).
|
||||
* @param guard A shared_ptr<SpanGuard> or optional<SpanGuard>.
|
||||
* @return An RAII activation; drop it to restore the prior context.
|
||||
*/
|
||||
template <class SpanGuardHandle>
|
||||
[[nodiscard]] ScopedActivation
|
||||
activateIfLive(SpanGuardHandle const& guard)
|
||||
{
|
||||
if (guard && *guard)
|
||||
return guard->activate();
|
||||
return ScopedActivation{};
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// No-op stub (all inline, zero overhead, no OTel dependency)
|
||||
// ---------------------------------------------------------------------------
|
||||
@@ -1063,6 +1081,22 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* No-op counterpart to the telemetry-enabled activateIfLive(). Same signature
|
||||
* and handle contract (shared_ptr / optional of SpanGuard); always yields a
|
||||
* null ScopedActivation because a stub guard is never live.
|
||||
* @param guard A shared_ptr<SpanGuard> or optional<SpanGuard>.
|
||||
* @return A null (no-op) ScopedActivation.
|
||||
*/
|
||||
template <class SpanGuardHandle>
|
||||
[[nodiscard]] ScopedActivation
|
||||
activateIfLive(SpanGuardHandle const& guard)
|
||||
{
|
||||
if (guard && *guard)
|
||||
return guard->activate();
|
||||
return ScopedActivation{};
|
||||
}
|
||||
|
||||
#endif // XRPL_ENABLE_TELEMETRY
|
||||
|
||||
} // namespace xrpl::telemetry
|
||||
|
||||
Reference in New Issue
Block a user