From: Pieter Lexis Date: Wed, 12 Nov 2025 10:39:36 +0000 (+0100) Subject: feat(dnsdist): Allow setting Span Attributes from Closer X-Git-Tag: rec-5.4.0-alpha1~72^2~6 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9dc60656ec302dfbb9b2d27bb23b1e1d7084e385;p=thirdparty%2Fpdns.git feat(dnsdist): Allow setting Span Attributes from Closer --- diff --git a/pdns/dnsdistdist/dnsdist-opentelemetry.cc b/pdns/dnsdistdist/dnsdist-opentelemetry.cc index f064f7c37f..393d005767 100644 --- a/pdns/dnsdistdist/dnsdist-opentelemetry.cc +++ b/pdns/dnsdistdist/dnsdist-opentelemetry.cc @@ -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 diff --git a/pdns/dnsdistdist/dnsdist-opentelemetry.hh b/pdns/dnsdistdist/dnsdist-opentelemetry.hh index 95344c0c0a..f1ceee12d4 100644 --- a/pdns/dnsdistdist/dnsdist-opentelemetry.hh +++ b/pdns/dnsdistdist/dnsdist-opentelemetry.hh @@ -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 d_tracer{nullptr}; diff --git a/pdns/dnsdistdist/test-dnsdist-opentelemetry_cc.cc b/pdns/dnsdistdist/test-dnsdist-opentelemetry_cc.cc index c6afa31729..58bf54894c 100644 --- a/pdns/dnsdistdist/test-dnsdist-opentelemetry_cc.cc +++ b/pdns/dnsdistdist/test-dnsdist-opentelemetry_cc.cc @@ -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)