]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Use a more leightweight struct to pass the initial Span data, we're only using a...
authorOtto Moerbeek <otto.moerbeek@open-xchange.com>
Wed, 25 Jun 2025 09:49:20 +0000 (11:49 +0200)
committerOtto Moerbeek <otto.moerbeek@open-xchange.com>
Tue, 1 Jul 2025 07:29:17 +0000 (09:29 +0200)
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-eventtrace.cc
pdns/recursordist/rec-eventtrace.hh
pdns/recursordist/rec-main.cc
pdns/recursordist/rec-main.hh
pdns/recursordist/rec-tcp.cc
pdns/recursordist/syncres.hh

index 059e2a679647f25f4f4e00b36a47f85599d062f9..3599b688d8aa159bfa147c706acb47e1318f4dc9 100644 (file)
@@ -506,7 +506,7 @@ KeyValue KeyValue::decode(protozero::pbf_reader& reader)
   return value;
 }
 
-void extractOTraceIDs(const EDNSOptionViewMap& map, pdns::trace::Span& span)
+void extractOTraceIDs(const EDNSOptionViewMap& map, pdns::trace::InitialSpanInfo& span)
 {
   // traceid gets set from edns options (if available and well-formed), otherwise random
   // parent_span_id gets set from edns options (if available and well-formed, otherwise it remains cleared (no parent))
index c07acc6ac740bdc673cd1dff15e375c5591790d8..1c1250adb69ccec424e865f3ad65bdbb3c956ffb 100644 (file)
@@ -339,6 +339,24 @@ inline uint64_t timestamp()
   return (1000000000ULL * now.tv_sec) + now.tv_nsec;
 }
 
+// This struct is used to store the info of the initial span. As it is passed around resolving
+// queries, it needs to be as small as possible, hence no full Span.
+struct InitialSpanInfo
+{
+  TraceID trace_id{};
+  SpanID span_id{};
+  SpanID parent_span_id{};
+  uint64_t start_time_unix_nano{0};
+
+  void clear()
+  {
+    pdns::trace::clear(trace_id);
+    pdns::trace::clear(span_id);
+    pdns::trace::clear(parent_span_id);
+    start_time_unix_nano = 0;
+  }
+};
+
 struct Span
 {
   // A unique identifier for a trace. All spans from the same trace share
@@ -694,6 +712,6 @@ inline KeyValueList KeyValueList::decode(protozero::pbf_reader& reader)
   return pdns::trace::decode<KeyValueList, KeyValue>(reader);
 }
 
-void extractOTraceIDs(const EDNSOptionViewMap& map, pdns::trace::Span& span);
+void extractOTraceIDs(const EDNSOptionViewMap& map, pdns::trace::InitialSpanInfo& span);
 
 } // namespace pdns::trace
index 8df1a3bf47af03331838bb6c3348f8c75975aee2..e18c24e891d14c549ee4be61f3dba7a9bca158a4 100644 (file)
@@ -1875,7 +1875,6 @@ void startDoResolve(void* arg) // NOLINT(readability-function-cognitive-complexi
         pbMessage.addEvents(resolver.d_eventTrace);
       }
       if (resolver.d_eventTrace.enabled() && SyncRes::eventTraceEnabled(SyncRes::event_trace_to_ot)) {
-        resolver.d_otTrace.close();
         auto otTrace = pdns::trace::TracesData::boilerPlate("rec", comboWriter->d_mdp.d_qname.toLogString() + '/' + QType(comboWriter->d_mdp.d_qtype).toString(), resolver.d_eventTrace.convertToOT(resolver.d_otTrace));
         string otData = otTrace.encode();
         pbMessage.setOpenTelemetryData(otData);
@@ -2177,7 +2176,7 @@ bool expectProxyProtocol(const ComboAddress& from, const ComboAddress& listenAdd
 // source: the address we assume the query is coming from, might be set by proxy protocol
 // destination: the address we assume the query was sent to, might be set by proxy protocol
 // mappedSource: the address we assume the query is coming from. Differs from source if table based mapping has been applied
-static string* doProcessUDPQuestion(const std::string& question, const ComboAddress& fromaddr, const ComboAddress& destaddr, ComboAddress source, ComboAddress destination, const ComboAddress& mappedSource, struct timeval tval, int fileDesc, std::vector<ProxyProtocolValue>& proxyProtocolValues, RecEventTrace& eventTrace, pdns::trace::Span& otTrace) // NOLINT(readability-function-cognitive-complexity): https://github.com/PowerDNS/pdns/issues/12791
+static string* doProcessUDPQuestion(const std::string& question, const ComboAddress& fromaddr, const ComboAddress& destaddr, ComboAddress source, ComboAddress destination, const ComboAddress& mappedSource, struct timeval tval, int fileDesc, std::vector<ProxyProtocolValue>& proxyProtocolValues, RecEventTrace& eventTrace, pdns::trace::InitialSpanInfo& otTrace) // NOLINT(readability-function-cognitive-complexity): https://github.com/PowerDNS/pdns/issues/12791
 {
   RecThreadInfo::self().incNumberOfDistributedQueries();
   gettimeofday(&g_now, nullptr);
@@ -2475,7 +2474,7 @@ static void handleNewUDPQuestion(int fileDesc, FDMultiplexer::funcparam_t& /* va
   bool firstQuery = true;
   std::vector<ProxyProtocolValue> proxyProtocolValues;
   RecEventTrace eventTrace;
-  pdns::trace::Span otTrace;
+  pdns::trace::InitialSpanInfo otTrace;
 
   for (size_t queriesCounter = 0; queriesCounter < g_maxUDPQueriesPerRound; queriesCounter++) {
     bool proxyProto = false;
@@ -2495,7 +2494,6 @@ static void handleNewUDPQuestion(int fileDesc, FDMultiplexer::funcparam_t& /* va
       if (SyncRes::eventTraceEnabled(SyncRes::event_trace_to_ot)) {
         otTrace.clear();
         otTrace.start_time_unix_nano = traceTS;
-        otTrace.name = "RecRequest";
       }
       firstQuery = false;
 
index 360ad29e3dd986ab31ba671c60498793fa47fa22..aeb2d480784d95a63adbb8d65fb6d570fd13f58d 100644 (file)
@@ -66,7 +66,7 @@ static void addValue(const RecEventTrace::Entry& event, Span& work, bool start)
 
 // The event trace uses start-stop records which need to be mapped to OpenTelemetry Spans, which is a
 // list of spans. Spans can refer to other spans as their parent.
-std::vector<pdns::trace::Span> RecEventTrace::convertToOT(const Span& span) const
+std::vector<pdns::trace::Span> RecEventTrace::convertToOT(const InitialSpanInfo& span) const
 {
   timespec realtime{};
   clock_gettime(CLOCK_REALTIME, &realtime);
@@ -79,7 +79,7 @@ std::vector<pdns::trace::Span> RecEventTrace::convertToOT(const Span& span) cons
   ret.reserve((d_events.size() / 2) + 1);
 
   // The parent of all Spans
-  ret.emplace_back(span);
+  ret.emplace_back(Span{.trace_id = span.trace_id, .span_id = span.span_id, .parent_span_id = span.parent_span_id, .end_time_unix_nano = timestamp()});
 
   std::vector<SpanID> spanIDs; // mapping of span index in ret vector to SpanID
   std::map<size_t, size_t> ids; // mapping from event record index to index in ret vector (Spans)
index 1623b0c2ab990249cb23fa6f0709a38f81ec14b7..a661f5afc3c86850fe0371fec1c2de59461915c4 100644 (file)
@@ -266,7 +266,7 @@ public:
     return d_events;
   }
 
-  std::vector<pdns::trace::Span> convertToOT(const pdns::trace::Span& span) const;
+  std::vector<pdns::trace::Span> convertToOT(const pdns::trace::InitialSpanInfo& span) const;
 
   size_t setParent(size_t parent)
   {
index c4f73cb95163c6be3fb9104c276c170e70947186..009940d50b5dfa119f3da4966d627f688ac6d173 100644 (file)
@@ -603,7 +603,7 @@ void protobufLogResponse(const DNSName& qname, QType qtype,
                          const boost::uuids::uuid& uniqueId, const string& requestorId, const string& deviceId,
                          const string& deviceName, const std::map<std::string, RecursorLua4::MetaValue>& meta,
                          const RecEventTrace& eventTrace,
-                         pdns::trace::Span& otTrace,
+                         pdns::trace::InitialSpanInfo& otTrace,
                          const std::unordered_set<std::string>& policyTags)
 {
   pdns::ProtoZero::RecMessage pbMessage(pbData ? pbData->d_message : "", pbData ? pbData->d_response : "", 64, 10); // The extra bytes we are going to add
@@ -665,7 +665,6 @@ void protobufLogResponse(const DNSName& qname, QType qtype,
     pbMessage.addEvents(eventTrace);
   }
   if (eventTrace.enabled() && (SyncRes::s_event_trace_enabled & SyncRes::event_trace_to_ot) != 0) {
-    otTrace.close();
     auto trace = pdns::trace::TracesData::boilerPlate("rec", qname.toLogString() + '/' + qtype.toString(), eventTrace.convertToOT(otTrace));
     pbMessage.setOpenTelemetryData(trace.encode());
   }
index 4a639bf911292f11ccf9a4c9ba2b574e971a771c..49576ee7bb016a2d08f5784f3242b8e2ad2aae81 100644 (file)
@@ -115,7 +115,7 @@ struct DNSComboWriter
   ComboAddress d_destination; // the address we assume the query is sent to, might be set by proxy protocol
   ComboAddress d_mappedSource; // the source address after being mapped by table based proxy mapping
   RecEventTrace d_eventTrace;
-  pdns::trace::Span d_otTrace;
+  pdns::trace::InitialSpanInfo d_otTrace;
   boost::uuids::uuid d_uuid;
   string d_requestorId;
   string d_deviceId;
@@ -638,7 +638,7 @@ void protobufLogResponse(const DNSName& qname, QType qtype, const struct dnshead
                          const boost::uuids::uuid& uniqueId, const string& requestorId, const string& deviceId,
                          const string& deviceName, const std::map<std::string, RecursorLua4::MetaValue>& meta,
                          const RecEventTrace& eventTrace,
-                         pdns::trace::Span& otTrace,
+                         pdns::trace::InitialSpanInfo& otTrace,
                          const std::unordered_set<std::string>& policyTags);
 void requestWipeCaches(const DNSName& canon);
 void startDoResolve(void*);
index 2b164c21e18cf21f14ee6a18f6f584fd2d3bd6d2..8a56f40b02df732755f122c0b7973fea179b803e 100644 (file)
@@ -315,7 +315,7 @@ static void doProcessTCPQuestion(std::unique_ptr<DNSComboWriter>& comboWriter, s
   if (SyncRes::eventTraceEnabled(SyncRes::event_trace_to_ot)) {
     comboWriter->d_otTrace.clear();
     comboWriter->d_otTrace.start_time_unix_nano = traceTS;
-    comboWriter->d_otTrace.name = "RecRequest";
+    //comboWriter->d_otTrace.name = "RecRequest";
   }
   auto luaconfsLocal = g_luaconfs.getLocal();
   if (checkProtobufExport(luaconfsLocal)) {
index 761b9879a0d818e1d9e276e9aa6cc7475cf7810a..09242aa09cbb7f81769a2469429f8dd6a0015d68 100644 (file)
@@ -585,7 +585,7 @@ public:
   boost::optional<string> d_routingTag;
   ComboAddress d_fromAuthIP;
   RecEventTrace d_eventTrace;
-  pdns::trace::Span d_otTrace;
+  pdns::trace::InitialSpanInfo d_otTrace;
   std::shared_ptr<Logr::Logger> d_slog = g_slog->withName("syncres");
   boost::optional<EDNSExtendedError> d_extendedError;