Exception context
To attach context only to a specific exception, define a context() method on its class:
use Exception;
class ExceptionWithContext extends Exception
{
public function context(): array
{
return [
'key' => 'value',
];
}
}
Flare collects this context when the exception is reported, including when you pass a caught exception to Laravel's report() helper. These values belong to that exception's report.
For values shared across errors, traces, and logs, such as a tenant ID, use Flare::context().
It is possible to disable the collection of context information by ignoring the ExceptionContext collect in config.php:
use Spatie\LaravelFlare\Enums\LaravelCollectType;
'collects' => FlareConfig::defaultCollects(
ignore: [LaravelCollectType::ExceptionContext],
),