Skip to content

correlation

Correlation enhancement features for structured logging

Enhanced trace context with additional correlation capabilities

Fields

FieldTypeDescription
basedomain::TraceContextBase trace context from observability_core
baggageHashMap<String, String>W3C baggage for cross-cutting concerns
scoped_contextsVec<ScopedContext>Scoped context stack for nested operations
correlation_metadataHashMap<String, serde_json::Value>Correlation metadata

Methods

fn new(base: TraceContext) -> Self

Create new enhanced trace context

fn from_w3c_headers(trace_parent: &str, _trace_state: Option<&str>) -> Result<Self>

Create from W3C trace headers

fn add_baggage(&mut self, key: String, value: String) -> Result<()>

Add baggage item

fn get_baggage(&self, key: &str) -> Option<&String>

Get baggage item

fn remove_baggage(&mut self, key: &str) -> Option<String>

Remove baggage item

fn push_scope(&mut self, scope_name: String, metadata: HashMap<String, Value>) -> Result<String>

Push new scoped context

fn pop_scope(&mut self) -> Option<ScopedContext>

Pop current scoped context

fn current_scope(&self) -> Option<&ScopedContext>

Get current scope

fn add_correlation_metadata(&mut self, key: String, value: Value)

Add correlation metadata

fn get_correlation_metadata(&self) -> &HashMap<String, Value>

Get correlation metadata

fn to_baggage_header(&self) -> String

Convert to W3C baggage header format

fn from_baggage_header(&mut self, baggage_header: &str) -> Result<()>

Parse from W3C baggage header

Scoped context for nested operations

Fields

FieldTypeDescription
scope_idStringUnique identifier for this scope
scope_nameStringScope name (e.g., “llm_request”, “template_render”)
start_timeStringWhen this scope started (as timestamp string for WASM compatibility)
parent_scope_idOption&lt;String&gt;Parent scope ID (if nested)
metadataHashMap&lt;String, serde_json::Value&gt;Scope-specific metadata

W3C baggage support manager

Methods

fn new(config: CorrelationConfig) -> Self
fn validate_baggage_item(&self, key: &str, value: &str) -> Result<()>

Validate baggage item

fn add_system_baggage(&self, ctx: &mut EnhancedTraceContext, operation: &str) -> Result<()>

Add system baggage for agent operations

Scoped context manager for nested operations

Methods

fn new(config: CorrelationConfig) -> Self
fn enter_scope(&self, trace_id: &str, scope_name: String, metadata: HashMap<String, Value>) -> Result<String>

Enter a new scope

fn exit_scope(&self, trace_id: &str) -> Result<Option<ScopedContext>>

Exit current scope

fn current_scope(&self, trace_id: &str) -> Result<Option<ScopedContext>>

Get current scope

fn register_context(&self, ctx: EnhancedTraceContext) -> Result<()>

Register new trace context

fn unregister_context(&self, trace_id: &str) -> Result<()>

Unregister trace context

W3C baggage support utilities

Methods

fn extract_from_headers(headers: &HashMap<String, String>) -> Result<HashMap<String, String>>

Extract baggage from HTTP headers

fn inject_into_headers(baggage: &HashMap<String, String>, headers: &mut HashMap<String, String>)

Inject baggage into HTTP headers

Correlation processor for log entries

Methods

fn new(config: CorrelationConfig) -> Self
fn process_entry(&self, entry: LogEntry) -> Result<LogEntry>

Process log entry to add correlation information

Correlation manager that coordinates all correlation features

Methods

fn new(config: &CorrelationConfig) -> Result<Self>
fn process_entry(&self, entry: LogEntry) -> Result<LogEntry>
fn baggage_manager(&self) -> &BaggageManager
fn scoped_context_manager(&self) -> &ScopedContextManager