45#include <unordered_map>
48namespace kcenon {
namespace monitoring {
61 std::unordered_map<std::string, std::string>
tags;
83 void set_tag(
const std::string& key,
const std::string& value) {
92 std::string
get_tag(
const std::string& key)
const {
93 auto it =
tags.find(key);
94 return it !=
tags.end() ? it->second :
"";
115 std::unordered_map<std::string, std::string>
tags;
128 ,
start_time(std::chrono::steady_clock::now()) {}
135 void add_tag(
const std::string& key,
const std::string& value) {
144 std::string
get_tag(
const std::string& key)
const {
145 auto it =
tags.find(key);
146 return it !=
tags.end() ? it->second :
"";
Thread-local context management for request tracking.
static std::string generate_correlation_id()
Generate a unique correlation ID.
static bool copy_from(const thread_context_data &source)
Copy context data from another source into the current thread.
static void clear()
Clear and destroy the current thread-local context.
static thread_context_data * current()
Get the current thread-local context.
static thread_local std::unique_ptr< thread_context_data > current_context_
static thread_context_data & create(const std::string &request_id="")
Create a new thread-local context, replacing any existing one.
static std::string generate_request_id()
Generate a unique request ID.
static bool has_context()
Check whether a context exists on the current thread.
Context metadata for thread-specific information.
std::string correlation_id
Correlation ID for tracing across services.
std::unordered_map< std::string, std::string > tags
Arbitrary key-value tags.
std::string request_id
Unique identifier for the current request.
context_metadata(std::string req_id="")
Construct context metadata with an optional request ID.
std::string user_id
User identifier associated with the request.
std::string get_tag(const std::string &key) const
Retrieve a tag value by key.
void set_tag(const std::string &key, const std::string &value)
Set a custom tag on this context.
bool empty() const
Check if all metadata fields are empty.
Enhanced thread context data for comprehensive request and trace tracking.
thread_context_data(std::string req_id)
Construct with a request ID. Records the current time as start_time.
std::chrono::steady_clock::time_point start_time
Context creation timestamp.
std::string span_id
Current span ID for distributed tracing.
void add_tag(const std::string &key, const std::string &value)
Add or update a custom tag.
std::string request_id
Unique identifier for the current request.
std::string correlation_id
Correlation ID for cross-service tracing.
std::string get_tag(const std::string &key) const
Retrieve a tag value by key.
std::string trace_id
Trace ID linking all spans in a trace.
std::unordered_map< std::string, std::string > tags
Arbitrary key-value tags.
thread_context_data()
Default constructor. Records the current time as start_time.
std::optional< std::string > parent_span_id
Parent span ID (if nested)
std::string user_id
User identifier associated with the request.