Consider capturing error stack traces by default in ErrorHandler
Author: SeldaekCreated Aug 28, 2026Updated Sep 1, 2026
LabelsFeature
ErrorHandler::captureStackTraces() was added in 3.11 (see #1448) to attach an \ErrorException carrying the stack trace of the error to context['exception'], so PHP warnings/notices can be traced back to their caller. It is opt-in in 3.x to avoid changing behaviour in a minor release.
For 4.0 we should consider enabling it by default: context['exception'] is the PSR-3 convention, and the absence of a trace is what made #1448 a problem in the first place.
Things to weigh before flipping the default:
- Handlers which treat
context['exception']specially would start seeing every notice and deprecation as an exception:NewRelicHandlercallsnewrelic_notice_error()andRollbarHandlerreports an exception occurrence (both affect error inventory and quota),PHPConsoleHandlercallsdispatchException(), andGelfMessageFormatterderives itsfile/lineadditional fields from the exception. NormalizerFormatter::$maxTraceLengthdefaults tonull, so every record would carry a full stack trace. Capping it might be worth doing at the same time.- Legacy code bases can emit a lot of
E_DEPRECATED, where a full trace per record is rarely worth the volume.E_ALL & ~E_DEPRECATED & ~E_USER_DEPRECATEDmay be a better default thanE_ALL.
The cost itself is not a concern: roughly 1µs and one small object per handled error, and debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS) means no arguments are retained.
Source: Seldaek/monolog