std::optional<pdns::trace::dnsdist::Tracer::Closer> InternalQueryState::getCloser([[maybe_unused]] const std::string_view& name, [[maybe_unused]] const SpanID& parentSpanID)
{
- std::optional<pdns::trace::dnsdist::Tracer::Closer> ret(std::nullopt);
+ std::optional<pdns::trace::dnsdist::Tracer::Closer> ret{std::nullopt};
#ifndef DISABLE_PROTOBUF
// getTracer returns a Tracer when tracing is globally enabled
// tracingEnabled tells us whether or not tracing is enabled for this query
// Should tracing be disabled, *but* we have not processed query rules, we will still return a closer if tracing is globally enabled
if (auto tracer = getTracer(); tracer != nullptr && (tracingEnabled || !rulesAppliedToQuery)) {
- ret = std::optional<pdns::trace::dnsdist::Tracer::Closer>(d_OTTracer->openSpan(std::string(name), parentSpanID));
+ ret = d_OTTracer->openSpan(std::string(name), parentSpanID);
}
#endif
return ret;
std::optional<pdns::trace::dnsdist::Tracer::Closer> InternalQueryState::getCloser([[maybe_unused]] const std::string_view& name, [[maybe_unused]] const std::string_view& parentSpanName)
{
- std::optional<pdns::trace::dnsdist::Tracer::Closer> ret(std::nullopt);
+ std::optional<pdns::trace::dnsdist::Tracer::Closer> ret{std::nullopt};
#ifndef DISABLE_PROTOBUF
if (auto tracer = getTracer(); tracer != nullptr) {
auto parentSpanID = d_OTTracer->getLastSpanIDForName(std::string(parentSpanName));
- return getCloser(name, parentSpanID);
+ ret = getCloser(name, parentSpanID);
}
#endif
return ret;
std::optional<pdns::trace::dnsdist::Tracer::Closer> InternalQueryState::getCloser([[maybe_unused]] const std::string_view& name)
{
- std::optional<pdns::trace::dnsdist::Tracer::Closer> ret(std::nullopt);
+ std::optional<pdns::trace::dnsdist::Tracer::Closer> ret{std::nullopt};
#ifndef DISABLE_PROTOBUF
if (auto tracer = getTracer(); tracer != nullptr) {
- return getCloser(std::string(name), tracer->getLastSpanID());
+ ret = getCloser(std::string(name), tracer->getLastSpanID());
}
#endif
return ret;
std::optional<pdns::trace::dnsdist::Tracer::Closer> InternalQueryState::getRulesCloser([[maybe_unused]] const std::string_view& ruleName, [[maybe_unused]] const std::string& ruleType)
{
- std::optional<pdns::trace::dnsdist::Tracer::Closer> ret(std::nullopt);
+ std::optional<pdns::trace::dnsdist::Tracer::Closer> ret{std::nullopt};
#ifndef DISABLE_PROTOBUF
static const std::string prefix = "Rule: ";
// getTracer returns a Tracer when tracing is globally enabled
if (auto tracer = getTracer(); tracer != nullptr && (tracingEnabled || !rulesAppliedToQuery)) {
auto parentSpanID = tracer->getLastSpanID();
auto name = ruleType + prefix + std::string(ruleName);
- ret = std::optional<pdns::trace::dnsdist::Tracer::Closer>(tracer->openSpan(name, parentSpanID));
+ ret = tracer->openSpan(name, parentSpanID);
}
#endif
return ret;
d_tracer->closeSpan(d_spanID);
}
#endif
- };
- Closer(const Closer&) = default;
- Closer& operator=(const Closer&) = default;
- Closer& operator=(Closer&&) noexcept = default;
- Closer(Closer&&) = default;
+ }
+ Closer(const Closer&) = delete;
+ Closer& operator=(const Closer&) = delete;
+ Closer& operator=(Closer&& rhs) noexcept
+ {
+#ifndef DISABLE_PROTOBUF
+ this->d_tracer = std::move(rhs.d_tracer);
+ this->d_spanID = rhs.d_spanID;
+ /* we wouldn't want to close it twice */
+ rhs.d_tracer.reset();
+ rhs.d_spanID.clear();
+#endif
+ return *this;
+ }
+ Closer(Closer&& rhs)
+ {
+#ifndef DISABLE_PROTOBUF
+ this->d_tracer = std::move(rhs.d_tracer);
+ this->d_spanID = rhs.d_spanID;
+ /* we wouldn't want to close it twice */
+ rhs.d_tracer.reset();
+ rhs.d_spanID.clear();
+#endif
+ }
/**
* @brief Get the SpanID