spatie/backtrace
A cleaner, more useful PHP backtrace than debug_backtrace(). Create a Backtrace, get frames as typed Frame objects with correct file, line, class/method, and optional arguments, making stack traces easier to inspect, filter, and work with.
Debugging & Observability:
Performance & Cost Optimization:
Security & Compliance:
ArgumentReducer to mask sensitive data (e.g., passwords, tokens) in stack traces.Roadmap Alignment:
artisan or Statamic’s please CLI commands to exclude them from application frames (already supported).applicationPath to distinguish between service-specific backtraces in distributed systems.Build vs. Buy:
ArgumentReducer or Frame properties for niche use cases (e.g., custom argument formatting for domain objects).Adopt if:
debug_backtrace() output.Look elsewhere if:
"This package transforms how we debug PHP applications by replacing cryptic debug_backtrace() output with structured, actionable stack traces. For example:
"Spatie’s backtrace solves three key pain points:
debug_backtrace()’s quirks (e.g., skewed function names) and adds properties like applicationFrame to distinguish your code from vendor libraries.withArguments()). Reduce clutter with custom ArgumentReducer classes (e.g., format DateTime objects).artisan/please from application frames—no manual config needed.
Use cases:"Swap debug_backtrace() for this in 5 minutes:
$frames = Spatie\Backtrace\Backtrace::create()
->withArguments()
->applicationPath(base_path())
->trimFilePaths()
->frames();
// Now you get:
// - `frame->file` (relative to app root)
// - `frame->arguments` (with custom reducers)
// - `frame->applicationFrame` (bool: is this our code?)
Pro tip: Use startingFromFrame() to isolate stack traces to specific classes/methods. Perfect for unit tests or CLI debugging."*
How can I help you explore Laravel packages today?