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

Classes | |
| struct | impl |
| Internal implementation structure for span. More... | |
Public Member Functions | |
| span (std::string_view name, trace_context ctx, span_kind kind=span_kind::internal) | |
| Construct a new span. | |
| ~span () | |
| Destructor - automatically ends the span if not ended. | |
| span (const span &)=delete | |
| auto | operator= (const span &) -> span &=delete |
| span (span &&other) noexcept | |
| auto | operator= (span &&other) noexcept -> span & |
| auto | set_attribute (std::string_view key, std::string_view value) -> span & |
| Set a string attribute. | |
| auto | set_attribute (std::string_view key, const char *value) -> span & |
| Set a string attribute (const char* overload) | |
| auto | set_attribute (std::string_view key, int64_t value) -> span & |
| Set an integer attribute. | |
| auto | set_attribute (std::string_view key, double value) -> span & |
| Set a double attribute. | |
| auto | set_attribute (std::string_view key, bool value) -> span & |
| Set a boolean attribute. | |
| auto | add_event (std::string_view name) -> span & |
| Add an event to the span. | |
| auto | add_event (std::string_view name, const std::map< std::string, attribute_value > &attributes) -> span & |
| Add an event with attributes. | |
| auto | set_status (span_status status) -> span & |
| Set the span status. | |
| auto | set_status (span_status status, std::string_view description) -> span & |
| Set the span status with description. | |
| auto | set_error (std::string_view message) -> span & |
| Set error status with message. | |
| void | end () |
| Manually end the span. | |
| auto | is_ended () const noexcept -> bool |
| Check if the span has ended. | |
| auto | context () const noexcept -> const trace_context & |
| Get the trace context for this span. | |
| auto | name () const noexcept -> const std::string & |
| Get the span name. | |
| auto | kind () const noexcept -> span_kind |
| Get the span kind. | |
| auto | status () const noexcept -> span_status |
| Get the span status. | |
| auto | status_description () const noexcept -> const std::string & |
| Get the status description. | |
| auto | attributes () const noexcept -> const std::map< std::string, attribute_value > & |
| Get the span attributes. | |
| auto | events () const noexcept -> const std::vector< span_event > & |
| Get the span events. | |
| auto | start_time () const noexcept -> std::chrono::steady_clock::time_point |
| Get the span start time. | |
| auto | end_time () const noexcept -> std::chrono::steady_clock::time_point |
| Get the span end time. | |
| auto | duration () const noexcept -> std::chrono::nanoseconds |
| Get the span duration. | |
Private Attributes | |
| std::unique_ptr< impl > | impl_ |
RAII span for distributed tracing.
A span represents a single operation within a trace. It has a name, start and end time, attributes, and can have events recorded during its lifetime. The span automatically ends when destroyed (RAII).
Spans maintain the current trace context via thread-local storage, enabling automatic parent-child relationship tracking.
|
explicit |
Construct a new span.
| name | Span name (operation name) |
| ctx | Trace context for this span |
| kind | Kind of span (default: internal) |
Definition at line 84 of file span.cpp.
References impl_, and kcenon::network::tracing::span::impl::owner.
| kcenon::network::tracing::span::~span | ( | ) |
Destructor - automatically ends the span if not ended.
Definition at line 90 of file span.cpp.
References kcenon::network::tracing::span::impl::do_end(), kcenon::network::tracing::span::impl::ended, and impl_.

|
delete |
|
noexcept |
| auto kcenon::network::tracing::span::add_event | ( | std::string_view | name | ) | -> span& |
Add an event to the span.
| name | Event name |
Definition at line 162 of file span.cpp.
References kcenon::network::tracing::span_event::name.
| auto kcenon::network::tracing::span::add_event | ( | std::string_view | name, |
| const std::map< std::string, attribute_value > & | attributes ) -> span& |
Add an event with attributes.
| name | Event name |
| attributes | Event attributes |
Definition at line 174 of file span.cpp.
References kcenon::network::tracing::span_event::name.
|
nodiscardnoexcept |
Get the span attributes.
Definition at line 263 of file span.cpp.
References kcenon::network::tracing::span::impl::attributes, and impl_.
|
nodiscardnoexcept |
Get the trace context for this span.
Definition at line 235 of file span.cpp.
References kcenon::network::tracing::span::impl::context, and impl_.
|
nodiscardnoexcept |
Get the span duration.
Definition at line 286 of file span.cpp.
References end(), kcenon::network::tracing::span::impl::end_time, kcenon::network::tracing::span::impl::ended, impl_, and kcenon::network::tracing::span::impl::start_time.

| void kcenon::network::tracing::span::end | ( | ) |
Manually end the span.
After calling end(), the span will not be ended again in destructor.
Definition at line 222 of file span.cpp.
References kcenon::network::tracing::span::impl::do_end(), and impl_.
Referenced by duration().


|
nodiscardnoexcept |
|
nodiscardnoexcept |
|
nodiscardnoexcept |
|
nodiscardnoexcept |
Get the span kind.
Definition at line 247 of file span.cpp.
References impl_, kcenon::network::tracing::internal, and kcenon::network::tracing::span::impl::kind.
|
nodiscardnoexcept |
Get the span name.
Definition at line 241 of file span.cpp.
References impl_, and kcenon::network::tracing::span::impl::name.
| auto kcenon::network::tracing::span::set_attribute | ( | std::string_view | key, |
| bool | value ) -> span& |
| auto kcenon::network::tracing::span::set_attribute | ( | std::string_view | key, |
| const char * | value ) -> span& |
Set a string attribute (const char* overload)
| key | Attribute key |
| value | Attribute value |
This overload prevents implicit conversion of const char* to bool.
| auto kcenon::network::tracing::span::set_attribute | ( | std::string_view | key, |
| double | value ) -> span& |
| auto kcenon::network::tracing::span::set_attribute | ( | std::string_view | key, |
| int64_t | value ) -> span& |
| auto kcenon::network::tracing::span::set_attribute | ( | std::string_view | key, |
| std::string_view | value ) -> span& |
| auto kcenon::network::tracing::span::set_error | ( | std::string_view | message | ) | -> span& |
Set error status with message.
| message | Error message |
Definition at line 207 of file span.cpp.
References kcenon::network::tracing::error, and kcenon::network::message.
| auto kcenon::network::tracing::span::set_status | ( | span_status | status | ) | -> span& |
Set the span status.
| status | Status code |
Definition at line 188 of file span.cpp.
| auto kcenon::network::tracing::span::set_status | ( | span_status | status, |
| std::string_view | description ) -> span& |
Set the span status with description.
| status | Status code |
| description | Status description |
|
nodiscardnoexcept |
Get the span start time.
Definition at line 276 of file span.cpp.
References impl_, and kcenon::network::tracing::span::impl::start_time.
|
nodiscardnoexcept |
Get the span status.
Definition at line 252 of file span.cpp.
References impl_, kcenon::network::tracing::span::impl::status, and kcenon::network::tracing::unset.
|
nodiscardnoexcept |
Get the status description.
Definition at line 257 of file span.cpp.
References impl_, and kcenon::network::tracing::span::impl::status_description.
|
private |
Definition at line 286 of file span.h.
Referenced by attributes(), context(), duration(), end(), end_time(), events(), is_ended(), kind(), name(), span(), start_time(), status(), status_description(), and ~span().