]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
feat(dnsdist): Add instance field to OT Trace messages 16741/head
authorPieter Lexis <pieter.lexis@powerdns.com>
Tue, 20 Jan 2026 09:28:16 +0000 (10:28 +0100)
committerPieter Lexis <pieter.lexis@powerdns.com>
Fri, 6 Mar 2026 14:24:45 +0000 (15:24 +0100)
And drop hostname as a result.

pdns/dnsdistdist/dnsdist-actions-factory.cc
pdns/dnsdistdist/dnsdist-opentelemetry.cc
pdns/dnsdistdist/test-dnsdist-opentelemetry_cc.cc
regression-tests.dnsdist/test_OpenTelemetryTracing.py

index 9488a73cfb52ee1d412fedb2f383677813e803f7..aa843ad45bfd9c5b5502bf09944501df974b5237 100644 (file)
@@ -29,6 +29,7 @@
 
 #include "config.h"
 #include "dnsdist-configuration.hh"
+#include "dnsdist-opentelemetry.hh"
 #include "dnsdist.hh"
 #include "dnsdist-async.hh"
 #include "dnsdist-dnsparser.hh"
@@ -1741,6 +1742,7 @@ public:
     tracer->setRootSpanAttribute("query.qtype", AnyValue{QType(dnsquestion->ids.qtype).toString()});
     tracer->setRootSpanAttribute("query.remote.address", AnyValue{dnsquestion->ids.origRemote.toString()});
     tracer->setRootSpanAttribute("query.remote.port", AnyValue{dnsquestion->ids.origRemote.getPort()});
+    tracer->setTraceAttribute("instance", AnyValue{dnsdist::configuration::getCurrentRuntimeConfiguration().d_server_id});
 
     if (d_sendDownstreamTraceparent) {
       dnsquestion->ids.sendTraceParentToDownstreamID = d_traceparentOptionCode;
index cf2df4f825b1053a47daa1b3afa0aec2dc17b16c..45e76d9a61ae01f118fadc2074fda6799a7978fc 100644 (file)
@@ -21,7 +21,6 @@
  */
 
 #include "dnsdist-opentelemetry.hh"
-#include "misc.hh"
 #include "dnsdist-ecs.hh"
 
 #include <memory>
 namespace pdns::trace::dnsdist
 {
 
-#ifndef DISABLE_PROTOBUF
-static const KeyValue hostnameAttr{.key = "hostname", .value = {getHostname().value_or("")}};
-#endif
-
 TracesData Tracer::getTracesData()
 {
 #ifdef DISABLE_PROTOBUF
@@ -59,8 +54,6 @@ TracesData Tracer::getTracesData()
                           },
                           .spans = {}}}}}};
 
-    otTrace.resource_spans.at(0).scope_spans.at(0).scope.attributes.push_back(hostnameAttr);
-
     for (auto const& span : data->d_spans) {
       otTrace.resource_spans.at(0).scope_spans.at(0).spans.push_back(
         {
index ec51839eed32471bc6964b8339c4a361f34b96a3..fec5e51e506e8902dae86363dc4ad60a37fdb2af 100644 (file)
@@ -152,12 +152,10 @@ BOOST_AUTO_TEST_CASE(traceAttributes)
   BOOST_CHECK_EQUAL(trace.resource_spans.at(0).resource.attributes.at(0).key, "service.name");
 
   // Check if we have a hostname
-  BOOST_CHECK_EQUAL(trace.resource_spans.at(0).scope_spans.at(0).scope.attributes.size(), 2U);
+  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, "foo");
   BOOST_CHECK_EQUAL(trace.resource_spans.at(0).scope_spans.at(0).scope.attributes.at(0).value, AnyValue{"bar"});
-
-  BOOST_CHECK_EQUAL(trace.resource_spans.at(0).scope_spans.at(0).scope.attributes.at(1).key, "hostname");
 }
 
 BOOST_AUTO_TEST_CASE(spanAttributes)
@@ -200,11 +198,11 @@ BOOST_AUTO_TEST_CASE(getOTProtobuf)
 {
   auto tracer = pdns::trace::dnsdist::Tracer::getTracer();
   auto data = tracer->getOTProtobuf();
-  BOOST_TEST(data.size() >= 100U);
+  BOOST_TEST(data.size() >= 50U);
 
   tracer->setTraceAttribute("foo", AnyValue{"bar"});
   data = tracer->getOTProtobuf();
-  BOOST_TEST(data.size() >= 110U);
+  BOOST_TEST(data.size() >= 60U);
 }
 
 BOOST_AUTO_TEST_CASE(setTraceID)
index f3a24da22d60f286b7b86c1544c04ca544905687..fe16ec00eb4fe55f5f6ac9cfdd4921adfb7907e8 100644 (file)
@@ -104,7 +104,7 @@ class DNSDistOpenTelemetryProtobufTest(test_Protobuf.DNSDistProtobufTest):
                 "attributes"
             ]
         ]
-        self.assertListEqual(msg_scope_attr_keys, ["hostname"])
+        self.assertListEqual(msg_scope_attr_keys, ["instance"])
 
         root_span_attr_keys = [
             v["key"]