panic_handler
Structured panic logging for downstream observability systems
This module provides structured panic logging that integrates with observability infrastructure like Grafana, focusing purely on capturing panic information in structured format for monitoring and analysis.
Features
Section titled “Features”- 🔥 Structured Panic Logging: Detailed panic information in structured JSON format
- 📊 Panic Analytics: Basic statistics for monitoring patterns
- 🔗 Context Preservation: Maintains trace context for correlation
- 🎯 WASM Compatibility: Works in WebAssembly environments
- 🏥 Downstream Integration: Designed for Grafana and monitoring stacks
Structs
Section titled “Structs”PanicHandlerConfig
Section titled “PanicHandlerConfig”Configuration for panic logging
Fields
| Field | Type | Description |
|---|---|---|
enable_structured_logging | bool | Enable structured panic logging |
enable_analytics | bool | Enable panic analytics and pattern detection |
enable_context_preservation | bool | Enable context preservation across panics |
StructuredPanicInfo
Section titled “StructuredPanicInfo”Structured panic information for downstream systems
Fields
| Field | Type | Description |
|---|---|---|
message | String | Panic message |
location | Option<String> | Panic location (file:line:column) |
thread_info | ThreadInfo | Thread name and ID |
timestamp | String | Timestamp when panic occurred (ISO 8601) |
severity | PanicSeverity | Panic severity classification |
trace_context | Option<domain::TraceContext> | Preserved trace context |
enhanced_context | Option<EnhancedTraceContext> | Enhanced correlation context |
metadata | HashMap<String, serde_json::Value> | Additional metadata |
ThreadInfo
Section titled “ThreadInfo”Thread information for panic context
Fields
| Field | Type | Description |
|---|---|---|
name | Option<String> | |
id | String | |
is_main | bool |
PanicStats
Section titled “PanicStats”Panic statistics for monitoring
Fields
| Field | Type | Description |
|---|---|---|
total_panics | u64 | Total panics encountered |
panics_by_severity | HashMap<String, u64> | Panics by severity |
panics_by_thread | HashMap<String, u64> | Panics by thread |
common_patterns | Vec<PanicPattern> | Most common panic patterns |
last_panic_timestamp | Option<String> | Last panic timestamp |
PanicPattern
Section titled “PanicPattern”Panic pattern for analytics
Fields
| Field | Type | Description |
|---|---|---|
pattern | String | |
count | u64 | |
first_seen | String | |
last_seen | String |
PanicHandler
Section titled “PanicHandler”Structured panic logger for downstream systems
Methods
fn new(config: PanicHandlerConfig) -> Result<Self>Create a new panic handler
install
Section titled “install”fn install(config: PanicHandlerConfig) -> Result<()>Install the panic handler globally
get_stats
Section titled “get_stats”fn get_stats(&self) -> Result<PanicStats>Get current panic statistics
reset_stats
Section titled “reset_stats”fn reset_stats(&self) -> Result<()>Reset panic statistics
PanicSeverity
Section titled “PanicSeverity”Panic severity levels for classification
Variants
| Variant | Description |
|---|---|
Low | Low severity panic |
Medium | Medium severity panic |
High | High severity panic |
Critical | Critical severity panic |
Functions
Section titled “Functions”install_panic_handler
Section titled “install_panic_handler”fn install_panic_handler() -> Result<()>Install panic handler with default configuration
install_panic_handler_with_config
Section titled “install_panic_handler_with_config”fn install_panic_handler_with_config(config: PanicHandlerConfig) -> Result<()>Install panic handler with custom configuration
get_panic_stats
Section titled “get_panic_stats”fn get_panic_stats() -> Result<PanicStats>Get panic statistics if handler is installed
reset_panic_stats
Section titled “reset_panic_stats”fn reset_panic_stats() -> Result<()>Reset panic statistics if handler is installed