]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
feat(dnsdist): Use the stack-based approach for Tracing
authorPieter Lexis <pieter.lexis@powerdns.com>
Thu, 27 Nov 2025 14:57:32 +0000 (15:57 +0100)
committerPieter Lexis <pieter.lexis@powerdns.com>
Fri, 12 Dec 2025 15:30:51 +0000 (16:30 +0100)
pdns/dnsdistdist/dnsdist-idstate.cc
pdns/dnsdistdist/dnsdist-idstate.hh
pdns/dnsdistdist/dnsdist.cc

index 19a92f66514489ff1ac2ab7f03ef0f55271ac774..5c1e41ab353589ee47d85dd41eabf72fef360e52 100644 (file)
@@ -129,13 +129,13 @@ std::optional<pdns::trace::dnsdist::Tracer::Closer> InternalQueryState::getClose
   std::optional<pdns::trace::dnsdist::Tracer::Closer> ret(std::nullopt);
 #ifndef DISABLE_PROTOBUF
   if (auto tracer = getTracer(); tracer != nullptr) {
-    return getCloser(std::string(name), d_OTTracer->getLastSpanID());
+    return getCloser(std::string(name), tracer->getLastSpanID());
   }
 #endif
   return ret;
 }
 
-std::optional<pdns::trace::dnsdist::Tracer::Closer> InternalQueryState::getRulesCloser([[maybe_unused]] const std::string_view& ruleName, [[maybe_unused]] const std::string_view& parentSpanName, [[maybe_unused]] const std::string& ruleType)
+std::optional<pdns::trace::dnsdist::Tracer::Closer> InternalQueryState::getRulesCloser([[maybe_unused]] const std::string_view& ruleName, [[maybe_unused]] const std::string& ruleType)
 {
   std::optional<pdns::trace::dnsdist::Tracer::Closer> ret(std::nullopt);
 #ifndef DISABLE_PROTOBUF
@@ -144,9 +144,9 @@ std::optional<pdns::trace::dnsdist::Tracer::Closer> InternalQueryState::getRules
   // tracingEnabled tells us whether or not tracing is enabled for this query
   // Should tracing be disabled, *but* we have not processed query rules, we will still return a closer if tracing is globally enabled
   if (auto tracer = getTracer(); tracer != nullptr && (tracingEnabled || !rulesAppliedToQuery)) {
-    auto parentSpanID = d_OTTracer->getLastSpanIDForName(std::string(parentSpanName));
+    auto parentSpanID = tracer->getLastSpanID();
     auto name = ruleType + prefix + std::string(ruleName);
-    ret = std::optional<pdns::trace::dnsdist::Tracer::Closer>(d_OTTracer->openSpan(name, parentSpanID));
+    ret = std::optional<pdns::trace::dnsdist::Tracer::Closer>(tracer->openSpan(name, parentSpanID));
   }
 #endif
   return ret;
index 93de5908249a50af19385783e04379cb1c6aae6f..e3c4afbc7394b394b3c777967bfddae489dc94f9 100644 (file)
@@ -151,7 +151,7 @@ struct InternalQueryState
   std::optional<pdns::trace::dnsdist::Tracer::Closer> getCloser([[maybe_unused]] const std::string_view& name, [[maybe_unused]] const SpanID& parentSpanID);
   std::optional<pdns::trace::dnsdist::Tracer::Closer> getCloser([[maybe_unused]] const std::string_view& name, [[maybe_unused]] const std::string_view& parentSpanName);
   std::optional<pdns::trace::dnsdist::Tracer::Closer> getCloser([[maybe_unused]] const std::string_view& name);
-  std::optional<pdns::trace::dnsdist::Tracer::Closer> getRulesCloser([[maybe_unused]] const std::string_view& ruleName, [[maybe_unused]] const std::string_view& parentSpanName, [[maybe_unused]] const std::string& ruleType);
+  std::optional<pdns::trace::dnsdist::Tracer::Closer> getRulesCloser([[maybe_unused]] const std::string_view& ruleName, [[maybe_unused]] const std::string& ruleType);
 
   InternalQueryState()
   {
index d66c4a483cf853cc288ef01f69323c708b621755..ecc8d97d0ecb40312405d0364a4d06a466dea8f6 100644 (file)
@@ -466,7 +466,7 @@ bool applyRulesToResponse(const std::vector<dnsdist::rules::ResponseRuleAction>&
   static const std::string ruleType = "Response";
 
   for (const auto& rrule : respRuleActions) {
-    auto ruleCloser = dnsResponse.ids.getRulesCloser(rrule.d_name, __func__, ruleType); // NOLINT(cppcoreguidelines-pro-bounds-array-to-pointer-decay)
+    auto ruleCloser = dnsResponse.ids.getRulesCloser(rrule.d_name, ruleType);
     if (rrule.d_rule->matches(&dnsResponse)) {
       ++rrule.d_rule->d_matches;
       action = (*rrule.d_action)(&dnsResponse, &ruleresult);
@@ -520,7 +520,7 @@ bool applyRulesToResponse(const std::vector<dnsdist::rules::ResponseRuleAction>&
 
 bool processResponseAfterRules(PacketBuffer& response, DNSResponse& dnsResponse, [[maybe_unused]] bool muted)
 {
-  auto closer = dnsResponse.ids.getCloser(__func__, "processResponse"); // NOLINT(cppcoreguidelines-pro-bounds-array-to-pointer-decay)
+  auto closer = dnsResponse.ids.getCloser(__func__); // NOLINT(cppcoreguidelines-pro-bounds-array-to-pointer-decay)
   bool zeroScope = false;
   if (!fixUpResponse(response, dnsResponse.ids.qname, dnsResponse.ids.origFlags, dnsResponse.ids.ednsAdded, dnsResponse.ids.ecsAdded, dnsResponse.ids.useZeroScope ? &zeroScope : nullptr)) {
     if (closer) {
@@ -552,7 +552,7 @@ bool processResponseAfterRules(PacketBuffer& response, DNSResponse& dnsResponse,
       cacheKey = dnsResponse.ids.cacheKeyNoECS;
     }
     {
-      auto cacheInsertCloser = dnsResponse.ids.getCloser("packetCacheInsert", __func__); // NOLINT(cppcoreguidelines-pro-bounds-array-to-pointer-decay)
+      auto cacheInsertCloser = dnsResponse.ids.getCloser("packetCacheInsert"); // NOLINT(cppcoreguidelines-pro-bounds-array-to-pointer-decay)
       dnsResponse.ids.packetCache->insert(cacheKey, zeroScope ? std::nullopt : dnsResponse.ids.subnet, dnsResponse.ids.cacheFlags, dnsResponse.ids.dnssecOK ? *dnsResponse.ids.dnssecOK : false, dnsResponse.ids.qname, dnsResponse.ids.qtype, dnsResponse.ids.qclass, response, dnsResponse.ids.forwardedOverUDP, dnsResponse.getHeader()->rcode, dnsResponse.ids.tempFailureTTL);
     }
     const auto& chains = dnsdist::configuration::getCurrentRuntimeConfiguration().d_ruleChains;
@@ -584,7 +584,7 @@ bool processResponseAfterRules(PacketBuffer& response, DNSResponse& dnsResponse,
 bool processResponse(PacketBuffer& response, DNSResponse& dnsResponse, bool muted)
 {
   // This is a new root span
-  auto closer = dnsResponse.ids.getCloser(__func__, SpanID{}); // NOLINT(cppcoreguidelines-pro-bounds-array-to-pointer-decay)
+  auto closer = dnsResponse.ids.getCloser(__func__); // NOLINT(cppcoreguidelines-pro-bounds-array-to-pointer-decay)
 
   const auto& chains = dnsdist::configuration::getCurrentRuntimeConfiguration().d_ruleChains;
   const auto& respRuleActions = dnsdist::rules::getResponseRuleChain(chains, dnsdist::rules::ResponseRuleChain::ResponseRules);
@@ -1026,7 +1026,7 @@ static bool applyRulesChainToQuery(const std::vector<dnsdist::rules::RuleAction>
   static const std::string ruleType; // Empty string
 
   for (const auto& rule : rules) {
-    auto ruleCloser = dnsQuestion.ids.getRulesCloser(rule.d_name, __func__, ruleType); // NOLINT(cppcoreguidelines-pro-bounds-array-to-pointer-decay)
+    auto ruleCloser = dnsQuestion.ids.getRulesCloser(rule.d_name, ruleType);
 
     if (!rule.d_rule->matches(&dnsQuestion)) {
       continue;
@@ -1454,7 +1454,7 @@ static ProcessQueryResult handleQueryTurnedIntoSelfAnsweredResponse(DNSQuestion&
 static ServerPolicy::SelectedBackend selectBackendForOutgoingQuery(DNSQuestion& dnsQuestion, const ServerPool& serverPool)
 {
   // Not exactly processQuery, but it works for now
-  auto closer = dnsQuestion.ids.getCloser(__func__, "processQuery"); // NOLINT(cppcoreguidelines-pro-bounds-array-to-pointer-decay)
+  auto closer = dnsQuestion.ids.getCloser(__func__); // NOLINT(cppcoreguidelines-pro-bounds-array-to-pointer-decay)
 
   const auto& policy = serverPool.policy != nullptr ? *serverPool.policy : *dnsdist::configuration::getCurrentRuntimeConfiguration().d_lbPolicy;
   const auto& servers = serverPool.getServers();
@@ -1812,7 +1812,7 @@ ProcessQueryResult processQuery(DNSQuestion& dnsQuestion, std::shared_ptr<Downst
 
 bool assignOutgoingUDPQueryToBackend(std::shared_ptr<DownstreamState>& downstream, uint16_t queryID, DNSQuestion& dnsQuestion, PacketBuffer& query, bool actuallySend)
 {
-  auto closer = dnsQuestion.ids.getCloser(__func__, "processUDPQuery"); // NOLINT(cppcoreguidelines-pro-bounds-array-to-pointer-decay)
+  auto closer = dnsQuestion.ids.getCloser(__func__); // NOLINT(cppcoreguidelines-pro-bounds-array-to-pointer-decay)
 
   bool doh = dnsQuestion.ids.du != nullptr;