From 17e69e660c634191f293ab82433879debbb461be Mon Sep 17 00:00:00 2001 From: Pratik Mankawde <3397372+pratikmankawde@users.noreply.github.com> Date: Wed, 29 Apr 2026 13:00:39 +0100 Subject: [PATCH] feat(telemetry): add toDisplayString() and use Title Case in consensus attributes Co-Authored-By: Claude Opus 4.6 --- src/xrpld/app/consensus/RCLConsensus.cpp | 8 ++++---- src/xrpld/consensus/ConsensusTypes.h | 20 ++++++++++++++++++++ 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/src/xrpld/app/consensus/RCLConsensus.cpp b/src/xrpld/app/consensus/RCLConsensus.cpp index 5280e9eb5d..a09409ee64 100644 --- a/src/xrpld/app/consensus/RCLConsensus.cpp +++ b/src/xrpld/app/consensus/RCLConsensus.cpp @@ -357,7 +357,7 @@ RCLConsensus::Adaptor::onClose( span.setAttribute( telemetry::cons_span::attr::ledgerSeq, static_cast(ledger.ledger_->header().seq + 1)); - span.setAttribute(telemetry::cons_span::attr::mode, to_string(mode).c_str()); + span.setAttribute(telemetry::cons_span::attr::mode, toDisplayString(mode).c_str()); bool const wrongLCL = mode == ConsensusMode::wrongLedger; bool const proposing = mode == ConsensusMode::proposing; @@ -1018,8 +1018,8 @@ RCLConsensus::Adaptor::onModeChange(ConsensusMode before, ConsensusMode after) telemetry::TraceCategory::Consensus, telemetry::seg::consensus, telemetry::cons_span::op::modeChange); - span.setAttribute(telemetry::cons_span::attr::modeOld, to_string(before).c_str()); - span.setAttribute(telemetry::cons_span::attr::modeNew, to_string(after).c_str()); + span.setAttribute(telemetry::cons_span::attr::modeOld, toDisplayString(before).c_str()); + span.setAttribute(telemetry::cons_span::attr::modeNew, toDisplayString(after).c_str()); JLOG(j_.info()) << "Consensus mode change before=" << to_string(before) << ", after=" << to_string(after); @@ -1218,7 +1218,7 @@ RCLConsensus::Adaptor::startRoundTracing(RCLCxLedger const& prevLgr) roundSpan_->setAttribute(cons_span::attr::ledgerId, to_string(prevLgr.id()).c_str()); roundSpan_->setAttribute(cons_span::attr::ledgerSeq, static_cast(prevLgr.seq() + 1)); - roundSpan_->setAttribute(cons_span::attr::mode, to_string(mode_.load()).c_str()); + roundSpan_->setAttribute(cons_span::attr::mode, toDisplayString(mode_.load()).c_str()); roundSpan_->setAttribute(cons_span::attr::traceStrategy, strategy.c_str()); roundSpan_->setAttribute(cons_span::attr::roundId, static_cast(prevLgr.seq() + 1)); diff --git a/src/xrpld/consensus/ConsensusTypes.h b/src/xrpld/consensus/ConsensusTypes.h index 8a81211722..bfbcddcb42 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