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

Simulated Authentication service. More...

Collaboration diagram for AuthService:
Collaboration graph

Public Member Functions

trace_span verify_token (const trace_context &parent_ctx, const std::string &)
 Verify user authentication.
 

Static Private Member Functions

static std::string generate_span_id ()
 

Private Attributes

std::string service_name_ = "auth_service"
 

Detailed Description

Simulated Authentication service.

Examples
multi_service_tracing_example.cpp.

Definition at line 116 of file multi_service_tracing_example.cpp.

Member Function Documentation

◆ generate_span_id()

static std::string AuthService::generate_span_id ( )
inlinestaticprivate
Examples
multi_service_tracing_example.cpp.

Definition at line 163 of file multi_service_tracing_example.cpp.

163 {
164 std::string id;
165 for (int i = 0; i < 16; ++i) {
166 id += "0123456789abcdef"[rand() % 16];
167 }
168 return id;
169 }

Referenced by verify_token().

Here is the caller graph for this function:

◆ verify_token()

trace_span AuthService::verify_token ( const trace_context & parent_ctx,
const std::string &  )
inline

Verify user authentication.

Examples
multi_service_tracing_example.cpp.

Definition at line 124 of file multi_service_tracing_example.cpp.

124 {
125 std::cout << "\n[" << service_name_ << "] Verifying authentication token" << std::endl;
126 std::cout << " Received context: " << parent_ctx.to_w3c_traceparent() << std::endl;
127
128 // Create child span
129 trace_span span;
130 span.trace_id = parent_ctx.trace_id; // Same trace ID
131 span.span_id = generate_span_id(); // New span ID
132 span.parent_span_id = parent_ctx.span_id; // Link to parent
133 span.operation_name = "verify_token";
135 span.start_time = std::chrono::system_clock::now();
136
137 // Inherit baggage from parent
138 span.baggage = parent_ctx.baggage;
139
140 // Add service-specific tags
141 span.tags["auth.token_type"] = "bearer";
142 span.tags["auth.method"] = "jwt";
143
144 std::cout << " → Created child span: " << span.span_id << std::endl;
145 std::cout << " Parent span: " << span.parent_span_id << std::endl;
146 std::cout << " Inherited baggage: user.id=" << span.baggage["user.id"] << std::endl;
147
148 // Simulate authentication work
149 std::this_thread::sleep_for(5ms);
150
151 span.end_time = std::chrono::system_clock::now();
152 span.calculate_duration();
153 span.status = trace_span::status_code::ok;
154 span.tags["auth.result"] = "success";
155
156 std::cout << " ✓ Authentication successful (duration: "
157 << span.duration.count() << "µs)" << std::endl;
158
159 return span;
160 }
static std::string generate_span_id()
std::string to_w3c_traceparent() const
Serialize to W3C Trace Context format.
std::unordered_map< std::string, std::string > baggage
Trace span representing a unit of work in distributed tracing.
void calculate_duration()
Calculate duration if span is finished.
std::unordered_map< std::string, std::string > tags
std::unordered_map< std::string, std::string > baggage
std::chrono::system_clock::time_point end_time
std::chrono::microseconds duration
std::chrono::system_clock::time_point start_time

References kcenon::monitoring::trace_context::baggage, kcenon::monitoring::trace_span::baggage, kcenon::monitoring::trace_span::calculate_duration(), kcenon::monitoring::trace_span::duration, kcenon::monitoring::trace_span::end_time, generate_span_id(), kcenon::monitoring::trace_span::operation_name, kcenon::monitoring::trace_span::parent_span_id, kcenon::monitoring::trace_span::service_name, service_name_, kcenon::monitoring::trace_context::span_id, kcenon::monitoring::trace_span::span_id, kcenon::monitoring::trace_span::start_time, kcenon::monitoring::trace_span::status, kcenon::monitoring::trace_span::tags, kcenon::monitoring::trace_context::to_w3c_traceparent(), kcenon::monitoring::trace_context::trace_id, and kcenon::monitoring::trace_span::trace_id.

Referenced by simulate_multi_service_request().

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

Member Data Documentation

◆ service_name_

std::string AuthService::service_name_ = "auth_service"
private
Examples
multi_service_tracing_example.cpp.

Definition at line 118 of file multi_service_tracing_example.cpp.

Referenced by verify_token().


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