]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
fix(dnsdist): Move OT query information into the scope span
authorPieter Lexis <pieter.lexis@powerdns.com>
Tue, 7 Oct 2025 14:41:31 +0000 (16:41 +0200)
committerPieter Lexis <pieter.lexis@powerdns.com>
Tue, 14 Oct 2025 18:34:58 +0000 (20:34 +0200)
Signed-off-by: Pieter Lexis <pieter.lexis@powerdns.com>
pdns/dnsdistdist/dnsdist-opentelemetry.cc
pdns/dnsdistdist/test-dnsdist-opentelemetry_cc.cc
regression-tests.dnsdist/test_OpenTelemetryTracing.py

index 0beea052799a3874b86561b368dc3b6ab2cec758..f5fea72056fbdb6d2448aa66652cf50356eff078 100644 (file)
@@ -44,12 +44,10 @@ TracesData Tracer::getTracesData()
             pdns::trace::KeyValue{
               "service.name", pdns::trace::AnyValue{"dnsdist"}},
           }},
-        .scope_spans = std::vector<pdns::trace::ScopeSpans>{{}}}}};
-
-  otTrace.resource_spans.at(0).resource.attributes.insert(
-    otTrace.resource_spans.at(0).resource.attributes.end(),
-    d_attributes.begin(),
-    d_attributes.end());
+        .scope_spans = std::vector<pdns::trace::ScopeSpans>{{.scope = {
+                                                               .attributes = {d_attributes.begin(), d_attributes.end()},
+                                                             },
+                                                             .spans = {}}}}}};
 
   {
     auto lockedPre = d_preActivationSpans.read_only_lock();
index f9501c45f5ac110d4ad93d1f9e41fe33a13c8b04..847437aa327942d8f438eb030e2312402becebfb 100644 (file)
@@ -205,6 +205,8 @@ 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);
+
   // Now activate and add 2 attributes
   tracer->activate();
   tracer->setTraceAttribute("foo", AnyValue{"bar"});
@@ -212,12 +214,14 @@ BOOST_AUTO_TEST_CASE(attributes)
 
   trace = tracer->getTracesData();
 
-  BOOST_ASSERT(trace.resource_spans.at(0).resource.attributes.size() == 3);
-  BOOST_CHECK_EQUAL(trace.resource_spans.at(0).resource.attributes.at(1).key, "foo");
-  BOOST_CHECK_EQUAL(trace.resource_spans.at(0).resource.attributes.at(1).value, AnyValue{"bar"});
+  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);
+
+  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).resource.attributes.at(2).key, "baz");
-  BOOST_CHECK_EQUAL(trace.resource_spans.at(0).resource.attributes.at(2).value, AnyValue{256});
+  BOOST_CHECK_EQUAL(trace.resource_spans.at(0).scope_spans.at(0).scope.attributes.at(1).key, "baz");
+  BOOST_CHECK_EQUAL(trace.resource_spans.at(0).scope_spans.at(0).scope.attributes.at(1).value, AnyValue{256});
 
   // Add a span and some attributes
   auto spanid = tracer->openSpan("anEvent").getSpanID();
@@ -239,7 +243,7 @@ BOOST_AUTO_TEST_CASE(getOTProtobuf)
   tracer->activate();
   tracer->setTraceAttribute("foo", AnyValue{"bar"});
   data = tracer->getOTProtobuf();
-  BOOST_TEST(data.size() == 45U);
+  BOOST_TEST(data.size() == 49U);
 }
 
 BOOST_AUTO_TEST_SUITE_END()
index 83350a571052471650a25e51ee0e39ee1a58b053..a2705a95240da57dcd3c1bef964d8960930b7294 100644 (file)
@@ -62,26 +62,24 @@ class DNSDistOpenTelemetryProtobufBaseTest(DNSDistOpenTelemetryProtobufTest):
         )
 
         self.assertEqual(len(ot_data["resource_spans"]), 1)
-        self.assertEqual(len(ot_data["resource_spans"][0]["resource"]["attributes"]), 4)
+        self.assertEqual(len(ot_data["resource_spans"][0]["resource"]["attributes"]), 1)
 
         # Ensure all attributes exist
         for field in ot_data["resource_spans"][0]["resource"]["attributes"]:
-            self.assertTrue(
-                field["key"]
-                in ["service.name", "query.qname", "query.qtype", "query.remote"]
-            )
+            self.assertTrue(field["key"] in ["service.name"])
 
         # Ensure the values are correct
         # TODO: query.remote with port
-        msg_attrs = {
+        msg_scope_attrs = {
             v["key"]: v["value"]["string_value"]
-            for v in ot_data["resource_spans"][0]["resource"]["attributes"]
+            for v in ot_data["resource_spans"][0]["scope_spans"][0]["scope"][
+                "attributes"
+            ]
             if v["key"] != "query.remote"
         }
         self.assertDictEqual(
-            msg_attrs,
+            msg_scope_attrs,
             {
-                "service.name": "dnsdist",
                 "query.qname": "query.ot.tests.powerdns.com",
                 "query.qtype": "A",
             },