mirror of
https://github.com/XRPLF/rippled.git
synced 2026-07-23 23:20:33 +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:
@@ -12,6 +12,8 @@
|
||||
|
||||
#include <xrpl/telemetry/CoroAwareContextStorage.h>
|
||||
|
||||
#include <xrpl/basics/LocalValue.h>
|
||||
|
||||
#include <opentelemetry/context/context.h>
|
||||
#include <opentelemetry/context/runtime_context.h>
|
||||
#include <opentelemetry/nostd/unique_ptr.h>
|
||||
@@ -21,6 +23,20 @@ namespace xrpl::telemetry {
|
||||
opentelemetry::context::Context
|
||||
CoroAwareContextStorage::GetCurrent() noexcept
|
||||
{
|
||||
// Hot path: Log.cpp reads the current context on EVERY log line on EVERY
|
||||
// thread. Peek the raw per-thread/coro store WITHOUT materializing it:
|
||||
// getLocalValues().get() returns nullptr when this thread has no store yet
|
||||
// and never allocates. Dereferencing stack_ (a LocalValue) would instead
|
||||
// heap-allocate the store + a map entry + the vector on first touch, so we
|
||||
// avoid that on the no-span path.
|
||||
//
|
||||
// Behaviour is identical to touching *stack_: a thread with no store has no
|
||||
// active span, and a store whose stack was never pushed yields an empty
|
||||
// vector — both cases map to an empty Context, matching stock
|
||||
// ThreadLocalContextStorage (Top() returns Context() when the stack is
|
||||
// empty). Only when a store already exists do we read the top frame.
|
||||
if (detail::getLocalValues().get() == nullptr)
|
||||
return opentelemetry::context::Context{};
|
||||
auto& stack = *stack_;
|
||||
return stack.empty() ? opentelemetry::context::Context{} : stack.back();
|
||||
}
|
||||
|
||||
@@ -96,8 +96,10 @@ PendingTraceId::~PendingTraceId() noexcept
|
||||
if (!gTlsPendingConsumed)
|
||||
{
|
||||
// The assert above is stripped in release, so bump a counter too: a
|
||||
// dropped deterministic trace root stays observable via
|
||||
// unconsumedDeterministicIdDrops(). Relaxed: this is a diagnostic tally.
|
||||
// process-wide tally of dropped deterministic trace roots. It is
|
||||
// exposed via unconsumedDeterministicIdDrops() as an extension point
|
||||
// for a future metric or diagnostic to read; nothing wires it to a log
|
||||
// or metric yet. Relaxed: this is a plain diagnostic tally.
|
||||
gUnconsumedDeterministicIdDrops.fetch_add(1, std::memory_order_relaxed);
|
||||
}
|
||||
gTlsPendingTraceId.reset(); // never leak, even in release
|
||||
|
||||
Reference in New Issue
Block a user