]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
feat(dnsdist): Allow setting Span Attributes from Closer
authorPieter Lexis <pieter.lexis@powerdns.com>
Wed, 12 Nov 2025 10:39:36 +0000 (11:39 +0100)
committerPieter Lexis <pieter.lexis@powerdns.com>
Fri, 14 Nov 2025 15:03:56 +0000 (16:03 +0100)
pdns/dnsdistdist/dnsdist-opentelemetry.cc
pdns/dnsdistdist/dnsdist-opentelemetry.hh
pdns/dnsdistdist/test-dnsdist-opentelemetry_cc.cc

index f064f7c37f3b0d4b8e21615e59069a1cdd6966fd..393d005767ef9e0b8bab1f97f2b85085c994bad8 100644 (file)
@@ -281,4 +281,13 @@ SpanID Tracer::Closer::getSpanID() const
 #endif
 }
 
+void Tracer::Closer::setAttribute([[maybe_unused]] const std::string& key, [[maybe_unused]] const AnyValue& value)
+{
+#ifdef DISABLE_PROTOBUF
+  return;
+#else
+  return d_tracer->setSpanAttribute(d_spanID, key, value);
+#endif
+}
+
 } // namespace pdns::trace::dnsdist
index 95344c0c0aecb63e29c12ba1957ed9b9c732bda0..f1ceee12d475ed5a15b3699e00a025b079af6f0f 100644 (file)
@@ -224,6 +224,15 @@ public:
      */
     [[nodiscard]] SpanID getSpanID() const;
 
+    /**
+     * @brief Set an attribute on the Span
+     *
+     * @param key
+     * @param value
+     * @return
+     */
+    void setAttribute(const std::string& key, const AnyValue& value);
+
   private:
 #ifndef DISABLE_PROTOBUF
     std::shared_ptr<Tracer> d_tracer{nullptr};
index c6afa31729e04bc52df4334ae00681e6f3ca23d4..58bf54894c33a0c7fc757ea96504e31923f2c728 100644 (file)
@@ -154,12 +154,17 @@ BOOST_AUTO_TEST_CASE(spanAttributes)
   auto closer = tracer->openSpan("myspan");
   auto spanid = closer.getSpanID();
   tracer->setSpanAttribute(spanid, "foo", AnyValue{42});
+  closer.setAttribute("bar", AnyValue{"hello"});
   auto trace = tracer->getTracesData();
 
   BOOST_CHECK_EQUAL(trace.resource_spans.at(0).scope_spans.at(0).spans.size(), 1U);
-  BOOST_CHECK_EQUAL(trace.resource_spans.at(0).scope_spans.at(0).spans.at(0).attributes.size(), 1U);
+
+  BOOST_CHECK_EQUAL(trace.resource_spans.at(0).scope_spans.at(0).spans.at(0).attributes.size(), 2U);
   BOOST_CHECK_EQUAL(trace.resource_spans.at(0).scope_spans.at(0).spans.at(0).attributes.at(0).key, "foo");
   BOOST_CHECK_EQUAL(trace.resource_spans.at(0).scope_spans.at(0).spans.at(0).attributes.at(0).value, AnyValue{42});
+
+  BOOST_CHECK_EQUAL(trace.resource_spans.at(0).scope_spans.at(0).spans.at(0).attributes.at(1).key, "bar");
+  BOOST_CHECK_EQUAL(trace.resource_spans.at(0).scope_spans.at(0).spans.at(0).attributes.at(1).value, AnyValue{"hello"});
 }
 
 BOOST_AUTO_TEST_CASE(rootSpanAttributes)