From: Pieter Lexis Date: Tue, 30 Sep 2025 16:07:14 +0000 (+0200) Subject: feat(dnsdist): add getSpanID to DNSQuestion X-Git-Tag: rec-5.4.0-alpha1~187^2~14 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3d184ab9622ea7deea865c0d93f7a8e398f4f5df;p=thirdparty%2Fpdns.git feat(dnsdist): add getSpanID to DNSQuestion --- diff --git a/pdns/dnsdistdist/dnsdist-lua-bindings-dnsquestion.cc b/pdns/dnsdistdist/dnsdist-lua-bindings-dnsquestion.cc index 42501d8fc7..c56b0c5256 100644 --- a/pdns/dnsdistdist/dnsdist-lua-bindings-dnsquestion.cc +++ b/pdns/dnsdistdist/dnsdist-lua-bindings-dnsquestion.cc @@ -351,6 +351,20 @@ void setupLuaBindingsDNSQuestion([[maybe_unused]] LuaContext& luaCtx) #endif }); + luaCtx.registerFunction (DNSQuestion::*)()>( + "getSpanID", + []([[maybe_unused]] const DNSQuestion& dnsQuestion) -> std::optional { +#ifdef DISABLE_PROTOBUF + return std::nullopt; +#else + if (dnsQuestion.ids.tracingEnabled) { + auto spanID = dnsQuestion.ids.d_OTTracer->getLastSpanID(); + return std::string(spanID.begin(), spanID.end()); + } + return std::nullopt; +#endif + }); + class AsynchronousObject { public: diff --git a/pdns/dnsdistdist/docs/reference/dq.rst b/pdns/dnsdistdist/docs/reference/dq.rst index 10338e0ee9..b7a35c2301 100644 --- a/pdns/dnsdistdist/docs/reference/dq.rst +++ b/pdns/dnsdistdist/docs/reference/dq.rst @@ -255,6 +255,14 @@ This state can be modified from the various hooks. :returns: A binary string containing the OpenTelemetry trace identifier + .. method:: DNSQuestion:getSpanID() -> string + + .. versionadded:: 2.1.0 + + When :doc:`OpenTelemetry tracing ` is enabled for this query, get the ID of the current Span. Otherwise, ``nil``. This is an opaque binary string. + + :returns: A binary string containing the OpenTelemetry Span identifier + .. method:: DNSQuestion:getTrailingData() -> string .. versionadded:: 1.4.0 diff --git a/pdns/dnsdistdist/docs/reference/ottrace.rst b/pdns/dnsdistdist/docs/reference/ottrace.rst index b2229acb74..075c8d5fad 100644 --- a/pdns/dnsdistdist/docs/reference/ottrace.rst +++ b/pdns/dnsdistdist/docs/reference/ottrace.rst @@ -43,8 +43,8 @@ Example configuration type: RemoteLog logger_name: pblog -Passing Trace ID to downstream servers -====================================== +Passing Trace ID and Span ID to downstream servers +================================================== When storing traces, it is beneficial to correlate traces of the same query through different applications. The `PowerDNS Recursor `__ (since 5.3.0) supports the experimental `draft-edns-otel-trace-ids `__ EDNS option to pass the trace identifier. @@ -67,3 +67,24 @@ Combining all this, a :func:`LuaAction` can be used to add this EDNS option to t end return DNSAction.None end + +Optionally, the Span ID can also be added to the query. +This value is retrieved with the :func:`getSpanID ` function and can be added to the query as follows: + +.. code-block:: yaml + + - name: Add TraceID and SpanID to EDNS for backend + selector: + type: All + action: + type: Lua + function_code: | + return function (dq) + tid = dq:getTraceID() + sid = dq:getSpanID() + if (tid ~= nil and sid ~= nil) then + -- PowerDNS Recursor uses EDNS Option Code 65500. + dq:setEDNSOption(65500, "\000\000" .. tid .. sid) + end + return DNSAction.None + end