Skip to content

Commit f49a64e

Browse files
committed
feat(dnsdist): simplify DNSQuestion:withTraceSpan
1 parent 059eb35 commit f49a64e

File tree

2 files changed

+28
-14
lines changed

2 files changed

+28
-14
lines changed

pdns/dnsdistdist/dnsdist-lua-bindings-dnsquestion.cc

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -379,23 +379,27 @@ void setupLuaBindingsDNSQuestion([[maybe_unused]] LuaContext& luaCtx)
379379
#endif
380380
});
381381

382-
luaCtx.registerFunction<void (DNSQuestion::*)(const std::string& name, const std::function<void(const pdns::trace::dnsdist::Tracer::Closer& closer)>& func)>(
382+
luaCtx.registerFunction<void (DNSQuestion::*)(const std::string& name, const std::function<void()>& func)>(
383383
"withTraceSpan",
384-
[](const DNSQuestion& dnsQuestion, const std::string& name, const std::function<void(const pdns::trace::dnsdist::Tracer::Closer& closer)> func) {
384+
[](const DNSQuestion& dnsQuestion, const std::string& name, const std::function<void()>& func) {
385385
#ifndef DISABLE_PROTOBUF
386386
if (auto tracer = dnsQuestion.ids.getTracer(); tracer != nullptr) {
387387
auto closer = tracer->openSpan(name);
388-
func(closer);
388+
func();
389389
return;
390390
}
391391
#endif
392-
func(pdns::trace::dnsdist::Tracer::Closer());
392+
func();
393393
});
394394

395-
luaCtx.registerFunction<void (pdns::trace::dnsdist::Tracer::Closer::*)(const std::string& key, const std::string& value)>(
395+
luaCtx.registerFunction<void (DNSQuestion::*)(const std::string& key, const std::string& value)>(
396396
"setSpanAttribute",
397-
[](pdns::trace::dnsdist::Tracer::Closer& closer, const std::string& key, const std::string& value) {
398-
closer.setAttribute(key, AnyValue{value});
397+
[](const DNSQuestion& dnsQuestion, const std::string& key, const std::string& value) {
398+
#ifndef DISABLE_PROTOBUF
399+
if (auto tracer = dnsQuestion.ids.getTracer(); tracer != nullptr) {
400+
tracer->setSpanAttribute(tracer->getLastSpanID(), key, AnyValue{value});
401+
}
402+
#endif
399403
});
400404

401405
class AsynchronousObject
@@ -739,17 +743,27 @@ void setupLuaBindingsDNSQuestion([[maybe_unused]] LuaContext& luaCtx)
739743
return dnsdist::suspendResponse(dnsResponse, asyncID, queryID, timeoutMs);
740744
});
741745

742-
luaCtx.registerFunction<void (DNSResponse::*)(const std::string& name, const std::function<void(const pdns::trace::dnsdist::Tracer::Closer& closer)>& func)>(
746+
luaCtx.registerFunction<void (DNSResponse::*)(const std::string&, const std::function<void()>&)>(
743747
"withTraceSpan",
744-
[](const DNSResponse& dnsResponse, const std::string& name, const std::function<void(const pdns::trace::dnsdist::Tracer::Closer& closer)> func) {
748+
[](const DNSResponse& dnsResponse, const std::string& name, const std::function<void()>& func) {
745749
#ifndef DISABLE_PROTOBUF
746750
if (auto tracer = dnsResponse.ids.getTracer(); tracer != nullptr) {
747751
auto closer = tracer->openSpan(name);
748-
func(closer);
752+
func();
749753
return;
750754
}
751755
#endif
752-
func(pdns::trace::dnsdist::Tracer::Closer());
756+
func();
757+
});
758+
759+
luaCtx.registerFunction<void (DNSResponse::*)(const std::string& key, const std::string& value)>(
760+
"setSpanAttribute",
761+
[](const DNSResponse& dnsResponse, const std::string& key, const std::string& value) {
762+
#ifndef DISABLE_PROTOBUF
763+
if (auto tracer = dnsResponse.ids.getTracer(); tracer != nullptr) {
764+
tracer->setSpanAttribute(tracer->getLastSpanID(), key, AnyValue{value});
765+
}
766+
#endif
753767
});
754768

755769
luaCtx.registerFunction<bool (DNSResponse::*)(const DNSName& newName)>("changeName", [](DNSResponse& dnsResponse, const DNSName& newName) -> bool {

regression-tests.dnsdist/test_OpenTelemetryTracing.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1010,10 +1010,10 @@ class TestOpenTelemetryTracingSpansFromLua(DNSDistOpenTelemetryProtobufBaseTest)
10101010
function_code: |
10111011
return function (dq)
10121012
dq:withTraceSpan("my-span",
1013-
function (closer)
1014-
closer:setSpanAttribute("my-key-from-lua", "my-value-from-lua")
1013+
function ()
1014+
dq:setSpanAttribute("my-key-from-lua", "my-value-from-lua")
10151015
dq:withTraceSpan("my-second-span",
1016-
function(cl)
1016+
function()
10171017
end
10181018
)
10191019
end

0 commit comments

Comments
 (0)