Logger System 0.1.3
High-performance C++20 thread-safe logging system with asynchronous capabilities
Loading...
Searching...
No Matches
kcenon::logger::otlp::otel_context_storage Class Reference

Thread-local storage for OpenTelemetry context. More...

#include <otel_context.h>

Collaboration diagram for kcenon::logger::otlp::otel_context_storage:
Collaboration graph

Static Public Member Functions

static void set (const otel_context &ctx)
 Set the OpenTelemetry context for the current thread.
 
static std::optional< otel_contextget ()
 Get the OpenTelemetry context for the current thread.
 
static void clear ()
 Clear the OpenTelemetry context for the current thread.
 
static bool has_context ()
 Check if a context is set for the current thread.
 

Static Private Member Functions

static otel_contextget_storage ()
 
static bool & get_has_context ()
 

Detailed Description

Thread-local storage for OpenTelemetry context.

Provides thread-safe storage and retrieval of OpenTelemetry context using thread-local storage. This allows automatic context propagation within a thread.

Definition at line 215 of file otel_context.h.

Member Function Documentation

◆ clear()

static void kcenon::logger::otlp::otel_context_storage::clear ( )
inlinestatic

Clear the OpenTelemetry context for the current thread.

Examples
/home/runner/work/logger_system/logger_system/include/kcenon/logger/otlp/otel_context.h.

Definition at line 242 of file otel_context.h.

242 {
243 get_storage() = otel_context{};
244 get_has_context() = false;
245 }

References get_has_context(), and get_storage().

Referenced by kcenon::logger::otlp::otel_context_scope::~otel_context_scope().

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

◆ get()

static std::optional< otel_context > kcenon::logger::otlp::otel_context_storage::get ( )
inlinestaticnodiscard

Get the OpenTelemetry context for the current thread.

Returns
Optional context, empty if not set
Examples
/home/runner/work/logger_system/logger_system/include/kcenon/logger/otlp/otel_context.h.

Definition at line 232 of file otel_context.h.

232 {
233 if (get_has_context()) {
234 return get_storage();
235 }
236 return std::nullopt;
237 }

References get_has_context(), and get_storage().

Referenced by kcenon::logger::otlp_writer::write().

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

◆ get_has_context()

static bool & kcenon::logger::otlp::otel_context_storage::get_has_context ( )
inlinestaticprivate
Examples
/home/runner/work/logger_system/logger_system/include/kcenon/logger/otlp/otel_context.h.

Definition at line 262 of file otel_context.h.

262 {
263 thread_local bool has_ctx = false;
264 return has_ctx;
265 }

Referenced by clear(), get(), has_context(), and set().

Here is the caller graph for this function:

◆ get_storage()

static otel_context & kcenon::logger::otlp::otel_context_storage::get_storage ( )
inlinestaticprivate
Examples
/home/runner/work/logger_system/logger_system/include/kcenon/logger/otlp/otel_context.h.

Definition at line 257 of file otel_context.h.

257 {
258 thread_local otel_context storage;
259 return storage;
260 }

Referenced by clear(), get(), and set().

Here is the caller graph for this function:

◆ has_context()

static bool kcenon::logger::otlp::otel_context_storage::has_context ( )
inlinestaticnodiscard

Check if a context is set for the current thread.

Returns
true if context is set
Examples
/home/runner/work/logger_system/logger_system/include/kcenon/logger/otlp/otel_context.h.

Definition at line 252 of file otel_context.h.

252 {
253 return get_has_context();
254 }

References get_has_context().

Here is the call graph for this function:

◆ set()

static void kcenon::logger::otlp::otel_context_storage::set ( const otel_context & ctx)
inlinestatic

Set the OpenTelemetry context for the current thread.

Parameters
ctxContext to set
Examples
/home/runner/work/logger_system/logger_system/include/kcenon/logger/otlp/otel_context.h.

Definition at line 222 of file otel_context.h.

222 {
223 get_storage() = ctx;
224 get_has_context() = true;
225 }

References get_has_context(), and get_storage().

Referenced by kcenon::logger::otlp::otel_context_scope::otel_context_scope(), and kcenon::logger::otlp::otel_context_scope::~otel_context_scope().

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

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