Merge branch 'pratik/otel-phase8-log-correlation' into pratik/otel-phase9-metric-gap-fill

This commit is contained in:
Pratik Mankawde
2026-06-01 16:12:30 +01:00
4 changed files with 35 additions and 20 deletions

View File

@@ -23,3 +23,15 @@ compiler.libcxx={{detect_api.detect_libcxx(compiler, version, compiler_exe)}}
{% if compiler == "gcc" and compiler_version < 13 %}
tools.build:cxxflags+=['-Wno-restrict']
{% endif %}
{% if os == "Windows" %}
# opentelemetry-cpp's recipe removes the `shared` option on Windows and never
# sets BUILD_SHARED_LIBS, so its upstream CMake defaults the protobuf-generated
# `opentelemetry_proto` target to a DLL (opentelemetry_proto.dll). The rest of
# the project links statically and nothing deploys that DLL next to the
# executables, so the telemetry unit test fails to start with
# STATUS_DLL_NOT_FOUND (0xC0000135). Force the dependency to build fully static
# so no runtime DLL is produced. The conf is folded into the package id so a
# fresh static binary is built instead of reusing a previously cached one.
opentelemetry-cpp/*:tools.cmake.cmaketoolchain:extra_variables={"BUILD_SHARED_LIBS": "OFF"}
opentelemetry-cpp/*:tools.info.package_id:confs+=["tools.cmake.cmaketoolchain:extra_variables"]
{% endif %}

View File

@@ -9,7 +9,11 @@
#ifdef XRPL_ENABLE_TELEMETRY
#include <opentelemetry/context/runtime_context.h>
#include <opentelemetry/trace/context.h>
#include <opentelemetry/nostd/shared_ptr.h>
#include <opentelemetry/nostd/span.h>
#include <opentelemetry/nostd/variant.h>
#include <opentelemetry/trace/span.h>
#include <opentelemetry/trace/span_metadata.h>
#endif // XRPL_ENABLE_TELEMETRY
#include <chrono>

View File

@@ -54,7 +54,7 @@
#include <opentelemetry/sdk/metrics/view/instrument_selector_factory.h>
#include <opentelemetry/sdk/metrics/view/meter_selector_factory.h>
#include <opentelemetry/sdk/metrics/view/view_factory.h>
#include <opentelemetry/sdk/resource/semantic_conventions.h>
#include <opentelemetry/semconv/incubating/service_attributes.h>
#include <atomic>
#include <chrono>
@@ -362,7 +362,7 @@ private:
* @code
* auto collector = OTelCollector::New(
* "http://localhost:4318/v1/metrics", "xrpld", journal);
* auto counter = collector->make_counter("rpc.requests");
* auto counter = collector->makeCounter("rpc.requests");
* counter.increment(1);
* // Metric "xrpld_rpc_requests" exported via OTLP every 1s.
* @endcode
@@ -393,19 +393,19 @@ public:
/** @name Collector interface implementation */
/** @{ */
Hook
make_hook(HookImpl::HandlerType const& handler) override;
makeHook(HookImpl::HandlerType const& handler) override;
Counter
make_counter(std::string const& name) override;
makeCounter(std::string const& name) override;
Event
make_event(std::string const& name) override;
makeEvent(std::string const& name) override;
Gauge
make_gauge(std::string const& name) override;
makeGauge(std::string const& name) override;
Meter
make_meter(std::string const& name) override;
makeMeter(std::string const& name) override;
/** @} */
/** @name Hook management for observable callbacks */
@@ -680,9 +680,9 @@ OTelCollectorImp::OTelCollectorImp(
// Include service.instance.id when provided so Prometheus
// exported_instance labels distinguish multi-node deployments.
resource::ResourceAttributes attrs;
attrs[resource::SemanticConventions::kServiceName] = "xrpld";
attrs[opentelemetry::semconv::service::kServiceName] = "xrpld";
if (!instanceId.empty())
attrs[resource::SemanticConventions::kServiceInstanceId] = instanceId;
attrs[opentelemetry::semconv::service::kServiceInstanceId] = instanceId;
auto resourceAttrs = resource::Resource::Create(attrs);
// Create MeterProvider with resource, then attach the metric reader.
@@ -701,7 +701,6 @@ OTelCollectorImp::OTelCollectorImp(
auto histogramView = metrics_sdk::ViewFactory::Create(
"default_histogram",
"Default histogram view with SpanMetrics-compatible buckets",
"ms",
metrics_sdk::AggregationType::kHistogram,
std::move(histogramConfig));
@@ -729,32 +728,32 @@ OTelCollectorImp::~OTelCollectorImp()
}
Hook
OTelCollectorImp::make_hook(HookImpl::HandlerType const& handler)
OTelCollectorImp::makeHook(HookImpl::HandlerType const& handler)
{
return Hook(std::make_shared<OTelHookImpl>(handler, shared_from_this()));
}
Counter
OTelCollectorImp::make_counter(std::string const& name)
OTelCollectorImp::makeCounter(std::string const& name)
{
return Counter(std::make_shared<OTelCounterImpl>(formatName(name), m_otelMeter));
}
Event
OTelCollectorImp::make_event(std::string const& name)
OTelCollectorImp::makeEvent(std::string const& name)
{
return Event(std::make_shared<OTelEventImpl>(formatName(name), m_otelMeter));
}
Gauge
OTelCollectorImp::make_gauge(std::string const& name)
OTelCollectorImp::makeGauge(std::string const& name)
{
return Gauge(
std::make_shared<OTelGaugeImpl>(formatName(name), m_otelMeter, shared_from_this()));
}
Meter
OTelCollectorImp::make_meter(std::string const& name)
OTelCollectorImp::makeMeter(std::string const& name)
{
return Meter(std::make_shared<OTelMeterImpl>(formatName(name), m_otelMeter));
}
@@ -871,7 +870,7 @@ OTelCollector::New(
std::string const& /* instanceId */,
Journal /* journal */)
{
return NullCollector::New();
return NullCollector::make();
}
} // namespace beast::insight

View File

@@ -48,9 +48,11 @@
#include <exception>
#include <initializer_list>
#include <memory>
#include <string>
#include <string_view>
#include <typeinfo>
#include <utility>
#include <vector>
namespace xrpl::telemetry {
@@ -463,9 +465,7 @@ SpanGuard::addEvent(std::string_view name, std::initializer_list<EventAttribute>
// OTel's AddEvent template requires a key-value-iterable; a plain
// std::vector<std::pair<...>> doesn't satisfy is_key_value_iterable.
// Wrap in nostd::span over the vector's storage so the SDK accepts it.
std::vector<std::pair<
opentelemetry::noopentelemetry::nostd::string_view,
opentelemetry::common::AttributeValue>>
std::vector<std::pair<opentelemetry::nostd::string_view, opentelemetry::common::AttributeValue>>
otelAttrs;
otelAttrs.reserve(attrs.size());