mirror of
https://github.com/XRPLF/rippled.git
synced 2026-04-29 15:37:57 +00:00
Add unknownCommand and wsUpgrade span name constants to RpcSpanNames.h, fix SpanGuardFactory tests to use the 3-argument SpanGuard::span() API, update levelization results, and apply rename script to docs. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
78 lines
2.0 KiB
C++
78 lines
2.0 KiB
C++
#include <xrpl/telemetry/SpanGuard.h>
|
|
|
|
#include <gtest/gtest.h>
|
|
|
|
using namespace xrpl;
|
|
using namespace xrpl::telemetry;
|
|
|
|
TEST(SpanGuardFactory, null_guard_methods_are_safe)
|
|
{
|
|
auto span = SpanGuard::span(TraceCategory::Rpc, "rpc", "nonexistent");
|
|
EXPECT_FALSE(span);
|
|
|
|
span.setAttribute("key", "value");
|
|
span.setAttribute("int_key", static_cast<int64_t>(42));
|
|
span.setAttribute("bool_key", true);
|
|
span.setOk();
|
|
span.setError("test");
|
|
span.addEvent("event");
|
|
}
|
|
|
|
TEST(SpanGuardFactory, category_span_returns_null_when_disabled)
|
|
{
|
|
auto span = SpanGuard::span(TraceCategory::Rpc, "rpc", "test");
|
|
EXPECT_FALSE(span);
|
|
|
|
span.setAttribute("xrpl.rpc.command", "test");
|
|
span.setAttribute("xrpl.rpc.status", "success");
|
|
}
|
|
|
|
TEST(SpanGuardFactory, child_span_null_when_no_parent)
|
|
{
|
|
auto span = SpanGuard::span(TraceCategory::Rpc, "rpc", "parent");
|
|
auto child = span.childSpan("child.test");
|
|
EXPECT_FALSE(child);
|
|
}
|
|
|
|
TEST(SpanGuardFactory, linked_span_null_when_no_context)
|
|
{
|
|
auto span = SpanGuard::span(TraceCategory::Rpc, "rpc", "source");
|
|
auto linked = span.linkedSpan("linked.test");
|
|
EXPECT_FALSE(linked);
|
|
}
|
|
|
|
TEST(SpanGuardFactory, capture_context_returns_invalid_on_null)
|
|
{
|
|
auto span = SpanGuard::span(TraceCategory::Rpc, "rpc", "ctx");
|
|
auto ctx = span.captureContext();
|
|
EXPECT_FALSE(ctx.isValid());
|
|
}
|
|
|
|
TEST(SpanGuardFactory, move_construction_transfers_ownership)
|
|
{
|
|
auto span = SpanGuard::span(TraceCategory::Rpc, "rpc", "move");
|
|
auto moved = std::move(span);
|
|
EXPECT_FALSE(span);
|
|
moved.setAttribute("key", "value");
|
|
}
|
|
|
|
TEST(SpanGuardFactory, record_exception_safe_on_null)
|
|
{
|
|
auto span = SpanGuard::span(TraceCategory::Rpc, "rpc.command", "test");
|
|
try
|
|
{
|
|
throw std::runtime_error("test error");
|
|
}
|
|
catch (std::exception const& e)
|
|
{
|
|
span.recordException(e);
|
|
}
|
|
}
|
|
|
|
TEST(SpanGuardFactory, discard_safe_on_null)
|
|
{
|
|
auto span = SpanGuard::span(TraceCategory::Transactions, "tx", "process");
|
|
span.discard();
|
|
EXPECT_FALSE(span);
|
|
}
|