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

Trace context for propagation across service boundaries. More...

#include <distributed_tracer.h>

Collaboration diagram for kcenon::monitoring::trace_context:
Collaboration graph

Public Member Functions

std::string to_w3c_traceparent () const
 Serialize to W3C Trace Context format.
 

Static Public Member Functions

static common::Result< trace_contextfrom_w3c_traceparent (const std::string &header)
 Parse from W3C Trace Context format.
 

Public Attributes

std::string trace_id
 
std::string span_id
 
std::string trace_flags
 
std::string trace_state
 
std::unordered_map< std::string, std::string > baggage
 

Detailed Description

Trace context for propagation across service boundaries.

Examples
multi_service_tracing_example.cpp.

Definition at line 95 of file distributed_tracer.h.

Member Function Documentation

◆ from_w3c_traceparent()

static common::Result< trace_context > kcenon::monitoring::trace_context::from_w3c_traceparent ( const std::string & header)
inlinestatic

Parse from W3C Trace Context format.

Definition at line 113 of file distributed_tracer.h.

113 {
114 // Parse format: version-traceid-spanid-traceflags
115 if (header.length() < 55) { // Minimum valid length
117 "Invalid traceparent header length");
118 return common::Result<trace_context>::err(err.to_common_error());
119 }
120
121 trace_context ctx;
122 // Simple parsing - production code would be more robust
123 size_t pos = 0;
124 size_t dash1 = header.find('-', pos);
125 size_t dash2 = header.find('-', dash1 + 1);
126 size_t dash3 = header.find('-', dash2 + 1);
127
128 if (dash1 == std::string::npos || dash2 == std::string::npos || dash3 == std::string::npos) {
130 "Invalid traceparent header format");
131 return common::Result<trace_context>::err(err.to_common_error());
132 }
133
134 ctx.trace_id = header.substr(dash1 + 1, dash2 - dash1 - 1);
135 ctx.span_id = header.substr(dash2 + 1, dash3 - dash2 - 1);
136 ctx.trace_flags = header.substr(dash3 + 1);
137
138 return common::ok(ctx);
139 }

References kcenon::monitoring::invalid_argument, span_id, kcenon::monitoring::error_info::to_common_error(), trace_flags, and trace_id.

Referenced by kcenon::monitoring::distributed_tracer::extract_context_from_carrier(), and TEST_F().

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

◆ to_w3c_traceparent()

std::string kcenon::monitoring::trace_context::to_w3c_traceparent ( ) const
inline

Serialize to W3C Trace Context format.

Examples
multi_service_tracing_example.cpp.

Definition at line 105 of file distributed_tracer.h.

105 {
106 // Version-TraceId-SpanId-TraceFlags
107 return "00-" + trace_id + "-" + span_id + "-" + trace_flags;
108 }

References span_id, trace_flags, and trace_id.

Referenced by ApiGatewayService::create_context(), kcenon::monitoring::distributed_tracer::inject_context(), TEST_F(), and AuthService::verify_token().

Here is the caller graph for this function:

Member Data Documentation

◆ baggage

std::unordered_map<std::string, std::string> kcenon::monitoring::trace_context::baggage

◆ span_id

◆ trace_flags

std::string kcenon::monitoring::trace_context::trace_flags

◆ trace_id

◆ trace_state

std::string kcenon::monitoring::trace_context::trace_state

Definition at line 99 of file distributed_tracer.h.


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