Skip to main content

Crate structured_logging

Crate structured_logging 

Source
Expand description

§Enhanced Structured Logging for SpinKube Agents

This crate provides performance optimizations and convenience APIs on top of the excellent observability_core hexagonal architecture. It focuses on:

  • 🚀 Performance: String interning, buffer pooling, zero-allocation fast paths
  • 🔗 Correlation: Enhanced W3C baggage, scoped contexts, advanced tracing
  • 🎪 Convenience: Domain-specific APIs for LLM, template, and A2A operations

§Architecture

This crate builds on observability_core’s solid foundation:

  • Domain: Reuses LogEntry, ProcessorChain, TraceContext
  • Ports: Extends TransportPort, FormatterPort interfaces
  • Adapters: Enhances with performance-optimized implementations
  • Extension: Provides enhanced configuration and management

§Usage Tiers

§Tier 1: Standard (90% of users)

ⓘ
// Just use observability_core - works perfectly
use observability_core::ObservabilityManager;
log::info!("Standard structured logging");

§Tier 2: Enhanced (8% of users)

ⓘ
// Add convenience methods
use structured_logging::convenience::*;
log_llm_request("gpt-4", duration, tokens, "success")?;

§Tier 3: Performance (2% of users)

ⓘ
// Full performance optimization
use structured_logging::{EnhancedObservabilityConfig, PerformanceExtension};

Re-exports§

pub use extension::EnhancedObservabilityConfig;
pub use extension::PerformanceExtension;
pub use extension::create_performance_extension;
pub use extension::create_performance_extension_from_config;
pub use panic_handler::PanicHandlerConfig;
pub use panic_handler::PanicPattern;
pub use panic_handler::PanicSeverity;
pub use panic_handler::PanicStats;
pub use panic_handler::StructuredPanicInfo;
pub use panic_handler::ThreadInfo;
pub use panic_handler::get_panic_stats;
pub use panic_handler::install_panic_handler;
pub use panic_handler::install_panic_handler_with_config;
pub use panic_handler::reset_panic_stats;
pub use convenience::A2AContext;
pub use convenience::ConvenienceManager;
pub use convenience::DomainContextProcessor;
pub use convenience::LLMContext;
pub use convenience::TemplateContext;
pub use convenience::clear_a2a_context;
pub use convenience::clear_all_contexts;
pub use convenience::clear_llm_context;
pub use convenience::clear_request_context;
pub use convenience::clear_template_context;
pub use convenience::emit_a2a_message_latency;
pub use convenience::emit_counter;
pub use convenience::emit_histogram;
pub use convenience::emit_llm_request_duration;
pub use convenience::emit_llm_tokens_used;
pub use convenience::emit_request_duration;
pub use convenience::emit_template_render_duration;
pub use convenience::log_a2a_message;
pub use convenience::log_llm_request;
pub use convenience::log_template_render;
pub use convenience::set_a2a_context;
pub use convenience::set_llm_context;
pub use convenience::set_request_context;
pub use convenience::set_template_context;
pub use context_adapter::A2aContextGuard;
pub use context_adapter::A2aContextManager;
pub use context_adapter::AllContextsGuard;
pub use context_adapter::ContextManagerRegistry;
pub use context_adapter::LlmContextGuard;
pub use context_adapter::LlmContextManager;
pub use context_adapter::RequestContextGuard;
pub use context_adapter::RequestContextManager;
pub use context_adapter::ScopedContextBuilder;
pub use context_adapter::StructuredA2aContextManager;
pub use context_adapter::StructuredContextRegistry;
pub use context_adapter::StructuredLlmContextManager;
pub use context_adapter::StructuredRequestContextManager;
pub use context_adapter::init_context_integration;
pub use context_adapter::set_a2a_context_scoped;
pub use context_adapter::set_all_contexts_scoped;
pub use context_adapter::set_llm_context_scoped;
pub use context_adapter::set_request_context_scoped;
pub use context_adapter::with_a2a_context;
pub use context_adapter::with_all_contexts;
pub use context_adapter::with_llm_context;
pub use context_adapter::with_request_context;
pub use extension::ConvenienceConfig;

Modules§

context_adapter
Advanced context management for structured_logging
convenience
Context-aware processors for domain-specific logging operations
extension
Enhanced configuration and management for structured logging
panic_handler
Structured panic logging for downstream observability systems

Macros§

a2a_context
Set A2A context for subsequent standard log calls
a2a_log
clear_context
Clear all domain contexts
llm_context
Set LLM context for subsequent standard log calls
llm_log
Convenience macros for structured logging
supervised
Macro for supervised execution with panic capturing
template_context
Set template context for subsequent standard log calls
template_log
with_a2a_context_scoped
Macro for easy scoped A2A context
with_llm_context_scoped
Macro for easy scoped LLM context
with_request_context_scoped
Macro for easy scoped request context

Structs§

BatchingConfig
Configuration for batching behavior
BatchingManager
Batching manager for telemetry data
CompactJsonFormatter
Compact JSON formatter (single line)
JsonFormatter
JSON formatter for structured logging output
LogEntry
Core log entry - pure data structure
ObservabilityConfig
Configuration for observability
ObservabilityManager
Core observability manager
ProcessorChain
Processor chain pattern (inspired by structlog)
StandardLogAdapter
Standard logging adapter that hooks into Rust’s log crate
W3CTraceContext
W3C Trace Context implementation for distributed tracing
WasmStdoutAdapter
WASM stdout transport adapter

Enums§

LogLevel
Log levels for structured logging
ObservabilityError
Comprehensive error types for observability operations
StructuredLoggingError
Enhanced error types for structured logging operations

Constants§

VERSION
Version information

Traits§

ContextPort
Port for accessing context information
FormatterPort
Port for formatting log entries
StandardLoggingPort
Port for standard logging integration
TransportPort
Port for transporting log entries to external systems

Functions§

create_enhanced_logger_from_config
Create enhanced logger from enhanced configuration
create_logger
Create a logger using observability_core foundation
create_logger_from_config
Create logger from configuration

Type Aliases§

ObservabilityResult
Result type for observability operations
Result
Result type for structured logging operations
TraceContext
Backwards-compatible alias.