|
Network System 0.1.1
High-performance modular networking library for scalable client-server applications
|
Immutable trace context for distributed tracing. More...
#include <trace_context.h>

Public Member Functions | |
| trace_context ()=default | |
| Default constructor creates an invalid context. | |
| trace_context (trace_id_t trace_id, span_id_t span_id, trace_flags flags, std::optional< span_id_t > parent_span_id=std::nullopt) | |
| Construct a trace context with all components. | |
| auto | create_child_span (std::string_view name) const -> span |
| Create a child span inheriting this context. | |
| auto | to_traceparent () const -> std::string |
| Convert context to W3C traceparent header value. | |
| auto | to_headers () const -> std::vector< std::pair< std::string, std::string > > |
| Convert context to HTTP headers for propagation. | |
| auto | is_valid () const noexcept -> bool |
| Check if this context is valid. | |
| auto | is_sampled () const noexcept -> bool |
| Check if this trace is sampled. | |
| auto | trace_id () const noexcept -> const trace_id_t & |
| Get the trace ID. | |
| auto | span_id () const noexcept -> const span_id_t & |
| Get the span ID. | |
| auto | parent_span_id () const noexcept -> const std::optional< span_id_t > & |
| Get the parent span ID. | |
| auto | flags () const noexcept -> trace_flags |
| Get the trace flags. | |
| auto | trace_id_hex () const -> std::string |
| Convert trace ID to hex string. | |
| auto | span_id_hex () const -> std::string |
| Convert span ID to hex string. | |
| auto | operator== (const trace_context &other) const noexcept -> bool |
| Equality comparison. | |
| auto | operator!= (const trace_context &other) const noexcept -> bool |
| Inequality comparison. | |
Static Public Member Functions | |
| static auto | current () -> trace_context |
| Get the current trace context from thread-local storage. | |
| static auto | create_span (std::string_view name) -> span |
| Create a new root span with a new trace context. | |
| static auto | from_traceparent (std::string_view traceparent) -> trace_context |
| Parse trace context from W3C traceparent header. | |
| static auto | from_headers (const std::vector< std::pair< std::string, std::string > > &headers) -> trace_context |
| Parse trace context from HTTP headers. | |
Static Private Member Functions | |
| static void | set_current (const trace_context &ctx) |
| Set the current thread-local trace context. | |
| static void | clear_current () |
| Clear the current thread-local trace context. | |
Private Attributes | |
| trace_id_t | trace_id_ {} |
| span_id_t | span_id_ {} |
| std::optional< span_id_t > | parent_span_id_ |
| trace_flags | flags_ {trace_flags::none} |
| bool | valid_ {false} |
Friends | |
| class | span |
Immutable trace context for distributed tracing.
This class represents a W3C Trace Context compatible trace context that can be propagated across network boundaries. It stores trace ID, span ID, parent span ID, and sampling decision.
Thread-local storage is used to maintain the current trace context, enabling automatic context propagation within a thread.
Definition at line 77 of file trace_context.h.
|
default |
Default constructor creates an invalid context.
| kcenon::network::tracing::trace_context::trace_context | ( | trace_id_t | trace_id, |
| span_id_t | span_id, | ||
| trace_flags | flags, | ||
| std::optional< span_id_t > | parent_span_id = std::nullopt ) |
Construct a trace context with all components.
| trace_id | 128-bit trace identifier |
| span_id | 64-bit span identifier |
| flags | Trace flags (sampling decision) |
| parent_span_id | Optional parent span identifier |
Definition at line 80 of file trace_context.cpp.
|
staticprivate |
Clear the current thread-local trace context.
Definition at line 100 of file trace_context.cpp.
Referenced by kcenon::network::tracing::span::impl::do_end().

|
nodiscard |
Create a child span inheriting this context.
| name | Name of the child span |
Definition at line 121 of file trace_context.cpp.
References kcenon::network::tracing::generate_span_id(), kcenon::network::tracing::generate_trace_id(), and kcenon::network::tracing::sampled.

|
staticnodiscard |
Create a new root span with a new trace context.
| name | Name of the span |
Definition at line 105 of file trace_context.cpp.
References kcenon::network::tracing::generate_span_id(), kcenon::network::tracing::generate_trace_id(), and kcenon::network::tracing::sampled.
Referenced by kcenon::network::protocols::grpc::grpc_client::impl::call_raw(), kcenon::network::protocols::quic::connection::close(), kcenon::network::protocols::quic::connection::close_application(), kcenon::network::protocols::grpc::grpc_client::impl::connect(), kcenon::network::protocols::http2::http2_client::connect(), kcenon::network::protocols::quic::connection::init_server_handshake(), kcenon::network::core::messaging_server::on_accept(), kcenon::network::protocols::quic::connection::receive_packet(), kcenon::network::core::messaging_quic_client::send_on_stream(), kcenon::network::core::messaging_client::send_packet(), kcenon::network::core::messaging_quic_client::send_packet(), kcenon::network::protocols::http2::http2_client::send_request(), simulate_cache_lookup(), simulate_database_query(), kcenon::network::protocols::grpc::grpc_server::impl::start(), kcenon::network::core::messaging_client::start_client(), kcenon::network::core::messaging_quic_client::start_client(), kcenon::network::protocols::quic::connection::start_handshake(), and kcenon::network::core::messaging_server::start_server().


|
staticnodiscard |
Get the current trace context from thread-local storage.
Definition at line 90 of file trace_context.cpp.
|
nodiscardnoexcept |
Get the trace flags.
Definition at line 274 of file trace_context.cpp.
References flags_.
|
staticnodiscard |
Parse trace context from HTTP headers.
| headers | Vector of header name-value pairs |
Definition at line 226 of file trace_context.cpp.
Referenced by main().

|
staticnodiscard |
Parse trace context from W3C traceparent header.
| traceparent | The traceparent header value |
Definition at line 173 of file trace_context.cpp.
References kcenon::network::tracing::hex_to_bytes(), and kcenon::network::tracing::trace_id.

|
nodiscardnoexcept |
Check if this trace is sampled.
Definition at line 254 of file trace_context.cpp.
References flags_, and kcenon::network::tracing::sampled.
Referenced by to_traceparent().

|
nodiscardnoexcept |
Check if this context is valid.
Definition at line 249 of file trace_context.cpp.
References valid_.
Referenced by kcenon::network::tracing::span::impl::do_end(), to_headers(), and to_traceparent().

|
nodiscardnoexcept |
Inequality comparison.
Definition at line 296 of file trace_context.cpp.
|
nodiscardnoexcept |
Equality comparison.
Definition at line 289 of file trace_context.cpp.
|
nodiscardnoexcept |
Get the parent span ID.
Definition at line 269 of file trace_context.cpp.
References parent_span_id_.
|
staticprivate |
Set the current thread-local trace context.
| ctx | Context to set |
Definition at line 95 of file trace_context.cpp.
Referenced by kcenon::network::tracing::span::impl::do_end(), and kcenon::network::tracing::span::impl::impl().

|
nodiscardnoexcept |
Get the span ID.
Definition at line 264 of file trace_context.cpp.
References span_id_.
|
nodiscard |
Convert span ID to hex string.
Definition at line 284 of file trace_context.cpp.
References kcenon::network::tracing::bytes_to_hex(), and span_id_.
Referenced by to_traceparent().


|
nodiscard |
Convert context to HTTP headers for propagation.
Returns headers conforming to W3C Trace Context specification.
Definition at line 160 of file trace_context.cpp.
References is_valid(), and to_traceparent().

|
nodiscard |
Convert context to W3C traceparent header value.
Format: {version}-{trace-id}-{parent-id}-{trace-flags} Example: 00-0af7651916cd43dd8448eb211c80319c-b7ad6b7169203331-01
Definition at line 140 of file trace_context.cpp.
References is_sampled(), is_valid(), span_id_hex(), and trace_id_hex().
Referenced by to_headers().


|
nodiscardnoexcept |
Get the trace ID.
Definition at line 259 of file trace_context.cpp.
References trace_id_.
|
nodiscard |
Convert trace ID to hex string.
Definition at line 279 of file trace_context.cpp.
References kcenon::network::tracing::bytes_to_hex(), and trace_id_.
Referenced by to_traceparent().


|
friend |
Definition at line 230 of file trace_context.h.
|
private |
Definition at line 215 of file trace_context.h.
Referenced by flags(), and is_sampled().
|
private |
Definition at line 214 of file trace_context.h.
Referenced by parent_span_id().
|
private |
|
private |
Definition at line 212 of file trace_context.h.
Referenced by trace_id(), and trace_id_hex().
|
private |