]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Generate TraceID and SpanID later (and only if needed)
authorOtto Moerbeek <otto.moerbeek@open-xchange.com>
Wed, 22 Oct 2025 13:33:14 +0000 (15:33 +0200)
committerOtto Moerbeek <otto.moerbeek@open-xchange.com>
Mon, 10 Nov 2025 14:24:44 +0000 (15:24 +0100)
Signed-off-by: Otto Moerbeek <otto.moerbeek@open-xchange.com>
pdns/protozero-trace.cc
pdns/protozero-trace.hh
pdns/recursordist/pdns_recursor.cc
pdns/recursordist/rec-main.cc
pdns/recursordist/rec-rust-lib/cxxsettings.hh
pdns/recursordist/rec-rust-lib/cxxsupport.cc
pdns/recursordist/rec-tcp.cc

index 66a524ff8580b3c721500b656a498d51e3fb39c1..4a5ed0e7a200f37612a04836e30d388de476af5d 100644 (file)
@@ -556,9 +556,8 @@ KeyValue KeyValue::decode(protozero::pbf_reader& reader)
 bool extractOTraceIDs(const EDNSOptionViewMap& map, pdns::trace::InitialSpanInfo& span)
 {
   // traceid gets set from edns options (if available and well-formed)
-  // parent_span_id gets set from edns options (if available and well-formed, otherwise it remains cleared (no parent))
+  // parent_span_id gets set from edns options (if available and well-formed)
   auto traceidset = extractOTraceIDs(map, EDNSOptionCode::OTTRACEIDS, span.trace_id, span.parent_span_id);
-
   return traceidset;
 }
 
index 3735d0182620ca1e51fb0afdf44f0201d0c685d5..4477a9f9fe923b2bf4d021da1982b181b5d69f56 100644 (file)
@@ -392,6 +392,16 @@ struct InitialSpanInfo
     parent_span_id.clear();
     start_time_unix_nano = 0;
   }
+
+  void setIDsIfNotSet()
+  {
+    if (trace_id == s_emptyTraceID) {
+      trace_id.makeRandom();
+    }
+    if (span_id == s_emptySpanID) {
+      span_id.makeRandom();
+    }
+  }
 };
 
 struct Span
index 59219ff70cc6a1cfe78fe2a1a92868ec38bf451b..d8a4587329faec8054d227c1caee586a1230ac29 100644 (file)
@@ -1863,6 +1863,7 @@ void startDoResolve(void* arg) // NOLINT(readability-function-cognitive-complexi
       }
 
       if (resolver.d_eventTrace.enabled() && resolver.d_eventTrace.getThisOTTraceEnabled() && SyncRes::eventTraceEnabled(SyncRes::event_trace_to_ot)) {
+        resolver.d_otTrace.setIDsIfNotSet();
         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()}},
@@ -2657,8 +2658,8 @@ static void handleNewUDPQuestion(int fileDesc, FDMultiplexer::funcparam_t& /* va
             destination = destaddr;
           }
 
-          if (SyncRes::eventTraceEnabledOnly(SyncRes::event_trace_to_ot) && !matchOTConditions(t_OTConditions, mappedSource)) {
-              eventTrace.setEnabled(false);
+          if (eventTrace.enabled() && !matchOTConditions(t_OTConditions, mappedSource) && SyncRes::eventTraceEnabledOnly(SyncRes::event_trace_to_ot)) {
+            eventTrace.setEnabled(false);
           }
           eventTrace.add(RecEventTrace::ReqRecv, 0, false, match);
           if (RecThreadInfo::weDistributeQueries()) {
index 03f3cde46e577baef35e668d48ebde02724d1bd6..27e56680f0f537879614414ad9ddb486fb717237 100644 (file)
@@ -641,6 +641,7 @@ void protobufLogResponse(const DNSName& qname, QType qtype,
   }
 
   if (eventTrace.enabled() && eventTrace.getThisOTTraceEnabled() && SyncRes::eventTraceEnabled(SyncRes::event_trace_to_ot)) {
+    otTrace.setIDsIfNotSet();
     auto trace = pdns::trace::TracesData::boilerPlate("rec", eventTrace.convertToOT(otTrace),
                                                       {{"query.qname", {qname.toLogString()}},
                                                        {"query.qtype", {qtype.toString()}}},
index b6253e89df2ce99ec767fabd22c73147d27bbe3d..3e829789d9ac49ffe9c152a76097ec35e11f340c 100644 (file)
@@ -52,8 +52,8 @@ void readYamlAllowFromFile(const std::string& filename, ::rust::Vec<::rust::Stri
 void readYamlAllowNotifyForFile(const std::string& filename, ::rust::Vec<::rust::String>& vec, Logr::log_t log);
 void setArgsForZoneRelatedSettings(pdns::rust::settings::rec::Recursorsettings& settings);
 void setArgsForACLRelatedSettings(pdns::rust::settings::rec::Recursorsettings& settings);
-  void fromLuaConfigToBridgeStruct(LuaConfigItems& luaConfig, const ProxyMapping& proxyMapping, pdns::rust::settings::rec::Recursorsettings& settings);
-  void fromBridgeStructToLuaConfig(const pdns::rust::settings::rec::Recursorsettings& settings, LuaConfigItems& luaConfig, ProxyMapping& proxyMapping, OpenTelemetryTraceConditions& conditions);
+void fromLuaConfigToBridgeStruct(LuaConfigItems& luaConfig, const ProxyMapping& proxyMapping, pdns::rust::settings::rec::Recursorsettings& settings);
+void fromBridgeStructToLuaConfig(const pdns::rust::settings::rec::Recursorsettings& settings, LuaConfigItems& luaConfig, ProxyMapping& proxyMapping, OpenTelemetryTraceConditions& conditions);
 bool luaItemSet(const pdns::rust::settings::rec::Recursorsettings& settings);
 YamlSettingsStatus tryReadYAML(const string& yamlconfigname, bool setGlobals, bool& yamlSettings, bool& luaSettingsInYAML, rust::settings::rec::Recursorsettings& settings, Logr::log_t startupLog, Logr::Priority level = Logr::Debug);
 }
index ba9b0be8734d80526e96831c4550528f6f9ad6c3..f3d3371885f10961d70d6819ea9ac9d9ee95695c 100644 (file)
@@ -1333,7 +1333,6 @@ void fromRustToLuaConfig(const rust::Vec<pdns::rust::settings::rec::ForwardingCa
   }
 }
 
-
 void fromRustToOTTraceConditions(const rust::Vec<pdns::rust::settings::rec::OpenTelemetryTraceCondition>& settings, OpenTelemetryTraceConditions& conditions)
 {
   for (const auto& setting : settings) {
index cb1be7c0fd230916439250ef9406e1113e18a34d..0e15000a972d3ff7d634e57a60d37ac4ff7ccfaa 100644 (file)
@@ -284,7 +284,7 @@ static void doProtobufLogQuery(bool logQuery, LocalStateHolder<LuaConfigItems>&
   }
 }
 
-static void doProcessTCPQuestion(std::unique_ptr<DNSComboWriter>& comboWriter, shared_ptr<TCPConnection>& conn, RunningTCPQuestionGuard& tcpGuard, int fileDesc)
+static void doProcessTCPQuestion(std::unique_ptr<DNSComboWriter>& comboWriter, shared_ptr<TCPConnection>& conn, RunningTCPQuestionGuard& tcpGuard, int fileDesc) // NOLINT(readability-function-cognitive-complexity) will fix one day
 {
   RecThreadInfo::self().incNumberOfDistributedQueries();
   struct timeval start{};
@@ -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 (!matchOTConditions(t_OTConditions, comboWriter->d_mappedSource) && SyncRes::eventTraceEnabledOnly(SyncRes::event_trace_to_ot)) {
+  if (comboWriter->d_eventTrace.enabled() && !matchOTConditions(t_OTConditions, comboWriter->d_mappedSource) && SyncRes::eventTraceEnabledOnly(SyncRes::event_trace_to_ot)) {
     comboWriter->d_eventTrace.setEnabled(false);
   }