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

Simulated API Gateway service. More...

Collaboration diagram for ApiGatewayService:
Collaboration graph

Public Member Functions

trace_span handle_request (const std::string &endpoint, const std::string &method)
 Handle incoming HTTP request.
 
trace_context create_context (const trace_span &span)
 Create trace context for propagation.
 

Static Private Member Functions

static std::string generate_trace_id ()
 
static std::string generate_span_id ()
 

Private Attributes

std::string service_name_ = "api_gateway"
 

Detailed Description

Simulated API Gateway service.

Examples
multi_service_tracing_example.cpp.

Definition at line 40 of file multi_service_tracing_example.cpp.

Member Function Documentation

◆ create_context()

trace_context ApiGatewayService::create_context ( const trace_span & span)
inline

Create trace context for propagation.

Examples
multi_service_tracing_example.cpp.

Definition at line 80 of file multi_service_tracing_example.cpp.

80 {
81 trace_context ctx;
82 ctx.trace_id = span.trace_id;
83 ctx.span_id = span.span_id;
84 ctx.trace_flags = "01"; // Sampled
85 ctx.baggage = span.baggage;
86
87 std::cout << " → Context for propagation: "
88 << ctx.to_w3c_traceparent() << std::endl;
89
90 return ctx;
91 }
Trace context for propagation across service boundaries.
std::string to_w3c_traceparent() const
Serialize to W3C Trace Context format.
std::unordered_map< std::string, std::string > baggage
std::unordered_map< std::string, std::string > baggage

References kcenon::monitoring::trace_context::baggage, kcenon::monitoring::trace_span::baggage, kcenon::monitoring::trace_context::span_id, kcenon::monitoring::trace_span::span_id, kcenon::monitoring::trace_context::to_w3c_traceparent(), kcenon::monitoring::trace_context::trace_flags, 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:

◆ generate_span_id()

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

Definition at line 103 of file multi_service_tracing_example.cpp.

103 {
104 // Generate 16-character hex string (8 bytes)
105 std::string id;
106 for (int i = 0; i < 16; ++i) {
107 id += "0123456789abcdef"[rand() % 16];
108 }
109 return id;
110 }

Referenced by handle_request().

Here is the caller graph for this function:

◆ generate_trace_id()

static std::string ApiGatewayService::generate_trace_id ( )
inlinestaticprivate
Examples
multi_service_tracing_example.cpp.

Definition at line 94 of file multi_service_tracing_example.cpp.

94 {
95 // Generate 32-character hex string (16 bytes)
96 std::string id;
97 for (int i = 0; i < 32; ++i) {
98 id += "0123456789abcdef"[rand() % 16];
99 }
100 return id;
101 }

Referenced by handle_request().

Here is the caller graph for this function:

◆ handle_request()

trace_span ApiGatewayService::handle_request ( const std::string & endpoint,
const std::string & method )
inline

Handle incoming HTTP request.

Examples
multi_service_tracing_example.cpp.

Definition at line 48 of file multi_service_tracing_example.cpp.

48 {
49 std::cout << "\n[" << service_name_ << "] Processing " << method << " " << endpoint << std::endl;
50
51 // Create root span for this request
52 trace_span span;
55 span.operation_name = "http_request";
57 span.start_time = std::chrono::system_clock::now();
58
59 // Add HTTP-specific tags
60 span.tags["http.method"] = method;
61 span.tags["http.url"] = endpoint;
62 span.tags["http.target"] = endpoint;
63 span.tags["component"] = "http_server";
64
65 // Add baggage for cross-cutting concerns
66 span.baggage["user.id"] = "user-12345";
67 span.baggage["session.id"] = "sess-67890";
68 span.baggage["request.priority"] = "high";
69
70 std::cout << " → Created root span: " << span.span_id << std::endl;
71 std::cout << " Trace ID: " << span.trace_id << std::endl;
72 std::cout << " Baggage: user.id=" << span.baggage["user.id"] << std::endl;
73
74 return span;
75 }
static std::string generate_trace_id()
static std::string generate_span_id()
Trace span representing a unit of work in distributed tracing.
std::unordered_map< std::string, std::string > tags
std::chrono::system_clock::time_point start_time

References kcenon::monitoring::trace_span::baggage, generate_span_id(), generate_trace_id(), kcenon::monitoring::trace_span::operation_name, kcenon::monitoring::trace_span::service_name, service_name_, kcenon::monitoring::trace_span::span_id, kcenon::monitoring::trace_span::start_time, kcenon::monitoring::trace_span::tags, 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 ApiGatewayService::service_name_ = "api_gateway"
private
Examples
multi_service_tracing_example.cpp.

Definition at line 42 of file multi_service_tracing_example.cpp.

Referenced by handle_request().


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