mirror of
https://github.com/XRPLF/rippled.git
synced 2026-04-29 15:37:57 +00:00
fix(telemetry): use default_prng() for span IDs, fix non-telemetry build
Replace thread_local mt19937 with xrpl::default_prng() for span ID generation — uses the project's existing thread-local xor-shift engine. One call yields a uint64_t (8 bytes), filling the span ID in a single memcpy without loops. Fix compilation failure when XRPL_ENABLE_TELEMETRY is not defined: move xrpl.pb.h include outside the #ifdef guard in TxTracing.h since protocol::TMTransaction is used unconditionally in the function signature. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -20,6 +20,7 @@
|
||||
|
||||
#ifdef XRPL_ENABLE_TELEMETRY
|
||||
|
||||
#include <xrpl/basics/random.h>
|
||||
#include <xrpl/telemetry/DiscardFlag.h>
|
||||
#include <xrpl/telemetry/SpanGuard.h>
|
||||
#include <xrpl/telemetry/SpanNames.h>
|
||||
@@ -38,7 +39,7 @@
|
||||
#include <opentelemetry/trace/trace_id.h>
|
||||
#include <opentelemetry/trace/tracer.h>
|
||||
|
||||
#include <random>
|
||||
#include <cstring>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
|
||||
@@ -248,10 +249,9 @@ SpanGuard::txSpan(
|
||||
|
||||
otel_trace::TraceId traceId(opentelemetry::nostd::span<std::uint8_t const, 16>(hashData, 16));
|
||||
|
||||
auto const rval = default_prng()();
|
||||
std::uint8_t spanIdBytes[8];
|
||||
thread_local std::mt19937 prng{std::random_device{}()};
|
||||
for (auto& b : spanIdBytes)
|
||||
b = static_cast<std::uint8_t>(prng());
|
||||
std::memcpy(spanIdBytes, &rval, sizeof(spanIdBytes));
|
||||
otel_trace::SpanId spanId(opentelemetry::nostd::span<std::uint8_t const, 8>(spanIdBytes, 8));
|
||||
|
||||
otel_trace::SpanContext syntheticCtx(
|
||||
|
||||
@@ -13,11 +13,8 @@
|
||||
#include <xrpld/app/misc/TxSpanNames.h>
|
||||
|
||||
#include <xrpl/basics/base_uint.h>
|
||||
#include <xrpl/telemetry/SpanGuard.h>
|
||||
|
||||
#ifdef XRPL_ENABLE_TELEMETRY
|
||||
#include <xrpl/proto/xrpl.pb.h>
|
||||
#endif
|
||||
#include <xrpl/telemetry/SpanGuard.h>
|
||||
|
||||
namespace xrpl {
|
||||
namespace telemetry {
|
||||
|
||||
Reference in New Issue
Block a user