From 9bb8f2e12a22368d74c42a98a36d275bdf532b8d Mon Sep 17 00:00:00 2001 From: Pratik Mankawde <3397372+pratikmankawde@users.noreply.github.com> Date: Mon, 16 Mar 2026 16:43:55 +0000 Subject: [PATCH] Use Title Case for consensus mode names in telemetry attributes Add toDisplayString(ConsensusMode) helper that returns Title Case names (Proposing, Observing, Wrong Ledger, Switched Ledger) for use in OTel span attributes and Grafana dashboards. The existing to_string() is preserved unchanged for log output stability. Updated call sites: - RCLConsensus.cpp: onClose, onModeChange, startRoundInternal - TracingMacros.cpp: test attribute value Co-Authored-By: Claude Opus 4.6 --- src/tests/libxrpl/telemetry/TracingMacros.cpp | 2 +- src/xrpld/app/consensus/RCLConsensus.cpp | 8 ++++---- src/xrpld/consensus/ConsensusTypes.h | 20 +++++++++++++++++++ 3 files changed, 25 insertions(+), 5 deletions(-) diff --git a/src/tests/libxrpl/telemetry/TracingMacros.cpp b/src/tests/libxrpl/telemetry/TracingMacros.cpp index c65fb92488..fc22ce9523 100644 --- a/src/tests/libxrpl/telemetry/TracingMacros.cpp +++ b/src/tests/libxrpl/telemetry/TracingMacros.cpp @@ -27,7 +27,7 @@ TEST(TracingMacros, macros_with_null_telemetry) } { XRPL_TRACE_CONSENSUS(*tel, "consensus.test"); - XRPL_TRACE_SET_ATTR("xrpl.consensus.mode", "proposing"); + XRPL_TRACE_SET_ATTR("xrpl.consensus.mode", "Proposing"); } { XRPL_TRACE_PEER(*tel, "peer.test"); diff --git a/src/xrpld/app/consensus/RCLConsensus.cpp b/src/xrpld/app/consensus/RCLConsensus.cpp index a38e79b9c7..5f39799e09 100644 --- a/src/xrpld/app/consensus/RCLConsensus.cpp +++ b/src/xrpld/app/consensus/RCLConsensus.cpp @@ -341,7 +341,7 @@ RCLConsensus::Adaptor::onClose( XRPL_TRACE_CONSENSUS(app_.getTelemetry(), "consensus.ledger_close"); XRPL_TRACE_SET_ATTR( "xrpl.consensus.ledger.seq", static_cast(ledger.ledger_->header().seq + 1)); - XRPL_TRACE_SET_ATTR("xrpl.consensus.mode", to_string(mode).c_str()); + XRPL_TRACE_SET_ATTR("xrpl.consensus.mode", toDisplayString(mode).c_str()); bool const wrongLCL = mode == ConsensusMode::wrongLedger; bool const proposing = mode == ConsensusMode::proposing; @@ -939,8 +939,8 @@ RCLConsensus::Adaptor::onModeChange(ConsensusMode before, ConsensusMode after) // trace backend. Each transition (e.g. observing -> proposing) appears // as a child of the current consensus.round span. XRPL_TRACE_CONSENSUS(app_.getTelemetry(), "consensus.mode_change"); - XRPL_TRACE_SET_ATTR("xrpl.consensus.mode.old", to_string(before).c_str()); - XRPL_TRACE_SET_ATTR("xrpl.consensus.mode.new", to_string(after).c_str()); + XRPL_TRACE_SET_ATTR("xrpl.consensus.mode.old", toDisplayString(before).c_str()); + XRPL_TRACE_SET_ATTR("xrpl.consensus.mode.new", toDisplayString(after).c_str()); JLOG(j_.info()) << "Consensus mode change before=" << to_string(before) << ", after=" << to_string(after); @@ -1174,7 +1174,7 @@ RCLConsensus::Adaptor::startRoundTracing(RCLCxLedger const& prevLgr) // Set standard attributes on the round span. roundSpan_->setAttribute("xrpl.consensus.ledger_id", to_string(prevLgr.id()).c_str()); roundSpan_->setAttribute("xrpl.consensus.ledger.seq", static_cast(prevLgr.seq() + 1)); - roundSpan_->setAttribute("xrpl.consensus.mode", to_string(mode_.load()).c_str()); + roundSpan_->setAttribute("xrpl.consensus.mode", toDisplayString(mode_.load()).c_str()); roundSpan_->setAttribute("xrpl.consensus.trace_strategy", strategy.c_str()); roundSpan_->setAttribute("xrpl.consensus.round_id", static_cast(prevLgr.seq() + 1)); diff --git a/src/xrpld/consensus/ConsensusTypes.h b/src/xrpld/consensus/ConsensusTypes.h index 2331c9dfbf..21f7e04637 100644 --- a/src/xrpld/consensus/ConsensusTypes.h +++ b/src/xrpld/consensus/ConsensusTypes.h @@ -66,6 +66,26 @@ to_string(ConsensusMode m) } } +/// Title Case display name for telemetry attributes and dashboards. +/// Separate from to_string() which is used in logs and must remain stable. +inline std::string +toDisplayString(ConsensusMode m) +{ + switch (m) + { + case ConsensusMode::proposing: + return "Proposing"; + case ConsensusMode::observing: + return "Observing"; + case ConsensusMode::wrongLedger: + return "Wrong Ledger"; + case ConsensusMode::switchedLedger: + return "Switched Ledger"; + default: + return "Unknown"; + } +} + /** Phases of consensus for a single ledger round. @code