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

Thread-local context management for request tracking. More...

#include <thread_context.h>

Collaboration diagram for kcenon::monitoring::thread_context:
Collaboration graph

Static Public Member Functions

static thread_context_datacreate (const std::string &request_id="")
 Create a new thread-local context, replacing any existing one.
 
static thread_context_datacurrent ()
 Get the current thread-local context.
 
static bool has_context ()
 Check whether a context exists on the current thread.
 
static void clear ()
 Clear and destroy the current thread-local context.
 
static std::string generate_request_id ()
 Generate a unique request ID.
 
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 Private Attributes

static thread_local std::unique_ptr< thread_context_datacurrent_context_
 

Detailed Description

Thread-local context management for request tracking.

Manages a thread_context_data instance in thread-local storage. Each thread has its own independent context, so no locking is required. Use create() to initialize a context at the start of request processing, and clear() to release it when done.

// At request entry point
auto& ctx = thread_context::create();
// In downstream code
auto* ctx = thread_context::current();
// use ctx->request_id, ctx->tags, etc.
}
// At request exit
static std::string generate_correlation_id()
Generate a unique correlation ID.
static void clear()
Clear and destroy the current thread-local context.
static thread_context_data * current()
Get the current thread-local context.
static thread_context_data & create(const std::string &request_id="")
Create a new thread-local context, replacing any existing one.
static bool has_context()
Check whether a context exists on the current thread.
See also
thread_context_data For the stored context data structure

Definition at line 175 of file thread_context.h.

Member Function Documentation

◆ clear()

static void kcenon::monitoring::thread_context::clear ( )
static

Clear and destroy the current thread-local context.

Referenced by ThreadContextTest::SetUp(), ThreadContextTest::TearDown(), TEST_F(), and TEST_F().

Here is the caller graph for this function:

◆ copy_from()

static bool kcenon::monitoring::thread_context::copy_from ( const thread_context_data & source)
static

Copy context data from another source into the current thread.

Parameters
sourceThe context data to copy from
Returns
true if the copy succeeded, false on failure

Referenced by TEST_F().

Here is the caller graph for this function:

◆ create()

static thread_context_data & kcenon::monitoring::thread_context::create ( const std::string & request_id = "")
static

Create a new thread-local context, replacing any existing one.

Parameters
request_idOptional request identifier. If empty, one can be assigned later or generated via generate_request_id().
Returns
Reference to the newly created thread-local context data

Referenced by TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), and TEST_F().

Here is the caller graph for this function:

◆ current()

static thread_context_data * kcenon::monitoring::thread_context::current ( )
static

Get the current thread-local context.

Returns
Pointer to the current context, or nullptr if no context exists

Referenced by TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), and TEST_F().

Here is the caller graph for this function:

◆ generate_correlation_id()

static std::string kcenon::monitoring::thread_context::generate_correlation_id ( )
static

Generate a unique correlation ID.

Returns
A new UUID-style correlation identifier string

Referenced by kcenon::monitoring::span_builder::build(), and TEST_F().

Here is the caller graph for this function:

◆ generate_request_id()

static std::string kcenon::monitoring::thread_context::generate_request_id ( )
static

Generate a unique request ID.

Returns
A new UUID-style request identifier string

Referenced by kcenon::monitoring::span_builder::build(), and TEST_F().

Here is the caller graph for this function:

◆ has_context()

static bool kcenon::monitoring::thread_context::has_context ( )
static

Check whether a context exists on the current thread.

Returns
true if a context has been created and not yet cleared

Referenced by TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), and TEST_F().

Here is the caller graph for this function:

Member Data Documentation

◆ current_context_

thread_local std::unique_ptr<thread_context_data> kcenon::monitoring::thread_context::current_context_
staticprivate

Definition at line 222 of file thread_context.h.


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