mirror of
https://github.com/XRPLF/rippled.git
synced 2026-06-05 01:37:00 +00:00
Phase-3 (PR #6425) is scoped to transaction tracing only; consensus tracing belongs to phase-4 (PR #6426). The previous commit on this branch removed the namespace/attribute scaffoldingc6c019ed8bleaked into phase-3, but phase-3 still carried the consensus span construction and trace-context propagation introduced in earlier commits (61cb1faf8f,93bed03d8d). Move that out too so phase-3 creates and propagates no consensus spans of any kind. Removed: - src/xrpld/telemetry/ConsensusReceiveTracing.h (deleted; phase-4 owns it). - PeerImp.cpp: remove the std::make_shared<SpanGuard>( proposalReceiveSpan(...))/validationReceiveSpan(...) constructions in onMessage(TMProposeSet)/onMessage(TMValidation), drop the sp = std::move(span) lambda captures, and drop the #include <xrpld/telemetry/ConsensusReceiveTracing.h>. - RCLConsensus.cpp: drop the two telemetry::injectToProtobuf() blocks that injected the active trace context into TMProposeSet (in Adaptor::propose, after addSuppression) and TMValidation (in Adaptor::validate, around the broadcast call). Drop the now-unused #include of TraceContextPropagator.h and the XRPL_ENABLE_TELEMETRY-gated include of opentelemetry/context/runtime_context.h. - TraceContextPropagator.h: update file-level @see comment to drop the ConsensusReceiveTracing.h reference and to scope the "wired into the P2P message flow via PropagationHelpers.h" sentence to TMTransaction only. - PropagationHelpers.h: replace the @see ConsensusReceiveTracing.h cross-reference with @see TxTracing.h. Inert consensus metadata (TraceCategory::Consensus enum value, seg::consensus constant, isCategoryEnabled/categoryToSpanKind switch arms, the SpanGuard.h doc-comment example) is intentionally preserved on phase-3: nothing references it after this commit, but phase-4 needs it and removing it would widen the phase-3 -> phase-4 merge surface for no benefit. Verified via git grep: no remaining phase-3 references to proposalReceiveSpan, validationReceiveSpan, ConsensusReceiveTracing, consensus_span::, consensus.proposal, or consensus.validation. Signed-off-by: Pratik Mankawde <3397372+pratikmankawde@users.noreply.github.com>
99 lines
3.2 KiB
C++
99 lines
3.2 KiB
C++
#pragma once
|
|
|
|
/** Utilities for trace context propagation across nodes.
|
|
|
|
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 messages.
|
|
|
|
Only compiled when XRPL_ENABLE_TELEMETRY is defined.
|
|
|
|
@see PropagationHelpers.h (high-level inject helpers),
|
|
TxTracing.h (transaction receive-side extraction).
|
|
*/
|
|
|
|
#ifdef XRPL_ENABLE_TELEMETRY
|
|
|
|
#include <xrpl/proto/xrpl.pb.h>
|
|
|
|
#include <opentelemetry/context/context.h>
|
|
#include <opentelemetry/trace/context.h>
|
|
#include <opentelemetry/trace/default_span.h>
|
|
#include <opentelemetry/trace/span_context.h>
|
|
#include <opentelemetry/trace/trace_flags.h>
|
|
#include <opentelemetry/trace/trace_id.h>
|
|
|
|
#include <cstdint>
|
|
|
|
namespace xrpl {
|
|
namespace telemetry {
|
|
|
|
/** Extract OTel context from a protobuf TraceContext message.
|
|
|
|
@param proto The protobuf TraceContext received from a peer.
|
|
@return An OTel Context with the extracted parent span, or an empty
|
|
context if the protobuf fields are missing or invalid.
|
|
*/
|
|
inline opentelemetry::context::Context
|
|
extractFromProtobuf(protocol::TraceContext const& proto)
|
|
{
|
|
namespace trace = opentelemetry::trace;
|
|
|
|
if (!proto.has_trace_id() || proto.trace_id().size() != 16 || !proto.has_span_id() ||
|
|
proto.span_id().size() != 8)
|
|
{
|
|
return opentelemetry::context::Context{};
|
|
}
|
|
|
|
auto const* rawTraceId = reinterpret_cast<std::uint8_t const*>(proto.trace_id().data());
|
|
auto const* rawSpanId = reinterpret_cast<std::uint8_t const*>(proto.span_id().data());
|
|
trace::TraceId const traceId(
|
|
opentelemetry::nostd::span<std::uint8_t const, 16>(rawTraceId, 16));
|
|
trace::SpanId const spanId(opentelemetry::nostd::span<std::uint8_t const, 8>(rawSpanId, 8));
|
|
trace::TraceFlags const flags(
|
|
proto.has_trace_flags() ? static_cast<std::uint8_t>(proto.trace_flags())
|
|
: static_cast<std::uint8_t>(0));
|
|
|
|
trace::SpanContext const spanCtx(traceId, spanId, flags, /* remote = */ true);
|
|
|
|
return opentelemetry::context::Context{}.SetValue(
|
|
trace::kSpanKey,
|
|
opentelemetry::nostd::shared_ptr<trace::Span>(new trace::DefaultSpan(spanCtx)));
|
|
}
|
|
|
|
/** Inject the current span's trace context into a protobuf TraceContext.
|
|
|
|
@param ctx The OTel context containing the span to propagate.
|
|
@param proto The protobuf TraceContext to populate.
|
|
*/
|
|
inline void
|
|
injectToProtobuf(opentelemetry::context::Context const& ctx, protocol::TraceContext& proto)
|
|
{
|
|
namespace trace = opentelemetry::trace;
|
|
|
|
auto const span = trace::GetSpan(ctx);
|
|
if (!span)
|
|
return;
|
|
|
|
auto const& spanCtx = span->GetContext();
|
|
if (!spanCtx.IsValid())
|
|
return;
|
|
|
|
// Serialize trace_id (16 bytes)
|
|
auto const& traceId = spanCtx.trace_id();
|
|
proto.set_trace_id(traceId.Id().data(), trace::TraceId::kSize);
|
|
|
|
// Serialize span_id (8 bytes)
|
|
auto const& spanId = spanCtx.span_id();
|
|
proto.set_span_id(spanId.Id().data(), trace::SpanId::kSize);
|
|
|
|
// Serialize flags
|
|
proto.set_trace_flags(spanCtx.trace_flags().flags());
|
|
}
|
|
|
|
} // namespace telemetry
|
|
} // namespace xrpl
|
|
|
|
#endif // XRPL_ENABLE_TELEMETRY
|