]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Handle traceid_only and other conditions correctly
authorOtto Moerbeek <otto.moerbeek@open-xchange.com>
Tue, 21 Oct 2025 11:33:30 +0000 (13:33 +0200)
committerOtto Moerbeek <otto.moerbeek@open-xchange.com>
Mon, 10 Nov 2025 14:20:43 +0000 (15:20 +0100)
Signed-off-by: Otto Moerbeek <otto.moerbeek@open-xchange.com>
pdns/recursordist/pdns_recursor.cc
pdns/recursordist/rec-eventtrace.hh
pdns/recursordist/rec-main.cc
pdns/recursordist/rec-main.hh
pdns/recursordist/rec-tcp.cc

index 45b58877fb29f0811f7a628f55b00996c5ed3a0f..77f595bea4d7b59f68387e4613bcb2f13399f76c 100644 (file)
@@ -1861,7 +1861,8 @@ void startDoResolve(void* arg) // NOLINT(readability-function-cognitive-complexi
       if (resolver.d_eventTrace.enabled() && SyncRes::eventTraceEnabled(SyncRes::event_trace_to_pb)) {
         pbMessage.addEvents(resolver.d_eventTrace);
       }
-      if (resolver.d_eventTrace.enabled() && SyncRes::eventTraceEnabled(SyncRes::event_trace_to_ot)) {
+
+      if (resolver.d_eventTrace.enabled() && resolver.d_eventTrace.getThisOTTraceEnabled() && SyncRes::eventTraceEnabled(SyncRes::event_trace_to_ot)) {
         auto otTrace = pdns::trace::TracesData::boilerPlate("rec", resolver.d_eventTrace.convertToOT(resolver.d_otTrace), {
                                                                                                                             {"query.qname", {comboWriter->d_mdp.d_qname.toLogString()}},
                                                                                                                             {"query.qtype", {QType(comboWriter->d_mdp.d_qtype).toString()}},
@@ -2158,7 +2159,7 @@ bool matchOTConditions(const std::unique_ptr<OpenTelemetryTraceConditions>& cond
   return true;
 }
 
-bool matchOTConditions(const std::unique_ptr<OpenTelemetryTraceConditions>& conditions, const ComboAddress& source, const DNSName& qname, QType qtype, uint16_t qid, bool edns_option_present)
+bool matchOTConditions(RecEventTrace& eventTrace, const std::unique_ptr<OpenTelemetryTraceConditions>& conditions, const ComboAddress& source, const DNSName& qname, QType qtype, uint16_t qid, bool edns_option_present)
 {
   if (conditions == nullptr || conditions->size() == 0) {
     return false;
@@ -2181,6 +2182,7 @@ bool matchOTConditions(const std::unique_ptr<OpenTelemetryTraceConditions>& cond
       return false;
     }
   }
+  eventTrace.setThisOTTraceEnabled();
   return true;
 }
 
@@ -2290,7 +2292,7 @@ static string* doProcessUDPQuestion(const std::string& question, const ComboAddr
 
         if (SyncRes::eventTraceEnabled(SyncRes::event_trace_to_ot)) {
           bool ednsFound = pdns::trace::extractOTraceIDs(ednsOptions, otTrace);
-          if (SyncRes::eventTraceEnabledOnly(SyncRes::event_trace_to_ot) && !matchOTConditions(t_OTConditions, mappedSource, qname, qtype, ntohs(headerdata->id), ednsFound)) {
+          if (!matchOTConditions(eventTrace, t_OTConditions, mappedSource, qname, qtype, ntohs(headerdata->id), ednsFound) && SyncRes::eventTraceEnabledOnly(SyncRes::event_trace_to_ot)) {
             eventTrace.setEnabled(false);
           }
         }
index 31bb509f0c0bb68dad007b5a86970646fdad1105..34fe36067dccc683604b0257ada8ff1bf5f0643c 100644 (file)
@@ -71,7 +71,8 @@ public:
   RecEventTrace(const RecEventTrace& old) :
     d_events(old.d_events),
     d_base(old.d_base),
-    d_status(old.d_status)
+    d_status(old.d_status),
+    d_OTTrace(old.d_OTTrace)
   {
     // An RecEventTrace object can be copied, but the original will be marked invalid.
     // This is do detect (very likely) unintended modifications to the original after
@@ -82,7 +83,8 @@ public:
   RecEventTrace(RecEventTrace&& old) noexcept :
     d_events(std::move(old.d_events)),
     d_base(old.d_base),
-    d_status(old.d_status)
+    d_status(old.d_status),
+    d_OTTrace(old.d_OTTrace)
   {
     // An RecEventTrace object can be moved, but the original will be marked invalid.
     // This is do detect (very likely) unintended modifications to the original after
@@ -96,6 +98,7 @@ public:
     d_events = std::move(old.d_events);
     d_base = old.d_base;
     d_status = old.d_status;
+    d_OTTrace = old.d_OTTrace;
     old.d_status = Invalid;
     return *this;
   }
@@ -260,6 +263,7 @@ public:
     struct timespec theTime{};
     clock_gettime(CLOCK_MONOTONIC, &theTime);
     d_base = theTime.tv_nsec + theTime.tv_sec * 1000000000;
+    d_OTTrace = false;
     d_status = Disabled;
   }
 
@@ -298,6 +302,16 @@ public:
     return old;
   }
 
+  bool getThisOTTraceEnabled() const
+  {
+    return d_OTTrace;
+  }
+
+  void setThisOTTraceEnabled()
+  {
+    d_OTTrace = true;
+  }
+
   // The EventScope class is used to close (add an end event) automatically upon the scope object
   // going out of scope. It is also possible to manually close it, specifying a value to be registered
   // at the close event. In that case the dt call will become a no-op.
@@ -355,4 +369,5 @@ private:
     Enabled
   };
   mutable Status d_status{Disabled};
+  bool d_OTTrace{false};
 };
index d203128b74b8fe61ab4003dbc3411007f8b90455..03f3cde46e577baef35e668d48ebde02724d1bd6 100644 (file)
@@ -639,7 +639,8 @@ void protobufLogResponse(const DNSName& qname, QType qtype,
   if (eventTrace.enabled() && SyncRes::eventTraceEnabled(SyncRes::event_trace_to_pb)) {
     pbMessage.addEvents(eventTrace);
   }
-  if (eventTrace.enabled() && SyncRes::eventTraceEnabled(SyncRes::event_trace_to_ot)) {
+
+  if (eventTrace.enabled() && eventTrace.getThisOTTraceEnabled() && SyncRes::eventTraceEnabled(SyncRes::event_trace_to_ot)) {
     auto trace = pdns::trace::TracesData::boilerPlate("rec", eventTrace.convertToOT(otTrace),
                                                       {{"query.qname", {qname.toLogString()}},
                                                        {"query.qtype", {qtype.toString()}}},
index 94b7fedb60b8ddcbeebf2759455b44d03d3edc50..d5361b823481c5d945272e82b871cc0e3a986648 100644 (file)
@@ -647,7 +647,7 @@ void requestWipeCaches(const DNSName& canon);
 void startDoResolve(void*);
 bool expectProxyProtocol(const ComboAddress& from, const ComboAddress& listenAddress);
 bool matchOTConditions(const std::unique_ptr<OpenTelemetryTraceConditions>& conditions, const ComboAddress& source);
-bool matchOTConditions(const std::unique_ptr<OpenTelemetryTraceConditions>& conditions, const ComboAddress& source, const DNSName& qname, QType qtype, uint16_t qid, bool edns_option_present);
+bool matchOTConditions(RecEventTrace& eventTrace, const std::unique_ptr<OpenTelemetryTraceConditions>& conditions, const ComboAddress& source, const DNSName& qname, QType qtype, uint16_t qid, bool edns_option_present);
 void finishTCPReply(std::unique_ptr<DNSComboWriter>&, bool hadError, bool updateInFlight);
 void checkFastOpenSysctl(bool active, Logr::log_t);
 void checkTFOconnect(Logr::log_t);
index d6679149b240d65f0008a4d4d0b61bc0262d357c..cb1be7c0fd230916439250ef9406e1113e18a34d 100644 (file)
@@ -302,7 +302,7 @@ static void doProcessTCPQuestion(std::unique_ptr<DNSComboWriter>& comboWriter, s
   boost::optional<uint32_t> ednsVersion;
 
   comboWriter->d_eventTrace.setEnabled(SyncRes::s_event_trace_enabled != 0);
-  if (SyncRes::eventTraceEnabledOnly(SyncRes::event_trace_to_ot) && !matchOTConditions(t_OTConditions, comboWriter->d_mappedSource)) {
+  if (!matchOTConditions(t_OTConditions, comboWriter->d_mappedSource) && SyncRes::eventTraceEnabledOnly(SyncRes::event_trace_to_ot)) {
     comboWriter->d_eventTrace.setEnabled(false);
   }
 
@@ -341,7 +341,7 @@ static void doProcessTCPQuestion(std::unique_ptr<DNSComboWriter>& comboWriter, s
 
       if (SyncRes::eventTraceEnabled(SyncRes::event_trace_to_ot)) {
         bool ednsFound = pdns::trace::extractOTraceIDs(ednsOptions, comboWriter->d_otTrace);
-        if (SyncRes::eventTraceEnabledOnly(SyncRes::event_trace_to_ot) && !matchOTConditions(t_OTConditions, comboWriter->d_mappedSource, qname, qtype, ntohs(comboWriter->d_mdp.d_header.id), ednsFound)) {
+        if (SyncRes::eventTraceEnabledOnly(SyncRes::event_trace_to_ot) && !matchOTConditions(comboWriter->d_eventTrace, t_OTConditions, comboWriter->d_mappedSource, qname, qtype, ntohs(comboWriter->d_mdp.d_header.id), ednsFound)) {
           comboWriter->d_eventTrace.setEnabled(false);
         }
       }