From: Pieter Lexis Date: Tue, 14 Oct 2025 11:09:39 +0000 (+0200) Subject: feat(dnsdist): add hostname and version to scopespan X-Git-Tag: rec-5.4.0-alpha1~187^2~5 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e1b86952f721ba511cd6908be37e890ccf4a2031;p=thirdparty%2Fpdns.git feat(dnsdist): add hostname and version to scopespan --- diff --git a/pdns/dnsdistdist/dnsdist-opentelemetry.cc b/pdns/dnsdistdist/dnsdist-opentelemetry.cc index 822f385bea..1cbb4ba1c3 100644 --- a/pdns/dnsdistdist/dnsdist-opentelemetry.cc +++ b/pdns/dnsdistdist/dnsdist-opentelemetry.cc @@ -21,6 +21,7 @@ */ #include "dnsdist-opentelemetry.hh" +#include "misc.hh" #include @@ -31,6 +32,10 @@ namespace pdns::trace::dnsdist { +#ifndef DISABLE_PROTOBUF +static const KeyValue hostnameAttr{.key = "hostname", .value = {getHostname().value_or("")}}; +#endif + TracesData Tracer::getTracesData() { #ifdef DISABLE_PROTOBUF @@ -38,17 +43,18 @@ TracesData Tracer::getTracesData() #else auto otTrace = pdns::trace::TracesData{ .resource_spans = { - pdns::trace::ResourceSpans{ - .resource = { - .attributes = std::vector{ - pdns::trace::KeyValue{ - "service.name", pdns::trace::AnyValue{"dnsdist"}}, - }}, - .scope_spans = std::vector{{.scope = { - .name = "queryFromFrontend", - .attributes = {d_attributes.begin(), d_attributes.end()}, - }, - .spans = {}}}}}}; + {.resource = { + .attributes = { + {"service.name", {"dnsdist"}}, + }}, + .scope_spans = {{.scope = { + .name = "dnsdist/queryFromFrontend", + .version = PACKAGE_VERSION, + .attributes = {d_attributes.begin(), d_attributes.end()}, + }, + .spans = {}}}}}}; + + otTrace.resource_spans.at(0).scope_spans.at(0).scope.attributes.push_back(hostnameAttr); { auto lockedPre = d_preActivationSpans.read_only_lock(); diff --git a/pdns/dnsdistdist/dnsdist-opentelemetry.hh b/pdns/dnsdistdist/dnsdist-opentelemetry.hh index bdb17a4d3c..e4480f6a3e 100644 --- a/pdns/dnsdistdist/dnsdist-opentelemetry.hh +++ b/pdns/dnsdistdist/dnsdist-opentelemetry.hh @@ -303,7 +303,7 @@ private: */ LockGuarded> d_postActivationSpans; /** - * @brief All attributes related to this Trace + * @brief All attributes related to this Trace (added to the ScopeSpan) */ std::vector d_attributes; diff --git a/pdns/dnsdistdist/test-dnsdist-opentelemetry_cc.cc b/pdns/dnsdistdist/test-dnsdist-opentelemetry_cc.cc index 49364631be..32d03a2cb8 100644 --- a/pdns/dnsdistdist/test-dnsdist-opentelemetry_cc.cc +++ b/pdns/dnsdistdist/test-dnsdist-opentelemetry_cc.cc @@ -205,7 +205,9 @@ BOOST_AUTO_TEST_CASE(attributes) BOOST_CHECK_EQUAL(trace.resource_spans.at(0).resource.attributes.size(), 1); BOOST_CHECK_EQUAL(trace.resource_spans.at(0).resource.attributes.at(0).key, "service.name"); - BOOST_ASSERT(trace.resource_spans.at(0).scope_spans.at(0).scope.attributes.size() == 0); + // Check if we have a hostname + BOOST_CHECK_EQUAL(trace.resource_spans.at(0).scope_spans.at(0).scope.attributes.size(), 1U); + BOOST_CHECK_EQUAL(trace.resource_spans.at(0).scope_spans.at(0).scope.attributes.at(0).key, "hostname"); // Now activate and add 2 attributes tracer->activate(); @@ -215,7 +217,8 @@ BOOST_AUTO_TEST_CASE(attributes) trace = tracer->getTracesData(); BOOST_ASSERT(trace.resource_spans.at(0).resource.attributes.size() == 1); - BOOST_ASSERT(trace.resource_spans.at(0).scope_spans.at(0).scope.attributes.size() == 2); + // hostname plus the two we set + BOOST_ASSERT(trace.resource_spans.at(0).scope_spans.at(0).scope.attributes.size() == 3); BOOST_CHECK_EQUAL(trace.resource_spans.at(0).scope_spans.at(0).scope.attributes.at(0).key, "foo"); BOOST_CHECK_EQUAL(trace.resource_spans.at(0).scope_spans.at(0).scope.attributes.at(0).value, AnyValue{"bar"}); @@ -238,12 +241,12 @@ BOOST_AUTO_TEST_CASE(getOTProtobuf) { auto tracer = pdns::trace::dnsdist::Tracer::getTracer(); auto data = tracer->getOTProtobuf(); - BOOST_TEST(data.size() == 54U); + BOOST_TEST(data.size() >= 100U); tracer->activate(); tracer->setTraceAttribute("foo", AnyValue{"bar"}); data = tracer->getOTProtobuf(); - BOOST_TEST(data.size() == 68U); + BOOST_TEST(data.size() >= 110U); } BOOST_AUTO_TEST_SUITE_END()