mirror of
https://github.com/XRPLF/rippled.git
synced 2026-04-29 15:37:57 +00:00
refactor(telemetry): extract TX span name constants into TxSpanNames.h
Move scattered string literals from PeerImp.cpp and NetworkOPs.cpp into compile-time constants in src/xrpld/telemetry/TxSpanNames.h. Follows the same StaticStr/join() pattern established in Phase 1c for RPC spans. Constants cover: span prefixes (tx), operations (receive, process), attribute keys (hash, local, path, suppressed, status, peerId, peerVersion), and values (sync, async, knownBad). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -34,6 +34,7 @@
|
||||
#include <xrpld/rpc/DeliveredAmount.h>
|
||||
#include <xrpld/rpc/MPTokenIssuanceID.h>
|
||||
#include <xrpld/rpc/ServerHandler.h>
|
||||
#include <xrpld/telemetry/TxSpanNames.h>
|
||||
|
||||
#include <xrpl/basics/Log.h>
|
||||
#include <xrpl/basics/ToString.h>
|
||||
@@ -1313,9 +1314,10 @@ NetworkOPsImp::processTransaction(
|
||||
FailHard failType)
|
||||
{
|
||||
using namespace telemetry;
|
||||
auto span = SpanGuard::span(TraceCategory::Transactions, "tx", "process");
|
||||
span.setAttribute("xrpl.tx.hash", to_string(transaction->getID()).c_str());
|
||||
span.setAttribute("xrpl.tx.local", bLocal);
|
||||
auto span =
|
||||
SpanGuard::span(TraceCategory::Transactions, tx_span::prefix::tx, tx_span::op::process);
|
||||
span.setAttribute(tx_span::attr::hash, to_string(transaction->getID()).c_str());
|
||||
span.setAttribute(tx_span::attr::local, bLocal);
|
||||
|
||||
auto ev = m_job_queue.makeLoadEvent(jtTXN_PROC, "ProcessTXN");
|
||||
|
||||
@@ -1325,12 +1327,12 @@ NetworkOPsImp::processTransaction(
|
||||
|
||||
if (bLocal)
|
||||
{
|
||||
span.setAttribute("xrpl.tx.path", "sync");
|
||||
span.setAttribute(tx_span::attr::path, tx_span::val::sync);
|
||||
doTransactionSync(transaction, bUnlimited, failType);
|
||||
}
|
||||
else
|
||||
{
|
||||
span.setAttribute("xrpl.tx.path", "async");
|
||||
span.setAttribute(tx_span::attr::path, tx_span::val::async);
|
||||
doTransactionAsync(transaction, bUnlimited, failType);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
#include <xrpld/overlay/detail/Tuning.h>
|
||||
#include <xrpld/peerfinder/PeerfinderManager.h>
|
||||
#include <xrpld/peerfinder/Slot.h>
|
||||
#include <xrpld/telemetry/TxSpanNames.h>
|
||||
|
||||
#include <xrpl/basics/Log.h>
|
||||
#include <xrpl/basics/SHAMapHash.h>
|
||||
@@ -1423,10 +1424,11 @@ PeerImp::handleTransaction(
|
||||
bool batch)
|
||||
{
|
||||
using namespace telemetry;
|
||||
auto span = SpanGuard::span(TraceCategory::Transactions, "tx", "receive");
|
||||
span.setAttribute("xrpl.peer.id", static_cast<int64_t>(id_));
|
||||
auto span =
|
||||
SpanGuard::span(TraceCategory::Transactions, tx_span::prefix::tx, tx_span::op::receive);
|
||||
span.setAttribute(tx_span::attr::peerId, static_cast<int64_t>(id_));
|
||||
if (auto const version = getVersion(); !version.empty())
|
||||
span.setAttribute("xrpl.peer.version", version.c_str());
|
||||
span.setAttribute(tx_span::attr::peerVersion, version.c_str());
|
||||
|
||||
XRPL_ASSERT(eraseTxQueue != batch, ("xrpl::PeerImp::handleTransaction : valid inputs"));
|
||||
if (tracking_.load() == Tracking::diverged)
|
||||
@@ -1446,7 +1448,7 @@ PeerImp::handleTransaction(
|
||||
{
|
||||
auto stx = std::make_shared<STTx const>(sit);
|
||||
uint256 const txID = stx->getTransactionID();
|
||||
span.setAttribute("xrpl.tx.hash", to_string(txID).c_str());
|
||||
span.setAttribute(tx_span::attr::hash, to_string(txID).c_str());
|
||||
|
||||
// Charge strongly for attempting to relay a txn with tfInnerBatchTxn
|
||||
// LCOV_EXCL_START
|
||||
@@ -1480,11 +1482,11 @@ PeerImp::handleTransaction(
|
||||
|
||||
if (!app_.getHashRouter().shouldProcess(txID, id_, flags, tx_interval))
|
||||
{
|
||||
span.setAttribute("xrpl.tx.suppressed", true);
|
||||
span.setAttribute(tx_span::attr::suppressed, true);
|
||||
// we have seen this transaction recently
|
||||
if (any(flags & HashRouterFlags::BAD))
|
||||
{
|
||||
span.setAttribute("xrpl.tx.status", "known_bad");
|
||||
span.setAttribute(tx_span::attr::status, tx_span::val::knownBad);
|
||||
fee_.update(Resource::feeUselessData, "known bad");
|
||||
JLOG(p_journal_.debug()) << "Ignoring known bad tx " << txID;
|
||||
}
|
||||
|
||||
72
src/xrpld/telemetry/TxSpanNames.h
Normal file
72
src/xrpld/telemetry/TxSpanNames.h
Normal file
@@ -0,0 +1,72 @@
|
||||
#pragma once
|
||||
|
||||
/** Compile-time span name constants for transaction tracing.
|
||||
*
|
||||
* Used by PeerImp (overlay) and NetworkOPs (app) for transaction
|
||||
* lifecycle spans. Built on StaticStr/join() from SpanNames.h.
|
||||
*
|
||||
* Span hierarchy:
|
||||
*
|
||||
* Node A (sender) Node B (receiver)
|
||||
* +------------------+ +------------------+
|
||||
* | tx.process | protobuf | tx.receive |
|
||||
* | injectTo | ---------> | extractFrom |
|
||||
* | Protobuf() | trace_ctx | Protobuf() |
|
||||
* +------------------+ +------------------+
|
||||
*/
|
||||
|
||||
#include <xrpl/telemetry/SpanNames.h>
|
||||
|
||||
namespace xrpl {
|
||||
namespace telemetry {
|
||||
namespace tx_span {
|
||||
|
||||
// ===== Span prefixes =======================================================
|
||||
|
||||
namespace prefix {
|
||||
/// "tx" — root prefix for transaction lifecycle spans.
|
||||
inline constexpr auto tx = seg::tx;
|
||||
} // namespace prefix
|
||||
|
||||
// ===== Span operation suffixes =============================================
|
||||
|
||||
namespace op {
|
||||
inline constexpr auto receive = makeStr("receive");
|
||||
inline constexpr auto process = makeStr("process");
|
||||
} // namespace op
|
||||
|
||||
// ===== Attribute keys ======================================================
|
||||
|
||||
namespace attr {
|
||||
inline constexpr auto xrplTx = join(seg::xrpl, seg::tx);
|
||||
|
||||
/// "xrpl.tx.hash"
|
||||
inline constexpr auto hash = join(xrplTx, makeStr("hash"));
|
||||
/// "xrpl.tx.local"
|
||||
inline constexpr auto local = join(xrplTx, makeStr("local"));
|
||||
/// "xrpl.tx.path"
|
||||
inline constexpr auto path = join(xrplTx, makeStr("path"));
|
||||
/// "xrpl.tx.suppressed"
|
||||
inline constexpr auto suppressed = join(xrplTx, makeStr("suppressed"));
|
||||
/// "xrpl.tx.status"
|
||||
inline constexpr auto status = join(xrplTx, makeStr("status"));
|
||||
|
||||
inline constexpr auto xrplPeer = join(seg::xrpl, seg::peer);
|
||||
|
||||
/// "xrpl.peer.id"
|
||||
inline constexpr auto peerId = join(xrplPeer, makeStr("id"));
|
||||
/// "xrpl.peer.version"
|
||||
inline constexpr auto peerVersion = join(xrplPeer, makeStr("version"));
|
||||
} // namespace attr
|
||||
|
||||
// ===== Attribute values ====================================================
|
||||
|
||||
namespace val {
|
||||
inline constexpr auto sync = makeStr("sync");
|
||||
inline constexpr auto async = makeStr("async");
|
||||
inline constexpr auto knownBad = makeStr("known_bad");
|
||||
} // namespace val
|
||||
|
||||
} // namespace tx_span
|
||||
} // namespace telemetry
|
||||
} // namespace xrpl
|
||||
Reference in New Issue
Block a user