mirror of
https://github.com/XRPLF/rippled.git
synced 2026-08-23 07:10:53 +00:00
The native OTel metrics path hard-coded service.name="xrpld" and stamped no network attribute, while traces stamped a configurable service.name and xrpl.network.type. Metrics therefore could not be filtered by service or network. Align the two paths: - OTelCollector::New / OTelCollectorImp gain serviceName + networkType params. service.name uses the configured value (default "xrpld" when unset, preserving today's behavior); xrpl.network.type is stamped when provided. The key is a string literal because beast/insight sits below the telemetry module and cannot include its SpanNames const. - CollectorManager reads service_name from [insight], falling back to the [telemetry] value, and receives the network type from the caller. - Application derives the network type once via the shared telemetry::networkTypeFromId, now declared in Telemetry.h and moved out of an anonymous namespace so the trace and metric paths reuse a single 0/1/2 -> mainnet/testnet/devnet mapping (no duplication). Dashboards (5 system-* files): add $service_name, $deployment_environment, $xrpl_network_type template variables and wire them into every panel query that filters by $node. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
108 lines
3.6 KiB
C++
108 lines
3.6 KiB
C++
#include <xrpld/app/main/CollectorManager.h>
|
|
|
|
#include <xrpl/beast/insight/Collector.h>
|
|
#include <xrpl/beast/insight/Group.h>
|
|
#include <xrpl/beast/insight/Groups.h>
|
|
#include <xrpl/beast/insight/NullCollector.h>
|
|
#include <xrpl/beast/insight/OTelCollector.h>
|
|
#include <xrpl/beast/insight/StatsDCollector.h>
|
|
#include <xrpl/beast/net/IPEndpoint.h>
|
|
#include <xrpl/beast/utility/Journal.h>
|
|
#include <xrpl/config/BasicConfig.h>
|
|
#include <xrpl/config/Constants.h>
|
|
|
|
#include <memory>
|
|
#include <string>
|
|
|
|
namespace xrpl {
|
|
|
|
class CollectorManagerImp : public CollectorManager
|
|
{
|
|
public:
|
|
// NOLINTBEGIN(readability-identifier-naming)
|
|
beast::Journal journal_;
|
|
beast::insight::Collector::ptr collector_;
|
|
std::unique_ptr<beast::insight::Groups> groups_;
|
|
// NOLINTEND(readability-identifier-naming)
|
|
|
|
CollectorManagerImp(
|
|
Section const& params,
|
|
std::string const& serviceName,
|
|
std::string const& networkType,
|
|
beast::Journal journal)
|
|
: journal_(journal)
|
|
{
|
|
std::string const& server = get(params, Keys::kServer);
|
|
|
|
if (server == "statsd")
|
|
{
|
|
beast::IP::Endpoint const address(
|
|
beast::IP::Endpoint::fromString(get(params, Keys::kAddress)));
|
|
std::string const& prefix(get(params, Keys::kPrefix));
|
|
|
|
collector_ = beast::insight::StatsDCollector::make(address, prefix, journal);
|
|
}
|
|
// LCOV_EXCL_START -- OTel collector path is not exercised in unit tests
|
|
else if (server == "otel")
|
|
{
|
|
// Read OTLP metrics endpoint from [insight] section.
|
|
// Default to the standard OTLP/HTTP metrics path on localhost.
|
|
std::string endpoint = get(params, "endpoint");
|
|
if (endpoint.empty())
|
|
endpoint = "http://localhost:4318/v1/metrics";
|
|
std::string const& prefix(get(params, "prefix"));
|
|
|
|
// Read service_instance_id, same key as the [telemetry]
|
|
// section uses, so multi-node deployments can distinguish
|
|
// metric sources via the exported_instance Prometheus label.
|
|
std::string const instanceId = get(params, "service_instance_id");
|
|
|
|
// service.name from [insight] (falls back to the value the
|
|
// caller derived from [telemetry]); network type derived from
|
|
// [network_id]. Both mirror the trace exporter so metrics and
|
|
// traces carry the same service and network identity.
|
|
std::string serviceNameCfg = get(params, "service_name");
|
|
if (serviceNameCfg.empty())
|
|
serviceNameCfg = serviceName;
|
|
|
|
collector_ = beast::insight::OTelCollector::New(
|
|
endpoint, prefix, instanceId, serviceNameCfg, networkType, journal);
|
|
}
|
|
// LCOV_EXCL_STOP
|
|
else
|
|
{
|
|
collector_ = beast::insight::NullCollector::make();
|
|
}
|
|
|
|
groups_ = beast::insight::makeGroups(collector_);
|
|
}
|
|
|
|
~CollectorManagerImp() override = default;
|
|
|
|
beast::insight::Collector::ptr const&
|
|
collector() override
|
|
{
|
|
return collector_;
|
|
}
|
|
|
|
beast::insight::Group::ptr const&
|
|
group(std::string const& name) override
|
|
{
|
|
return groups_->get(name);
|
|
}
|
|
};
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
std::unique_ptr<CollectorManager>
|
|
makeCollectorManager(
|
|
Section const& params,
|
|
std::string const& serviceName,
|
|
std::string const& networkType,
|
|
beast::Journal journal)
|
|
{
|
|
return std::make_unique<CollectorManagerImp>(params, serviceName, networkType, journal);
|
|
}
|
|
|
|
} // namespace xrpl
|