correlation
Correlation enhancement features for structured logging
Structs
Section titled “Structs”EnhancedTraceContext
Section titled “EnhancedTraceContext”Enhanced trace context with additional correlation capabilities
Fields
| Field | Type | Description |
|---|---|---|
base | domain::TraceContext | Base trace context from observability_core |
baggage | HashMap<String, String> | W3C baggage for cross-cutting concerns |
scoped_contexts | Vec<ScopedContext> | Scoped context stack for nested operations |
correlation_metadata | HashMap<String, serde_json::Value> | Correlation metadata |
Methods
fn new(base: TraceContext) -> SelfCreate new enhanced trace context
from_w3c_headers
Section titled “from_w3c_headers”fn from_w3c_headers(trace_parent: &str, _trace_state: Option<&str>) -> Result<Self>Create from W3C trace headers
add_baggage
Section titled “add_baggage”fn add_baggage(&mut self, key: String, value: String) -> Result<()>Add baggage item
get_baggage
Section titled “get_baggage”fn get_baggage(&self, key: &str) -> Option<&String>Get baggage item
remove_baggage
Section titled “remove_baggage”fn remove_baggage(&mut self, key: &str) -> Option<String>Remove baggage item
push_scope
Section titled “push_scope”fn push_scope(&mut self, scope_name: String, metadata: HashMap<String, Value>) -> Result<String>Push new scoped context
pop_scope
Section titled “pop_scope”fn pop_scope(&mut self) -> Option<ScopedContext>Pop current scoped context
current_scope
Section titled “current_scope”fn current_scope(&self) -> Option<&ScopedContext>Get current scope
add_correlation_metadata
Section titled “add_correlation_metadata”fn add_correlation_metadata(&mut self, key: String, value: Value)Add correlation metadata
get_correlation_metadata
Section titled “get_correlation_metadata”fn get_correlation_metadata(&self) -> &HashMap<String, Value>Get correlation metadata
to_baggage_header
Section titled “to_baggage_header”fn to_baggage_header(&self) -> StringConvert to W3C baggage header format
from_baggage_header
Section titled “from_baggage_header”fn from_baggage_header(&mut self, baggage_header: &str) -> Result<()>Parse from W3C baggage header
ScopedContext
Section titled “ScopedContext”Scoped context for nested operations
Fields
| Field | Type | Description |
|---|---|---|
scope_id | String | Unique identifier for this scope |
scope_name | String | Scope name (e.g., “llm_request”, “template_render”) |
start_time | String | When this scope started (as timestamp string for WASM compatibility) |
parent_scope_id | Option<String> | Parent scope ID (if nested) |
metadata | HashMap<String, serde_json::Value> | Scope-specific metadata |
BaggageManager
Section titled “BaggageManager”W3C baggage support manager
Methods
fn new(config: CorrelationConfig) -> Selfvalidate_baggage_item
Section titled “validate_baggage_item”fn validate_baggage_item(&self, key: &str, value: &str) -> Result<()>Validate baggage item
add_system_baggage
Section titled “add_system_baggage”fn add_system_baggage(&self, ctx: &mut EnhancedTraceContext, operation: &str) -> Result<()>Add system baggage for agent operations
ScopedContextManager
Section titled “ScopedContextManager”Scoped context manager for nested operations
Methods
fn new(config: CorrelationConfig) -> Selfenter_scope
Section titled “enter_scope”fn enter_scope(&self, trace_id: &str, scope_name: String, metadata: HashMap<String, Value>) -> Result<String>Enter a new scope
exit_scope
Section titled “exit_scope”fn exit_scope(&self, trace_id: &str) -> Result<Option<ScopedContext>>Exit current scope
current_scope
Section titled “current_scope”fn current_scope(&self, trace_id: &str) -> Result<Option<ScopedContext>>Get current scope
register_context
Section titled “register_context”fn register_context(&self, ctx: EnhancedTraceContext) -> Result<()>Register new trace context
unregister_context
Section titled “unregister_context”fn unregister_context(&self, trace_id: &str) -> Result<()>Unregister trace context
W3CBaggageSupport
Section titled “W3CBaggageSupport”W3C baggage support utilities
Methods
extract_from_headers
Section titled “extract_from_headers”fn extract_from_headers(headers: &HashMap<String, String>) -> Result<HashMap<String, String>>Extract baggage from HTTP headers
inject_into_headers
Section titled “inject_into_headers”fn inject_into_headers(baggage: &HashMap<String, String>, headers: &mut HashMap<String, String>)Inject baggage into HTTP headers
CorrelationProcessor
Section titled “CorrelationProcessor”Correlation processor for log entries
Methods
fn new(config: CorrelationConfig) -> Selfprocess_entry
Section titled “process_entry”fn process_entry(&self, entry: LogEntry) -> Result<LogEntry>Process log entry to add correlation information
CorrelationManager
Section titled “CorrelationManager”Correlation manager that coordinates all correlation features
Methods
fn new(config: &CorrelationConfig) -> Result<Self>process_entry
Section titled “process_entry”fn process_entry(&self, entry: LogEntry) -> Result<LogEntry>baggage_manager
Section titled “baggage_manager”fn baggage_manager(&self) -> &BaggageManagerscoped_context_manager
Section titled “scoped_context_manager”fn scoped_context_manager(&self) -> &ScopedContextManager