From: Pieter Lexis Date: Tue, 14 Oct 2025 11:12:02 +0000 (+0200) Subject: fix(dnsdist): make the rootspan the parent of processResponse X-Git-Tag: rec-5.4.0-alpha1~187^2~3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f5d26f9bab90fdbfbe84d826c976684369e354e8;p=thirdparty%2Fpdns.git fix(dnsdist): make the rootspan the parent of processResponse --- diff --git a/pdns/dnsdistdist/dnsdist-opentelemetry.cc b/pdns/dnsdistdist/dnsdist-opentelemetry.cc index 60c64ac2d0..ab1185c9f2 100644 --- a/pdns/dnsdistdist/dnsdist-opentelemetry.cc +++ b/pdns/dnsdistdist/dnsdist-opentelemetry.cc @@ -215,6 +215,21 @@ void Tracer::setSpanAttribute([[maybe_unused]] const SpanID& spanid, [[maybe_unu #endif } +SpanID Tracer::getRootSpanID() +{ +#ifdef DISABLE_PROTOBUF + return 0; +#else + if (auto spans = d_preActivationSpans.read_only_lock(); spans->size() != 0) { + auto iter = std::find_if(spans->cbegin(), spans->cend(), [](const auto& span) { return span.parent_span_id == pdns::trace::s_emptySpanID; }); + if (iter != spans->cend()) { + return iter->span_id; + } + } + return SpanID{}; +#endif +} + SpanID Tracer::getLastSpanID() { #ifdef DISABLE_PROTOBUF diff --git a/pdns/dnsdistdist/dnsdist-opentelemetry.hh b/pdns/dnsdistdist/dnsdist-opentelemetry.hh index aa3de14ed8..f3d5d27292 100644 --- a/pdns/dnsdistdist/dnsdist-opentelemetry.hh +++ b/pdns/dnsdistdist/dnsdist-opentelemetry.hh @@ -145,6 +145,13 @@ public: */ void closeSpan(const SpanID& spanID); + /** + * @brief Get the top-most SpanID + * + * @return The SpanID of the root Span + */ + [[nodiscard]] SpanID getRootSpanID(); + /** * @brief Get the last SpanID generated * diff --git a/pdns/dnsdistdist/dnsdist.cc b/pdns/dnsdistdist/dnsdist.cc index c424d7e0a8..4cfc5ebec3 100644 --- a/pdns/dnsdistdist/dnsdist.cc +++ b/pdns/dnsdistdist/dnsdist.cc @@ -591,7 +591,7 @@ bool processResponse(PacketBuffer& response, DNSResponse& dnsResponse, bool mute { pdns::trace::dnsdist::Tracer::Closer closer; if (auto tracer = dnsResponse.ids.getTracer(); tracer != nullptr && dnsResponse.ids.tracingEnabled) { - closer = tracer->openSpan("processResponse"); + closer = tracer->openSpan("processResponse", tracer->getRootSpanID()); } const auto& chains = dnsdist::configuration::getCurrentRuntimeConfiguration().d_ruleChains;