rootcause-backtrace
Stack backtrace support for the rootcause error reporting library.
Overview
This crate provides automatic stack trace capture for rootcause error reports. Backtraces help you see the call stack that led to an error, making debugging much easier.
Quick Start
Add to your Cargo.toml:
[]
= "0.11"
= "0.11"
Automatic Capture (All Errors)
Install a hook to automatically attach backtraces to every error:
use Hooks;
use BacktraceCollector;
Manual Attachment (Specific Errors)
Use the extension trait to attach backtraces selectively:
use ;
use BacktraceExt;
// Attach backtrace only to this specific error
let result = risky_operation.attach_backtrace;
Output Example
When an error with a backtrace is printed:
● Failed to process request
├ src/main.rs:45:10
├ Backtrace
│ │ process_request - src/main.rs:45
│ │ handle_connection - src/main.rs:32
│ │ main - src/main.rs:18
│ │ note: 15 frame(s) omitted. For a complete backtrace, set RUST_BACKTRACE=full.
│ ╰─
│
● Database connection lost
╰ src/db.rs:89:5
Environment Variables
Control backtrace behavior at runtime:
RUST_BACKTRACE=full- Show all frames with full file paths (no filtering)ROOTCAUSE_BACKTRACE- Comma-separated options:leafs- Only capture backtraces for leaf errors (errors without children)full_paths- Show full file paths instead of shortened versions
Examples:
# Show complete backtraces with all frames
RUST_BACKTRACE=full
# Only capture backtraces for leaf errors
ROOTCAUSE_BACKTRACE=leafs
# Show full file paths
ROOTCAUSE_BACKTRACE=full_paths
Filtering Frames
Customize which frames appear in backtraces:
use ;
let collector = BacktraceCollector ;
Release Builds
To get useful backtraces in release builds, enable debug symbols in your Cargo.toml:
[]
= false
= true # or "line-tables-only" for smaller binaries
Path Privacy
By default, backtraces show shortened paths for better readability, but they may still expose your filesystem structure. If this is a concern, use rustc's path remapping:
# Set when building for release
This remaps absolute paths to generic placeholders.
Features
- Smart filtering - Automatically hides noisy runtime frames while showing your code
- Readable output - Shortened paths and formatted display
- Configurable - Control capture behavior and filtering per your needs
- Environment-aware - Respects
RUST_BACKTRACEand custom options - Opt-in by design - Only applications that install the hooks pay the capture cost
API Documentation
For complete API documentation, see docs.rs/rootcause-backtrace.
Minimum Supported Rust Version (MSRV)
This crate's MSRV matches rootcause: 1.89.0