]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
feat(sdig): parse (optional) spanid from arguments
authorPieter Lexis <pieter.lexis@powerdns.com>
Thu, 30 Oct 2025 09:39:54 +0000 (10:39 +0100)
committerPieter Lexis <pieter.lexis@powerdns.com>
Tue, 4 Nov 2025 11:02:43 +0000 (12:02 +0100)
pdns/sdig.cc

index 0242a010fe9336973a8974aa022c27601c650d7e..44b6cabb82dd217f9e37b446776580cb0f697212 100644 (file)
@@ -371,19 +371,29 @@ try {
         }
         auto traceIDArg = std::string(argv[++i]);
         pdns::trace::TraceID traceid;
+        pdns::trace::SpanID spanid;
         if (traceIDArg == "-") {
           traceid.makeRandom();
+          spanid.makeRandom();
         }
         else {
           auto traceIDStr = makeBytesFromHex(traceIDArg);
-          if (traceIDStr.size() > traceid.size()) {
-            cerr << "Maximum length of traceid is " << traceid.size() << " bytes" << endl;
+          if (traceIDStr.size() > traceid.size() + spanid.size()) {
+            cerr << "Maximum length of traceid plus spanid is " << traceid.size() + spanid.size()<< " bytes" << endl;
             exit(EXIT_FAILURE);
           }
+          std::string spanidStr(traceIDStr.begin() + traceid.size(), traceIDStr.end());
           traceIDStr.resize(traceid.size());
           pdns::trace::fill(traceid, traceIDStr);
+          if (spanidStr.empty()) {
+            spanid.makeRandom();
+          } else if (spanidStr.size() != spanid.size()) {
+            cerr << "spanid size must be " << spanid.size()<< " bytes, but is " << spanidStr.size() << endl;
+            exit(EXIT_FAILURE);
+          } else {
+            pdns::trace::fill(spanid, spanidStr);
+          }
         }
-        pdns::trace::SpanID spanid{}; // default: all zero, so no parent
         otdata = std::make_pair(traceid, spanid);
       }
       else {