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.
debug_backtrace(), offering structured, human-readable frame objects with enhanced metadata (e.g., applicationFrame, object, arguments). This aligns perfectly with Laravel’s debugging needs (e.g., error handling, logging, monitoring).artisan and Statamic’s please CLI files as vendor frames reduces noise in application traces.composer require spatie/backtrace and a single line to replace debug_backtrace() (e.g., Spatie\Backtrace\Backtrace::create()).debug_backtrace() usage; no breaking changes to Laravel’s core.createForThrowable($e)).withArguments(), withObject()) adds CPU/memory cost. Mitigation: Use selectively (e.g., only in dev/staging).open_basedir Restrictions: Fixed in v1.7.4, but test locally if your server enforces this.artisan) may need manual exclusion if not handled by the package.debug_backtrace() calls, or only specific instances (e.g., error logs)?debug_backtrace() in App\Exceptions\Handler.Monolog handlers or custom log channels.debug_backtrace() in a single component (e.g., a custom error page).// Before
$trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 5);
// After
$trace = Spatie\Backtrace\Backtrace::create()->limit(5)->frames();
app() helper to inject the package into service providers:
$this->app->singleton('backtrace', fn() => Spatie\Backtrace\Backtrace::create()->applicationPath(base_path()));
Backtrace::frames()).User models).Log::error($e, ['backtrace' => Backtrace::createForThrowable($e)])).debug_backtrace() in Debugbar’s collectors.createForThrowable() to attach enhanced traces to errors.spatie/laravel-logging (for structured logs).nunomaduro/collision (for exception handling).withArguments()/withObject() in high-throughput endpoints (e.g., webhooks).artisan) are handled by the package.debug_backtrace() output.withArguments()/withObject() to reduce overhead.debug_backtrace() using microtime().| Scenario | Risk | Mitigation |
|---|---|---|
open_basedir restrictions |
Crashes when accessing files. | Test locally; use try-catch around frame creation. |
| Argument leakage | Sensitive data in logs. | Use reducers to mask data (e.g., Password::mask()). |
| PHP version mismatch | Breaking changes in new PHP. | Pin to LTS versions (e.g., PHP 8.1) or test upgrades. |
| Custom CLI files misclassified | Noise in traces. | Extend applicationPath() logic or use startingFromFrame(). |
| High-load endpoints | Performance degradation. | Disable arguments/objects in production. |
Backtrace::create()->frames()).debug_backtrace() (e.g., applicationFrame flag).How can I help you explore Laravel packages today?