From 2bb0995ff8524c4aeb20483003a38fdcc7429bad Mon Sep 17 00:00:00 2001 From: Pratik Mankawde <3397372+pratikmankawde@users.noreply.github.com> Date: Mon, 27 Apr 2026 14:48:07 +0100 Subject: [PATCH] fix(telemetry): use default_prng() for span IDs, fix non-telemetry build MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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) --- src/libxrpl/telemetry/SpanGuard.cpp | 8 ++++---- src/xrpld/telemetry/TxTracing.h | 5 +---- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/src/libxrpl/telemetry/SpanGuard.cpp b/src/libxrpl/telemetry/SpanGuard.cpp index a2cbfe5ec6..3d3f52ca29 100644 --- a/src/libxrpl/telemetry/SpanGuard.cpp +++ b/src/libxrpl/telemetry/SpanGuard.cpp @@ -20,6 +20,7 @@ #ifdef XRPL_ENABLE_TELEMETRY +#include #include #include #include @@ -38,7 +39,7 @@ #include #include -#include +#include #include #include @@ -248,10 +249,9 @@ SpanGuard::txSpan( otel_trace::TraceId traceId(opentelemetry::nostd::span(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(prng()); + std::memcpy(spanIdBytes, &rval, sizeof(spanIdBytes)); otel_trace::SpanId spanId(opentelemetry::nostd::span(spanIdBytes, 8)); otel_trace::SpanContext syntheticCtx( diff --git a/src/xrpld/telemetry/TxTracing.h b/src/xrpld/telemetry/TxTracing.h index d99163ee53..9cb0f296a6 100644 --- a/src/xrpld/telemetry/TxTracing.h +++ b/src/xrpld/telemetry/TxTracing.h @@ -13,11 +13,8 @@ #include #include -#include - -#ifdef XRPL_ENABLE_TELEMETRY #include -#endif +#include namespace xrpl { namespace telemetry {