feat(telemetry): add toDisplayString() and use Title Case in consensus attributes

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Pratik Mankawde
2026-04-29 13:00:39 +01:00
parent ef10c754b1
commit 17e69e660c
2 changed files with 24 additions and 4 deletions

View File

@@ -357,7 +357,7 @@ RCLConsensus::Adaptor::onClose(
span.setAttribute(
telemetry::cons_span::attr::ledgerSeq,
static_cast<int64_t>(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<int64_t>(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<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