Stacktrace arguments
When an error occurs in your application, Flare will send the stacktrace of the error to Flare. This stacktrace contains the file and line number where the error occurred and the argument values passed to the function or method that caused the error.
These argument values have been significantly reduced to make them easier to read and reduce the amount of data sent to Flare, which means that the arguments are not always complete. To see the full arguments, you can always use a glow to send the whole parameter to Flare.
For example, let's say you have the following Carbon object:
new DateTime('2020-05-16 14:00:00', new DateTimeZone('Europe/Brussels'))
Flare will automatically reduce this to the following:
16 May 2020 14:00:00 +02:00
It is possible to configure how these arguments are reduced. You can even implement your own reducers!
By default, the following reducers are used:
- BaseTypeArgumentReducer
- ArrayArgumentReducer
- StdClassArgumentReducer
- EnumArgumentReducer
- ClosureArgumentReducer
- DateTimeArgumentReducer
- DateTimeZoneArgumentReducer
- SymphonyRequestArgumentReducer
- ModelArgumentReducer
- CollectionArgumentReducer
- StringableArgumentReducer
Implementing your reducer
Each reducer implements Spatie\FlareClient\Arguments\Reducers\ArgumentReducer
. This interface contains a single method, execute
which provides the original argument value:
interface ArgumentReducer
{
public function execute(mixed $argument): ReducedArgumentContract;
}
In the end, three types of values can be returned:
When the reducer could not reduce this type of argument value:
return UnReducedArgument::create();
When the reducer could reduce the argument value, but a part was truncated due to the size:
return new TruncatedReducedArgument(
array_slice($argument, 0, 25), // The reduced value
'array' // The original type of the argument
);
When the reducer could reduce the full argument value:
return new TruncatedReducedArgument(
$argument, // The reduced value
'array' // The original type of the argument
);
For example, the DateTimeArgumentReducer
from the example above looks like this:
class DateTimeArgumentReducer implements ArgumentReducer
{
public function execute(mixed $argument): ReducedArgumentContract
{
if (! $argument instanceof \DateTimeInterface) {
return UnReducedArgument::create();
}
return new ReducedArgument(
$argument->format('d M Y H:i:s p'),
get_class($argument),
);
}
}
Configuring the reducers
Reducers can be added to the flare.php
config file (or ignition.php
if you're using the spatie/laravel-ignition
package):
/*
|--------------------------------------------------------------------------
| Argument reducers
|--------------------------------------------------------------------------
|
| Ignition show you stack traces of exceptions with the arguments that were
| passed to each method. To make these variables more readable, you can
| specify a list of classes here which summarize the variables.
|
*/
'argument_reducers' => [
\Spatie\Backtrace\Arguments\Reducers\BaseTypeArgumentReducer::class,
\Spatie\Backtrace\Arguments\Reducers\ArrayArgumentReducer::class,
\Spatie\Backtrace\Arguments\Reducers\StdClassArgumentReducer::class,
\Spatie\Backtrace\Arguments\Reducers\EnumArgumentReducer::class,
\Spatie\Backtrace\Arguments\Reducers\ClosureArgumentReducer::class,
\Spatie\Backtrace\Arguments\Reducers\DateTimeArgumentReducer::class,
\Spatie\Backtrace\Arguments\Reducers\DateTimeZoneArgumentReducer::class,
\Spatie\Backtrace\Arguments\Reducers\SymphonyRequestArgumentReducer::class,
\Spatie\LaravelFlare\ArgumentReducers\ModelArgumentReducer::class, // Or \Spatie\LaravelIgnition\ArgumentReducers\ModelArgumentReducer::class when using the `spatie/laravel-ignition` package
\Spatie\LaravelFlare\ArgumentReducers\CollectionArgumentReducer::class, // Or \Spatie\LaravelIgnition\ArgumentReducers\CollectionArgumentReducer::class when using the `spatie/laravel-ignition` package
\Spatie\Backtrace\Arguments\Reducers\StringableArgumentReducer::class,
],
Reducers are executed from top to bottom. The first reducer which doesn't return an UnReducedArgument
will be used.
Disabling stack frame arguments
If you don't want to send any arguments to Flare, you can turn off this behavior within the flare.php
config file (or ignition.php
if you're using the spatie/laravel-ignition
package):
/*
|--------------------------------------------------------------------------
| Include arguments
|--------------------------------------------------------------------------
|
| Ignition show you stack traces of exceptions with the arguments that were
| passed to each method. This feature can be disabled here.
|
*/
'with_stack_frame_arguments' => false,
Missing arguments?
- Make sure you've got the latest version of Flare / Ignition
- Check that
with_stack_frame_arguments
is not disabled - Check your ini file whether
zend.exception_ignore_args
is enabled, it should be0