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 <noreply@anthropic.com>
This commit is contained in:
Pratik Mankawde
2026-03-16 16:43:55 +00:00
parent 31d0ed178a
commit 9bb8f2e12a
3 changed files with 25 additions and 5 deletions

View File

@@ -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");

View File

@@ -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<int64_t>(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<int64_t>(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<int64_t>(prevLgr.seq() + 1));

View File

@@ -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