]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
feat(dnsdist): add Lua method to dq to get TraceID
authorPieter Lexis <pieter.lexis@powerdns.com>
Thu, 25 Sep 2025 15:39:31 +0000 (17:39 +0200)
committerPieter Lexis <pieter.lexis@powerdns.com>
Tue, 14 Oct 2025 18:34:58 +0000 (20:34 +0200)
pdns/dnsdistdist/dnsdist-lua-bindings-dnsquestion.cc

index e3b37f271a09b9c8b7b2e6a964fad4703019ad62..42501d8fc795a884895bc776ab99a295f0e4650c 100644 (file)
@@ -30,6 +30,7 @@
 #include "dnsparser.hh"
 
 #include "protozero.hh"
+#include <string>
 
 static void addMetaKeyAndValuesToProtobufContent([[maybe_unused]] DNSQuestion& dnsQuestion, [[maybe_unused]] const std::string& key, [[maybe_unused]] const LuaArray<boost::variant<int64_t, std::string>>& values)
 {
@@ -336,6 +337,20 @@ void setupLuaBindingsDNSQuestion([[maybe_unused]] LuaContext& luaCtx)
     return true;
   });
 
+  luaCtx.registerFunction<std::optional<std::string> (DNSQuestion::*)()>(
+    "getTraceID",
+    []([[maybe_unused]] const DNSQuestion& dnsQuestion) -> std::optional<std::string> {
+#ifdef DISABLE_PROTOBUF
+      return std::nullopt;
+#else
+      if (dnsQuestion.ids.tracingEnabled) {
+        auto traceID = dnsQuestion.ids.d_OTTracer->getTraceID();
+        return std::string(traceID.begin(), traceID.end());
+      }
+      return std::nullopt;
+#endif
+    });
+
   class AsynchronousObject
   {
   public: