refactor(rpc): scope rpc.command spans; coro-aware storage makes RPC scopes yield-safe

rpc.command.* becomes a scoped child so it nests under rpc.process, correlates
its log lines, and parents pathfind.request. No RPC::Context plumbing needed.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Pratik Mankawde
2026-07-22 19:57:27 +01:00
parent 6a9eaedeac
commit 47a29187fd
2 changed files with 9 additions and 3 deletions

View File

@@ -162,7 +162,10 @@ template <class Object, class Method>
Status
callMethod(JsonContext& context, Method method, std::string const& name, Object& result)
{
auto span = SpanGuard::span(TraceCategory::Rpc, rpc_span::prefix::command, name);
// Scoped so this command nests under rpc.process and becomes the ambient
// parent of any command-internal spans (e.g. pathfind.request). Coro-aware
// storage keeps the scope correct across doRipplePathFind's yield.
auto span = ScopedSpanGuard(TraceCategory::Rpc, rpc_span::prefix::command, name);
span.setAttribute(rpc_span::attr::command, name.c_str());
span.setAttribute(rpc_span::attr::version, static_cast<int64_t>(context.apiVersion));
span.setAttribute(
@@ -256,7 +259,7 @@ doCommand(RPC::JsonContext& context, json::Value& result)
// registered handler names (plus "unknown") — see the helper for why
// raw request input must not reach the telemetry pipeline.
auto const cmdName = resolveCommandSpanName(context);
auto span = SpanGuard::span(TraceCategory::Rpc, rpc_span::prefix::command, cmdName);
auto span = ScopedSpanGuard(TraceCategory::Rpc, rpc_span::prefix::command, cmdName);
span.setAttribute(rpc_span::attr::command, cmdName);
span.setAttribute(rpc_span::attr::rpcStatus, rpc_span::val::error);
span.setError(getErrorInfo(error).token.cStr());

View File

@@ -652,7 +652,10 @@ ServerHandler::processRequest(
std::string_view forwardedFor,
std::string_view user)
{
// Scoped child: nests under the httpRequest span active on this thread.
// Scoped child of rpc.http_request. Safe to hold across the coroutine
// yield in doRipplePathFind: the coro-aware context storage moves this
// scope with the coroutine on resume (it is never stranded on a worker's
// thread-local stack), so nesting and log-trace correlation both hold.
auto span = ScopedSpanGuard(TraceCategory::Rpc, rpc_span::prefix::rpc, rpc_span::op::process);
auto rpcJ = app_.getJournal("RPC");