#endif
});
+ luaCtx.registerFunction<std::optional<std::string> (DNSQuestion::*)()>(
+ "getSpanID",
+ []([[maybe_unused]] const DNSQuestion& dnsQuestion) -> std::optional<std::string> {
+#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:
:returns: A binary string containing the OpenTelemetry trace identifier
+ .. method:: DNSQuestion:getSpanID() -> string
+
+ .. versionadded:: 2.1.0
+
+ When :doc:`OpenTelemetry tracing <ottrace>` 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
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 <https://doc.powerdns.com/recursor>`__ (since 5.3.0) supports the experimental `draft-edns-otel-trace-ids <https://github.com/PowerDNS/draft-edns-otel-trace-ids>`__ EDNS option to pass the trace identifier.
end
return DNSAction.None
end
+
+Optionally, the Span ID can also be added to the query.
+This value is retrieved with the :func:`getSpanID <DNSQuestion: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