Monitoring System 0.1.0
System resource monitoring with pluggable collectors and alerting
Loading...
Searching...
No Matches
kcenon::monitoring::distributed_tracer Class Reference

Distributed tracer for managing spans and traces. More...

#include <distributed_tracer.h>

Collaboration diagram for kcenon::monitoring::distributed_tracer:
Collaboration graph

Public Member Functions

 distributed_tracer ()
 
 ~distributed_tracer ()
 
 distributed_tracer (const distributed_tracer &)=delete
 
distributed_traceroperator= (const distributed_tracer &)=delete
 
 distributed_tracer (distributed_tracer &&) noexcept
 
distributed_traceroperator= (distributed_tracer &&) noexcept
 
common::Result< std::shared_ptr< trace_span > > start_span (const std::string &operation_name, const std::string &service_name="monitoring_system")
 Start a new root span.
 
common::Result< std::shared_ptr< trace_span > > start_child_span (const trace_span &parent, const std::string &operation_name)
 Start a child span.
 
common::Result< std::shared_ptr< trace_span > > start_span_from_context (const trace_context &context, const std::string &operation_name)
 Start a span from trace context (for incoming requests)
 
common::Result< bool > finish_span (std::shared_ptr< trace_span > span)
 Finish a span.
 
std::shared_ptr< trace_spanget_current_span () const
 Get current active span for this thread.
 
void set_current_span (std::shared_ptr< trace_span > span)
 Set current active span for this thread.
 
trace_context extract_context (const trace_span &span) const
 Extract trace context for propagation.
 
template<typename Carrier >
void inject_context (const trace_context &context, Carrier &carrier)
 Inject trace context into carrier (e.g., HTTP headers)
 
template<typename Carrier >
common::Result< trace_contextextract_context_from_carrier (const Carrier &carrier)
 Extract trace context from carrier.
 
common::Result< std::vector< trace_span > > get_trace (const std::string &trace_id) const
 Get all spans for a trace.
 
common::Result< bool > export_spans (std::vector< trace_span > spans)
 Export spans to external system.
 
void set_exporter (std::shared_ptr< trace_exporter_interface > exporter)
 Set the trace exporter for span export.
 
std::shared_ptr< trace_exporter_interfaceget_exporter () const
 Get the current trace exporter.
 
void configure_export (const trace_export_settings &settings)
 Configure export settings.
 
trace_export_settings get_export_settings () const
 Get current export settings.
 
common::VoidResult flush ()
 Manually flush all pending spans to exporter.
 
std::unordered_map< std::string, std::size_t > get_export_stats () const
 Get export statistics.
 

Private Attributes

std::unique_ptr< tracer_impl > impl_
 

Detailed Description

Distributed tracer for managing spans and traces.

Examples
distributed_tracing_example.cpp.

Definition at line 195 of file distributed_tracer.h.

Constructor & Destructor Documentation

◆ distributed_tracer() [1/3]

kcenon::monitoring::distributed_tracer::distributed_tracer ( )

◆ ~distributed_tracer()

kcenon::monitoring::distributed_tracer::~distributed_tracer ( )

◆ distributed_tracer() [2/3]

kcenon::monitoring::distributed_tracer::distributed_tracer ( const distributed_tracer & )
delete

◆ distributed_tracer() [3/3]

kcenon::monitoring::distributed_tracer::distributed_tracer ( distributed_tracer && )
noexcept

Member Function Documentation

◆ configure_export()

void kcenon::monitoring::distributed_tracer::configure_export ( const trace_export_settings & settings)

Configure export settings.

Parameters
settingsExport configuration settings

◆ export_spans()

common::Result< bool > kcenon::monitoring::distributed_tracer::export_spans ( std::vector< trace_span > spans)

Export spans to external system.

◆ extract_context()

trace_context kcenon::monitoring::distributed_tracer::extract_context ( const trace_span & span) const

Extract trace context for propagation.

Examples
distributed_tracing_example.cpp.

Referenced by WebService::call_downstream_service(), and main().

Here is the caller graph for this function:

◆ extract_context_from_carrier()

template<typename Carrier >
common::Result< trace_context > kcenon::monitoring::distributed_tracer::extract_context_from_carrier ( const Carrier & carrier)
inline

Extract trace context from carrier.

Examples
distributed_tracing_example.cpp.

Definition at line 275 of file distributed_tracer.h.

275 {
276 auto traceparent_it = carrier.find("traceparent");
277 if (traceparent_it == carrier.end()) {
278 return common::Result<trace_context>::err(error_info(kcenon::monitoring::monitoring_error_code::not_found,
279 "Traceparent not found in carrier").to_common_error());
280 }
281
282 auto ctx_result = trace_context::from_w3c_traceparent(traceparent_it->second);
283 if (ctx_result.is_err()) {
284 return common::Result<trace_context>::err(ctx_result.error());
285 }
286
287 auto ctx = ctx_result.value();
288
289 // Extract tracestate if present
290 auto tracestate_it = carrier.find("tracestate");
291 if (tracestate_it != carrier.end()) {
292 ctx.trace_state = tracestate_it->second;
293 }
294
295 // Extract baggage
296 for (const auto& [key, value] : carrier) {
297 if (key.find("baggage-") == 0) { // C++17 compatible
298 ctx.baggage[key.substr(8)] = value;
299 }
300 }
301
302 return ctx;
303 }
static common::Result< trace_context > from_w3c_traceparent(const std::string &header)
Parse from W3C Trace Context format.

References kcenon::monitoring::trace_context::from_w3c_traceparent(), and kcenon::monitoring::not_found.

Referenced by WebService::handle_request(), and main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ finish_span()

common::Result< bool > kcenon::monitoring::distributed_tracer::finish_span ( std::shared_ptr< trace_span > span)

◆ flush()

common::VoidResult kcenon::monitoring::distributed_tracer::flush ( )

Manually flush all pending spans to exporter.

Returns
Result indicating success or failure

◆ get_current_span()

std::shared_ptr< trace_span > kcenon::monitoring::distributed_tracer::get_current_span ( ) const

Get current active span for this thread.

Referenced by TEST_F().

Here is the caller graph for this function:

◆ get_export_settings()

trace_export_settings kcenon::monitoring::distributed_tracer::get_export_settings ( ) const

Get current export settings.

Returns
Current export settings

◆ get_export_stats()

std::unordered_map< std::string, std::size_t > kcenon::monitoring::distributed_tracer::get_export_stats ( ) const

Get export statistics.

Returns
Map of statistic name to value

◆ get_exporter()

std::shared_ptr< trace_exporter_interface > kcenon::monitoring::distributed_tracer::get_exporter ( ) const

Get the current trace exporter.

Returns
Shared pointer to current exporter, or nullptr if not set

◆ get_trace()

common::Result< std::vector< trace_span > > kcenon::monitoring::distributed_tracer::get_trace ( const std::string & trace_id) const

Get all spans for a trace.

Examples
distributed_tracing_example.cpp.

Referenced by analyze_traces().

Here is the caller graph for this function:

◆ inject_context()

template<typename Carrier >
void kcenon::monitoring::distributed_tracer::inject_context ( const trace_context & context,
Carrier & carrier )
inline

Inject trace context into carrier (e.g., HTTP headers)

Examples
distributed_tracing_example.cpp.

Definition at line 260 of file distributed_tracer.h.

260 {
261 carrier["traceparent"] = context.to_w3c_traceparent();
262 if (!context.trace_state.empty()) {
263 carrier["tracestate"] = context.trace_state;
264 }
265 // Inject baggage
266 for (const auto& [key, value] : context.baggage) {
267 carrier["baggage-" + key] = value;
268 }
269 }

References kcenon::monitoring::trace_context::to_w3c_traceparent().

Referenced by WebService::call_downstream_service(), and main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ operator=() [1/2]

distributed_tracer & kcenon::monitoring::distributed_tracer::operator= ( const distributed_tracer & )
delete

◆ operator=() [2/2]

distributed_tracer & kcenon::monitoring::distributed_tracer::operator= ( distributed_tracer && )
noexcept

◆ set_current_span()

void kcenon::monitoring::distributed_tracer::set_current_span ( std::shared_ptr< trace_span > span)

Set current active span for this thread.

Referenced by kcenon::monitoring::scoped_span::scoped_span().

Here is the caller graph for this function:

◆ set_exporter()

void kcenon::monitoring::distributed_tracer::set_exporter ( std::shared_ptr< trace_exporter_interface > exporter)

Set the trace exporter for span export.

Parameters
exporterShared pointer to trace exporter implementation

Referenced by ExporterIntegrationTest::TearDown().

Here is the caller graph for this function:

◆ start_child_span()

common::Result< std::shared_ptr< trace_span > > kcenon::monitoring::distributed_tracer::start_child_span ( const trace_span & parent,
const std::string & operation_name )

◆ start_span()

common::Result< std::shared_ptr< trace_span > > kcenon::monitoring::distributed_tracer::start_span ( const std::string & operation_name,
const std::string & service_name = "monitoring_system" )

Start a new root span.

Examples
distributed_tracing_example.cpp.

Referenced by analyze_traces(), WebService::handle_request(), main(), TEST_F(), TEST_F(), and TEST_F().

Here is the caller graph for this function:

◆ start_span_from_context()

common::Result< std::shared_ptr< trace_span > > kcenon::monitoring::distributed_tracer::start_span_from_context ( const trace_context & context,
const std::string & operation_name )

Start a span from trace context (for incoming requests)

Examples
distributed_tracing_example.cpp.

Referenced by WebService::handle_request(), and main().

Here is the caller graph for this function:

Member Data Documentation

◆ impl_

std::unique_ptr<tracer_impl> kcenon::monitoring::distributed_tracer::impl_
private

Definition at line 198 of file distributed_tracer.h.


The documentation for this class was generated from the following file: