mirror of
https://github.com/XRPLF/rippled.git
synced 2026-07-27 00:50:45 +00:00
Merge branch 'pratik/otel-phase8-log-correlation' into pratik/otel-phase9-metric-gap-fill
This commit is contained in:
@@ -3,6 +3,8 @@
|
|||||||
#ifdef XRPL_ENABLE_TELEMETRY
|
#ifdef XRPL_ENABLE_TELEMETRY
|
||||||
|
|
||||||
#include <opentelemetry/sdk/trace/id_generator.h>
|
#include <opentelemetry/sdk/trace/id_generator.h>
|
||||||
|
#include <opentelemetry/trace/span_id.h>
|
||||||
|
#include <opentelemetry/trace/trace_id.h>
|
||||||
|
|
||||||
#include <array>
|
#include <array>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
|||||||
@@ -16,6 +16,7 @@
|
|||||||
#include <xrpl/beast/utility/instrumentation.h>
|
#include <xrpl/beast/utility/instrumentation.h>
|
||||||
|
|
||||||
#include <opentelemetry/nostd/span.h>
|
#include <opentelemetry/nostd/span.h>
|
||||||
|
#include <opentelemetry/sdk/trace/id_generator.h>
|
||||||
#include <opentelemetry/sdk/trace/random_id_generator_factory.h>
|
#include <opentelemetry/sdk/trace/random_id_generator_factory.h>
|
||||||
#include <opentelemetry/trace/span_id.h>
|
#include <opentelemetry/trace/span_id.h>
|
||||||
#include <opentelemetry/trace/trace_id.h>
|
#include <opentelemetry/trace/trace_id.h>
|
||||||
@@ -32,14 +33,14 @@ namespace {
|
|||||||
* Trace_id pinned by PendingTraceId, consumed by GenerateTraceId(). File-local
|
* Trace_id pinned by PendingTraceId, consumed by GenerateTraceId(). File-local
|
||||||
* and thread-local, so it is set and read on the same thread with no locking.
|
* and thread-local, so it is set and read on the same thread with no locking.
|
||||||
*/
|
*/
|
||||||
thread_local std::optional<std::array<std::uint8_t, 16>> tlsPendingTraceId;
|
thread_local std::optional<std::array<std::uint8_t, 16>> gTlsPendingTraceId;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* True once GenerateTraceId() has consumed the pending id. ~PendingTraceId
|
* True once GenerateTraceId() has consumed the pending id. ~PendingTraceId
|
||||||
* asserts on it to catch a forced-root span that never reached the SDK root
|
* asserts on it to catch a forced-root span that never reached the SDK root
|
||||||
* branch.
|
* branch.
|
||||||
*/
|
*/
|
||||||
thread_local bool tlsPendingConsumed = false;
|
thread_local bool gTlsPendingConsumed = false;
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
@@ -52,11 +53,11 @@ DeterministicIdGenerator::DeterministicIdGenerator()
|
|||||||
opentelemetry::trace::TraceId
|
opentelemetry::trace::TraceId
|
||||||
DeterministicIdGenerator::GenerateTraceId() noexcept
|
DeterministicIdGenerator::GenerateTraceId() noexcept
|
||||||
{
|
{
|
||||||
if (tlsPendingTraceId)
|
if (gTlsPendingTraceId)
|
||||||
{
|
{
|
||||||
auto const id = *tlsPendingTraceId;
|
auto const id = *gTlsPendingTraceId;
|
||||||
tlsPendingTraceId.reset();
|
gTlsPendingTraceId.reset();
|
||||||
tlsPendingConsumed = true;
|
gTlsPendingConsumed = true;
|
||||||
return opentelemetry::trace::TraceId(
|
return opentelemetry::trace::TraceId(
|
||||||
opentelemetry::nostd::span<std::uint8_t const, 16>(id.data(), 16));
|
opentelemetry::nostd::span<std::uint8_t const, 16>(id.data(), 16));
|
||||||
}
|
}
|
||||||
@@ -71,8 +72,8 @@ DeterministicIdGenerator::GenerateSpanId() noexcept
|
|||||||
|
|
||||||
PendingTraceId::PendingTraceId(std::array<std::uint8_t, 16> const& id) noexcept
|
PendingTraceId::PendingTraceId(std::array<std::uint8_t, 16> const& id) noexcept
|
||||||
{
|
{
|
||||||
tlsPendingTraceId = id;
|
gTlsPendingTraceId = id;
|
||||||
tlsPendingConsumed = false;
|
gTlsPendingConsumed = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
PendingTraceId::~PendingTraceId() noexcept
|
PendingTraceId::~PendingTraceId() noexcept
|
||||||
@@ -81,10 +82,10 @@ PendingTraceId::~PendingTraceId() noexcept
|
|||||||
// via GenerateTraceId(). If not, the SDK took a different branch than the
|
// via GenerateTraceId(). If not, the SDK took a different branch than the
|
||||||
// caller forced — a bug — so fail loudly in debug/test builds.
|
// caller forced — a bug — so fail loudly in debug/test builds.
|
||||||
XRPL_ASSERT(
|
XRPL_ASSERT(
|
||||||
tlsPendingConsumed,
|
gTlsPendingConsumed,
|
||||||
"xrpl::telemetry::PendingTraceId : deterministic trace_id was not consumed");
|
"xrpl::telemetry::PendingTraceId : deterministic trace_id was not consumed");
|
||||||
tlsPendingTraceId.reset(); // never leak, even in release
|
gTlsPendingTraceId.reset(); // never leak, even in release
|
||||||
tlsPendingConsumed = false;
|
gTlsPendingConsumed = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace xrpl::telemetry
|
} // namespace xrpl::telemetry
|
||||||
|
|||||||
@@ -15,7 +15,6 @@
|
|||||||
#include <xrpl/json/json_writer.h>
|
#include <xrpl/json/json_writer.h>
|
||||||
#include <xrpl/ledger/LedgerTiming.h>
|
#include <xrpl/ledger/LedgerTiming.h>
|
||||||
#include <xrpl/telemetry/SpanGuard.h>
|
#include <xrpl/telemetry/SpanGuard.h>
|
||||||
#include <xrpl/telemetry/SpanNames.h>
|
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
|
|||||||
Reference in New Issue
Block a user