*/
#include "dnsdist-opentelemetry.hh"
+#include "misc.hh"
#include <vector>
namespace pdns::trace::dnsdist
{
+#ifndef DISABLE_PROTOBUF
+static const KeyValue hostnameAttr{.key = "hostname", .value = {getHostname().value_or("")}};
+#endif
+
TracesData Tracer::getTracesData()
{
#ifdef DISABLE_PROTOBUF
#else
auto otTrace = pdns::trace::TracesData{
.resource_spans = {
- pdns::trace::ResourceSpans{
- .resource = {
- .attributes = std::vector<pdns::trace::KeyValue>{
- pdns::trace::KeyValue{
- "service.name", pdns::trace::AnyValue{"dnsdist"}},
- }},
- .scope_spans = std::vector<pdns::trace::ScopeSpans>{{.scope = {
- .name = "queryFromFrontend",
- .attributes = {d_attributes.begin(), d_attributes.end()},
- },
- .spans = {}}}}}};
+ {.resource = {
+ .attributes = {
+ {"service.name", {"dnsdist"}},
+ }},
+ .scope_spans = {{.scope = {
+ .name = "dnsdist/queryFromFrontend",
+ .version = PACKAGE_VERSION,
+ .attributes = {d_attributes.begin(), d_attributes.end()},
+ },
+ .spans = {}}}}}};
+
+ otTrace.resource_spans.at(0).scope_spans.at(0).scope.attributes.push_back(hostnameAttr);
{
auto lockedPre = d_preActivationSpans.read_only_lock();
BOOST_CHECK_EQUAL(trace.resource_spans.at(0).resource.attributes.size(), 1);
BOOST_CHECK_EQUAL(trace.resource_spans.at(0).resource.attributes.at(0).key, "service.name");
- BOOST_ASSERT(trace.resource_spans.at(0).scope_spans.at(0).scope.attributes.size() == 0);
+ // Check if we have a hostname
+ BOOST_CHECK_EQUAL(trace.resource_spans.at(0).scope_spans.at(0).scope.attributes.size(), 1U);
+ BOOST_CHECK_EQUAL(trace.resource_spans.at(0).scope_spans.at(0).scope.attributes.at(0).key, "hostname");
// Now activate and add 2 attributes
tracer->activate();
trace = tracer->getTracesData();
BOOST_ASSERT(trace.resource_spans.at(0).resource.attributes.size() == 1);
- BOOST_ASSERT(trace.resource_spans.at(0).scope_spans.at(0).scope.attributes.size() == 2);
+ // hostname plus the two we set
+ BOOST_ASSERT(trace.resource_spans.at(0).scope_spans.at(0).scope.attributes.size() == 3);
BOOST_CHECK_EQUAL(trace.resource_spans.at(0).scope_spans.at(0).scope.attributes.at(0).key, "foo");
BOOST_CHECK_EQUAL(trace.resource_spans.at(0).scope_spans.at(0).scope.attributes.at(0).value, AnyValue{"bar"});
{
auto tracer = pdns::trace::dnsdist::Tracer::getTracer();
auto data = tracer->getOTProtobuf();
- BOOST_TEST(data.size() == 54U);
+ BOOST_TEST(data.size() >= 100U);
tracer->activate();
tracer->setTraceAttribute("foo", AnyValue{"bar"});
data = tracer->getOTProtobuf();
- BOOST_TEST(data.size() == 68U);
+ BOOST_TEST(data.size() >= 110U);
}
BOOST_AUTO_TEST_SUITE_END()