pub struct WasmStdoutAdapter { /* private fields */ }Expand description
WASM stdout transport adapter
Implementations§
Source§impl WasmStdoutAdapter
impl WasmStdoutAdapter
pub fn new(formatter: Box<dyn FormatterPort>) -> Self
pub fn with_json_formatter() -> Self
Sourcepub fn with_compact_formatter() -> Self
pub fn with_compact_formatter() -> Self
Examples found in repository?
examples/tracing_and_kv_demo.rs (line 34)
15fn main() -> Result<(), Box<dyn std::error::Error>> {
16 println!("🚀 Tracing Integration and Structured Fields Demo");
17 println!("================================================\n");
18
19 // 0) Initialize standard Rust logging (log::*) via the singleton manager.
20 // This keeps the example safe (no stack-pointer logger installation).
21 let mut manager = ObservabilityManager::new(ObservabilityConfig {
22 level: "debug".to_string(),
23 format: "compact".to_string(),
24 structured: true,
25 context_enrichment: true,
26 default_context: Default::default(),
27 })?;
28 manager.initialize()?;
29
30 // 1. Set up tracing integration
31 println!("🔧 Setting up tracing integration...");
32 let tracing_subscriber = TracingIntegrationBuilder::new()
33 .with_processor_chain(observability_core::domain::build_enhanced_processor_chain())
34 .with_transport(Arc::new(WasmStdoutAdapter::with_compact_formatter()))
35 .with_level_filter(observability_core::traits::LogLevel::Debug)
36 .build()?;
37
38 // Set as global tracing subscriber
39 tracing::subscriber::set_global_default(tracing_subscriber)
40 .map_err(|e| format!("Failed to set tracing subscriber: {}", e))?;
41
42 println!("✅ Tracing integration active\n");
43
44 // 2. Demo tracing events
45 println!("📊 Testing tracing events:");
46 println!("-------------------------");
47
48 let span = span!(Level::INFO, "demo_operation", operation_id = "op-123");
49 let _enter = span.enter();
50
51 info!(target: "demo", user_id = "user-456", session = "sess-789", "Operation started");
52 debug!(items = 42, size = 1024, "Processing data");
53
54 // Nested span
55 {
56 let nested_span = span!(Level::DEBUG, "data_processing", batch_id = "batch-001");
57 let _nested_enter = nested_span.enter();
58
59 info!(records = 100, duration_ms = 250, "Processing batch");
60 debug!(errors = 0, warnings = 2, "Validation complete");
61 }
62
63 info!(
64 status = "success",
65 total_time_ms = 500,
66 "Operation completed"
67 );
68
69 if false {
70 error!(
71 error_code = 500,
72 details = "Connection timeout",
73 "This would be an error"
74 );
75 }
76
77 println!("✅ Tracing events logged with structured fields and span context\n");
78
79 // 3. Demo structured fields with standard log macros
80 println!("📝 Testing structured fields with standard log macros:");
81 println!("-----------------------------------------------------");
82
83 // Standard log messages.
84 // (KV-style structured fields are supported by the core pipeline, but we keep this example
85 // syntax conservative to compile across toolchains.)
86 log::info!("User login successful");
87 log::debug!("Database query executed");
88 log::warn!("High memory usage detected");
89
90 println!("✅ Standard log macros processed through LogKvExtractor\n");
91
92 // 4. Demo mixed usage
93 println!("🔄 Testing mixed tracing and log usage:");
94 println!("---------------------------------------");
95
96 let mixed_span = span!(Level::INFO, "mixed_operation", request_id = "req-999");
97 let _mixed_enter = mixed_span.enter();
98
99 // Tracing event
100 info!(
101 endpoint = "/api/users",
102 method = "GET",
103 "Processing request"
104 );
105
106 // Standard log messages
107 log::info!("Authentication successful");
108
109 // Tracing debug
110 debug!(cache_key = "user:123", hit = true, "Cache lookup");
111
112 // Standard log debug
113 log::debug!("Response prepared");
114
115 info!(
116 status = "success",
117 response_time_ms = 89,
118 "Request completed"
119 );
120
121 println!("✅ Mixed tracing and log usage working together\n");
122
123 println!("🎉 Demo completed successfully!");
124 println!("\n💡 Key Features Demonstrated:");
125 println!(" ✨ Tracing events → structured logs with span context");
126 println!(" 🔑 log::info!(\"msg\"; \"key\" => value) → automatic kv extraction");
127 println!(" 🔗 Unified processing through hexagonal architecture");
128 println!(" 📊 Enhanced processor chain with metadata enrichment");
129 println!(" 🎯 Both tracing and log work together seamlessly");
130
131 Ok(())
132}pub fn with_plain_text_formatter() -> Self
Trait Implementations§
Source§impl TransportPort for WasmStdoutAdapter
impl TransportPort for WasmStdoutAdapter
Source§fn transport_batch(&self, entries: &[LogEntry]) -> ObservabilityResult<()>
fn transport_batch(&self, entries: &[LogEntry]) -> ObservabilityResult<()>
Transport multiple log entries (for batching)
Auto Trait Implementations§
impl Freeze for WasmStdoutAdapter
impl !RefUnwindSafe for WasmStdoutAdapter
impl Send for WasmStdoutAdapter
impl Sync for WasmStdoutAdapter
impl Unpin for WasmStdoutAdapter
impl UnsafeUnpin for WasmStdoutAdapter
impl !UnwindSafe for WasmStdoutAdapter
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more