131 -> std::vector<std::pair<std::
string, std::
string>>;
147 const std::vector<std::pair<std::
string, std::
string>>& headers)
154 [[nodiscard]] auto
is_valid() const noexcept ->
bool;
160 [[nodiscard]] auto
is_sampled() const noexcept ->
bool;
197 [[nodiscard]] auto
span_id_hex() const -> std::
string;
202 [[nodiscard]] auto operator==(const
trace_context& other) const noexcept
208 [[nodiscard]] auto operator!=(const
trace_context& other) const noexcept
251[[nodiscard]]
auto bytes_to_hex(
const uint8_t* data,
size_t size) -> std::string;
260[[nodiscard]]
auto hex_to_bytes(std::string_view hex, uint8_t* out,
size_t size)
RAII span for distributed tracing.
Immutable trace context for distributed tracing.
static auto create_span(std::string_view name) -> span
Create a new root span with a new trace context.
auto trace_id() const noexcept -> const trace_id_t &
Get the trace ID.
auto span_id_hex() const -> std::string
Convert span ID to hex string.
static auto current() -> trace_context
Get the current trace context from thread-local storage.
static void clear_current()
Clear the current thread-local trace context.
auto trace_id_hex() const -> std::string
Convert trace ID to hex string.
static auto from_headers(const std::vector< std::pair< std::string, std::string > > &headers) -> trace_context
Parse trace context from HTTP headers.
auto to_headers() const -> std::vector< std::pair< std::string, std::string > >
Convert context to HTTP headers for propagation.
static auto from_traceparent(std::string_view traceparent) -> trace_context
Parse trace context from W3C traceparent header.
auto parent_span_id() const noexcept -> const std::optional< span_id_t > &
Get the parent span ID.
auto is_sampled() const noexcept -> bool
Check if this trace is sampled.
auto flags() const noexcept -> trace_flags
Get the trace flags.
auto create_child_span(std::string_view name) const -> span
Create a child span inheriting this context.
auto is_valid() const noexcept -> bool
Check if this context is valid.
std::optional< span_id_t > parent_span_id_
static void set_current(const trace_context &ctx)
Set the current thread-local trace context.
auto span_id() const noexcept -> const span_id_t &
Get the span ID.
trace_context()=default
Default constructor creates an invalid context.
auto to_traceparent() const -> std::string
Convert context to W3C traceparent header value.
auto bytes_to_hex(const uint8_t *data, size_t size) -> std::string
Convert bytes to lowercase hex string.
trace_flags
Trace flags (8-bit)
auto generate_span_id() -> span_id_t
Generate a random span ID.
std::array< uint8_t, 8 > span_id_t
Span ID type (64-bit identifier)
auto generate_trace_id() -> trace_id_t
Generate a random trace ID.
auto hex_to_bytes(std::string_view hex, uint8_t *out, size_t size) -> bool
Parse hex string to bytes.
std::array< uint8_t, 16 > trace_id_t
Trace ID type (128-bit identifier)