mirror of
https://github.com/XRPLF/rippled.git
synced 2026-06-04 17:27:00 +00:00
Clang-tidy fixes: - Concatenate nested namespaces (modernize-concat-nested-namespaces) in OTelCollector.h, OTelCollector.cpp, ValidationTracker.h/.cpp - Add missing direct includes (misc-include-cleaner) in ValidationTracker.cpp, test, CollectorManager.cpp, OTelCollector.cpp - Make lock_guard variables const (misc-const-correctness) - Add braces around single-line if/else (readability-braces-around-statements) - Use designated initializer for WindowEvent (modernize-use-designated-initializers) - Initialize LedgerEvent::seq field (cppcoreguidelines-pro-type-member-init) Linker fix: - Add ValidationTracker.cpp as source to xrpl.test.telemetry target (it lives in src/xrpld/ but the test links against libxrpl only) Levelization fix: - Remove stale dependency edges from ordering.txt that were introduced by the erroneous develop-merge commit Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
91 lines
3.4 KiB
C++
91 lines
3.4 KiB
C++
#pragma once
|
|
|
|
/**
|
|
* @file OTelCollector.h
|
|
* @brief OpenTelemetry-based implementation of the beast::insight::Collector
|
|
* interface for native OTLP metric export.
|
|
*
|
|
* When XRPL_ENABLE_TELEMETRY is defined, OTelCollector maps each
|
|
* beast::insight instrument type (Counter, Gauge, Event, Meter, Hook) to
|
|
* the corresponding OpenTelemetry Metrics SDK instrument and exports
|
|
* them via OTLP/HTTP to an OpenTelemetry Collector.
|
|
*
|
|
* When XRPL_ENABLE_TELEMETRY is NOT defined, OTelCollector::New() returns
|
|
* a NullCollector so the binary compiles without OTel dependencies.
|
|
*
|
|
* Dependency diagram:
|
|
*
|
|
* +-----------------+ +-------------------+
|
|
* | Collector (ABC) |<----| OTelCollector |
|
|
* +-----------------+ | (public header) |
|
|
* ^ +-------------------+
|
|
* | |
|
|
* +-----------------+ +-------------------+
|
|
* | NullCollector | | OTelCollectorImp |
|
|
* | (fallback when | | (impl in .cpp, |
|
|
* | no telemetry) | | uses OTel SDK) |
|
|
* +-----------------+ +-------------------+
|
|
* |
|
|
* +-------------------+
|
|
* | OTel Metrics SDK |
|
|
* | MeterProvider |
|
|
* | OTLP HTTP Metric |
|
|
* | Exporter |
|
|
* +-------------------+
|
|
*/
|
|
|
|
#include <xrpl/beast/insight/Collector.h>
|
|
#include <xrpl/beast/utility/Journal.h>
|
|
|
|
#include <memory>
|
|
#include <string>
|
|
|
|
namespace beast::insight {
|
|
|
|
/**
|
|
* @brief A Collector that exports metrics via OpenTelemetry OTLP/HTTP.
|
|
*
|
|
* Replaces StatsD-based metric collection with native OTel Metrics SDK
|
|
* instruments. Each beast::insight instrument maps to an OTel equivalent:
|
|
*
|
|
* - Counter -> OTel Counter<uint64_t>
|
|
* - Gauge -> OTel ObservableGauge<int64_t> (async callback)
|
|
* - Event -> OTel Histogram<double> (duration in milliseconds)
|
|
* - Meter -> OTel Counter<uint64_t> (monotonic, unsigned)
|
|
* - Hook -> Called by PeriodicMetricReader at collection time
|
|
*
|
|
* @see StatsDCollector for the StatsD-based alternative.
|
|
* @see NullCollector for the no-op fallback.
|
|
*/
|
|
class OTelCollector : public Collector
|
|
{
|
|
public:
|
|
explicit OTelCollector() = default;
|
|
|
|
/**
|
|
* @brief Factory method to create an OTelCollector instance.
|
|
*
|
|
* When XRPL_ENABLE_TELEMETRY is defined, creates a real OTel-backed
|
|
* collector that exports metrics via OTLP/HTTP. When telemetry is
|
|
* disabled at compile time, returns a NullCollector.
|
|
*
|
|
* @param endpoint OTLP/HTTP metrics endpoint URL
|
|
* (e.g. "http://localhost:4318/v1/metrics").
|
|
* @param prefix Prefix prepended to all metric names
|
|
* (e.g. "xrpld").
|
|
* @param instanceId Unique identifier for this node instance,
|
|
* emitted as the `service.instance.id` OTel
|
|
* resource attribute. Defaults to empty string
|
|
* (attribute omitted when empty).
|
|
* @param journal Journal for logging.
|
|
* @return Shared pointer to the created Collector.
|
|
*/
|
|
static std::shared_ptr<Collector>
|
|
New(std::string const& endpoint,
|
|
std::string const& prefix,
|
|
std::string const& instanceId,
|
|
Journal journal);
|
|
};
|
|
|
|
} // namespace beast::insight
|