Monitoring System 0.1.0
System resource monitoring with pluggable collectors and alerting
Loading...
Searching...
No Matches
thread_context.h File Reference

Thread-local context management for request tracking and distributed tracing. More...

#include <string>
#include <chrono>
#include <optional>
#include <unordered_map>
#include <memory>
Include dependency graph for thread_context.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  kcenon::monitoring::context_metadata
 Context metadata for thread-specific information. More...
 
struct  kcenon::monitoring::thread_context_data
 Enhanced thread context data for comprehensive request and trace tracking. More...
 
class  kcenon::monitoring::thread_context
 Thread-local context management for request tracking. More...
 

Namespaces

namespace  kcenon
 
namespace  kcenon::monitoring
 

Detailed Description

Thread-local context management for request tracking and distributed tracing.

Provides thread-local storage for request metadata (request IDs, correlation IDs, trace/span IDs) enabling distributed tracing and per-request diagnostics across the monitoring system.

Uses thread_context as the primary API with pointer-based thread-local storage.

Thread Safety

Each thread has its own independent context via thread_local storage. No cross-thread synchronization is needed for context operations.

// Set up context for an incoming request
auto& ctx = thread_context::create("req-12345");
ctx.correlation_id = "corr-67890";
ctx.add_tag("service", "monitoring");
// Later, retrieve the context
if (auto* ctx = thread_context::current()) {
log("Processing request: " + ctx->request_id);
}
// Clean up when done
thread_context::clear();
Author
kcenon
Since
1.0.0
See also
distributed_tracer For span-level tracing integration
performance_monitor For metrics correlated with request contexts

Definition in file thread_context.h.