mirror of
https://github.com/XRPLF/rippled.git
synced 2026-06-03 00:36:48 +00:00
feat(telemetry): add cross-node trace context propagation
Wire trace context into P2P message flow so distributed traces link across nodes. TX relay injects SpanGuard context via PropagationHelpers.h; consensus propose/validate injects via TraceContextPropagator.h. Receive-side extraction in PeerImp creates child spans for proposals and validations. - Add TraceBytes struct and SpanGuard::getTraceBytes() for extracting raw trace context without OTel type dependencies - Add PropagationHelpers.h: injectSpanContext(SpanGuard, proto) - Add ConsensusReceiveTracing.h: proposalReceiveSpan(), validationReceiveSpan() with parent context extraction - NetworkOPs::apply(): inject tx.process context before relay - RCLConsensus::propose()/validate(): inject active span context - PeerImp: create receive spans for proposals and validations with sender's trace context as parent Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -20,6 +20,7 @@
|
||||
| + hashSpan(cat, name, hash) [static] |
|
||||
| + hashSpan(cat, name, hash, parent) [static] |
|
||||
| + captureContext() : SpanContext |
|
||||
| + getTraceBytes() : TraceBytes |
|
||||
| + setAttribute(key, value) |
|
||||
| + setOk() / setError(desc) |
|
||||
| + addEvent(name) |
|
||||
@@ -116,6 +117,7 @@
|
||||
exposed — all interaction goes through the public methods.
|
||||
*/
|
||||
|
||||
#include <array>
|
||||
#include <cstdint>
|
||||
#include <exception>
|
||||
#include <memory>
|
||||
@@ -131,6 +133,26 @@ namespace xrpl::telemetry {
|
||||
*/
|
||||
enum class TraceCategory { Rpc, Transactions, Consensus, Peer, Ledger };
|
||||
|
||||
/** Raw trace context bytes for cross-node propagation.
|
||||
|
||||
Holds the binary trace_id, span_id, and trace_flags extracted from
|
||||
an active span. Used by protocol-layer code to inject trace context
|
||||
into outgoing protobuf messages without depending on OTel types.
|
||||
|
||||
@see SpanGuard::getTraceBytes(), TraceContextPropagator.h
|
||||
*/
|
||||
struct TraceBytes
|
||||
{
|
||||
/// 16-byte W3C trace identifier.
|
||||
std::array<std::uint8_t, 16> traceId{};
|
||||
/// 8-byte span identifier of the current span.
|
||||
std::array<std::uint8_t, 8> spanId{};
|
||||
/// W3C trace flags (bit 0 = sampled).
|
||||
std::uint8_t traceFlags{0};
|
||||
/// True if this struct contains valid data from an active span.
|
||||
bool valid{false};
|
||||
};
|
||||
|
||||
/** Opaque wrapper for an OTel context snapshot.
|
||||
|
||||
Used to propagate trace context across threads. Created by
|
||||
@@ -288,6 +310,18 @@ public:
|
||||
[[nodiscard]] SpanContext
|
||||
captureContext() const;
|
||||
|
||||
/** Extract raw trace context bytes from this span for propagation.
|
||||
|
||||
Unlike captureContext() which captures the thread-local runtime
|
||||
context, this method reads the span's own SpanContext directly.
|
||||
Safe to call from any thread that holds a reference to this guard.
|
||||
|
||||
@return A TraceBytes struct with valid=true if the span is active
|
||||
and has a valid context, or valid=false otherwise.
|
||||
*/
|
||||
[[nodiscard]] TraceBytes
|
||||
getTraceBytes() const;
|
||||
|
||||
// --- Attribute setters (explicit overloads, no OTel types) ---------
|
||||
|
||||
/** Set a string attribute. No-op on a null guard. */
|
||||
@@ -416,6 +450,11 @@ public:
|
||||
{
|
||||
return {};
|
||||
}
|
||||
[[nodiscard]] TraceBytes
|
||||
getTraceBytes() const
|
||||
{
|
||||
return {};
|
||||
}
|
||||
// NOLINTEND(readability-convert-member-functions-to-static)
|
||||
|
||||
void
|
||||
|
||||
@@ -4,8 +4,14 @@
|
||||
|
||||
Provides serialization/deserialization of OTel trace context to/from
|
||||
Protocol Buffer TraceContext messages (P2P cross-node propagation).
|
||||
Wired into the P2P message flow via PropagationHelpers.h for
|
||||
TMTransaction, TMProposeSet, and TMValidation messages.
|
||||
|
||||
Only compiled when XRPL_ENABLE_TELEMETRY is defined.
|
||||
|
||||
@see PropagationHelpers.h (high-level inject helpers),
|
||||
TxTracing.h (transaction receive-side extraction),
|
||||
ConsensusReceiveTracing.h (proposal/validation receive-side).
|
||||
*/
|
||||
|
||||
#ifdef XRPL_ENABLE_TELEMETRY
|
||||
|
||||
Reference in New Issue
Block a user