4#include "attribute_map.hpp"
20 class Span :
public AttributeMap
48 Span &operator=(
const Span &) =
delete;
51 , statusMessage_(
std::move(other.statusMessage_))
57 Span &operator=(Span &&other)
noexcept
61 AttributeMap::operator=(
std::move(other));
62 statusMessage_ =
std::move(other.statusMessage_);
63 status_ = other.status_;
72#ifdef __cpp_lib_uncaught_exceptions
73 const bool hasUncaughtException = std::uncaught_exceptions() > 0;
75 const bool hasUncaughtException = std::uncaught_exception;
77 if (status_ == CExports::CVTSS_Unset && hasUncaughtException)
78 status_ = CExports::CVTSS_Error;
81 CExports::CVTSpanEnd(handle_, status_, (statusMessage_.size()) ? statusMessage_.c_str() :
nullptr);
91 status_ = CExports::CVTSS_Ok;
103 status_ = CExports::CVTSS_Ok;
113 status_ = CExports::CVTSS_Error;
124 statusMessage_ = message;
125 status_ = CExports::CVTSS_Error;
135 [[noreturn]]
void Raise(
const T &error)
137 statusMessage_ = error.what();
138 status_ = CExports::CVTSS_Error;
151 status_ = (code) ? CExports::CVTSS_Error : CExports::CVTSS_Ok;
164 status_ = (res) ? CExports::CVTSS_Ok : CExports::CVTSS_Error;
176 statusMessage_ = statusMessage;
183 const auto &
module = Module::Get();
184 if (!module.WouldTrace())
186 CExports::CVTSPAN handle =
nullptr;
187 CExports::CVTModuleStartSpan(module.Handle(), name.c_str(), handle);
191 Span() noexcept = default;
193 CExports::CVTSpanStatus status_ = CExports::CVTSS_Unset;
194 std::
string statusMessage_;
A attribute map for telemetry data.
Definition attribute_map.hpp:32
A span object to report traces.
Definition span.hpp:21
static Span Create(const std::string &name)
Creates a span with the given name.
Definition span.hpp:29
T Return(T code) noexcept
Set the span status based on return code evaluation.
Definition span.hpp:149
static Span Create()
Creates a dummy span.
Definition span.hpp:42
void SetStatusMessage(const std::string &statusMessage) noexcept
Set the status message.
Definition span.hpp:174
T ReturnBool(T res) noexcept
Set the span status based on boolean interpretation of a result.
Definition span.hpp:162
T Succeed(T &&result)
Return a result and the span status to success.
Definition span.hpp:101
void Fail(const std::string &message) noexcept
Set the span status to fail with a message.
Definition span.hpp:122
void Fail() noexcept
Set the span status to fail.
Definition span.hpp:111
void Succeed() noexcept
Set the span status to success.
Definition span.hpp:89
void Raise(const T &error)
Set the span status to fail and raises an exception.
Definition span.hpp:135
Namespace for telemetry.
Definition attribute_map.hpp:16
Root namespace for the Image Manager interface.
Definition version.hpp:11