mirror of
https://github.com/XRPLF/rippled.git
synced 2026-04-29 15:37:57 +00:00
fix(telemetry): use thread_local PRNG for span IDs and update class diagram
Replace per-call std::random_device with thread_local std::mt19937 in txSpan() for span ID generation. random_device is ~423x slower due to /dev/urandom syscalls on each construction; mt19937 is seeded once per thread and reused for all subsequent span IDs. Update the SpanGuard class ASCII diagram to include txSpan factory methods that were added in the hash-derived trace ID commit. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -9,23 +9,25 @@
|
||||
|
||||
Dependency diagram:
|
||||
|
||||
+-------------------------------------------+
|
||||
| SpanGuard |
|
||||
+-------------------------------------------+
|
||||
| - impl_ : unique_ptr<Impl> (pimpl) |
|
||||
+-------------------------------------------+
|
||||
| + span(name) : SpanGuard [static] |
|
||||
| + span(cat, prefix, name) [static] |
|
||||
| + childSpan(name) : SpanGuard |
|
||||
| + linkedSpan(name) : SpanGuard |
|
||||
| + captureContext() : SpanContext |
|
||||
| + setAttribute(key, value) |
|
||||
| + setOk() / setError(desc) |
|
||||
| + addEvent(name) |
|
||||
| + recordException(e) |
|
||||
| + discard() |
|
||||
| + operator bool() |
|
||||
+-------------------------------------------+
|
||||
+------------------------------------------------+
|
||||
| SpanGuard |
|
||||
+------------------------------------------------+
|
||||
| - impl_ : unique_ptr<Impl> (pimpl) |
|
||||
+------------------------------------------------+
|
||||
| + span(name) : SpanGuard [static] |
|
||||
| + span(cat, prefix, name) [static] |
|
||||
| + childSpan(name) : SpanGuard |
|
||||
| + linkedSpan(name) : SpanGuard |
|
||||
| + txSpan(prefix, name, hash) [static] |
|
||||
| + txSpan(prefix, name, hash, parent) [static] |
|
||||
| + captureContext() : SpanContext |
|
||||
| + setAttribute(key, value) |
|
||||
| + setOk() / setError(desc) |
|
||||
| + addEvent(name) |
|
||||
| + recordException(e) |
|
||||
| + discard() |
|
||||
| + operator bool() |
|
||||
+------------------------------------------------+
|
||||
| hides (pimpl)
|
||||
+-------+-------+
|
||||
| |
|
||||
|
||||
@@ -258,9 +258,9 @@ SpanGuard::txSpan(
|
||||
otel_trace::TraceId traceId(opentelemetry::nostd::span<std::uint8_t const, 16>(hashData, 16));
|
||||
|
||||
std::uint8_t spanIdBytes[8];
|
||||
std::random_device rd;
|
||||
thread_local std::mt19937 prng{std::random_device{}()};
|
||||
for (auto& b : spanIdBytes)
|
||||
b = static_cast<std::uint8_t>(rd());
|
||||
b = static_cast<std::uint8_t>(prng());
|
||||
otel_trace::SpanId spanId(opentelemetry::nostd::span<std::uint8_t const, 8>(spanIdBytes, 8));
|
||||
|
||||
otel_trace::SpanContext syntheticCtx(
|
||||
|
||||
Reference in New Issue
Block a user