Customise grouping
Flare has a unique grouping algorithm that groups similar error occurrences into errors to make understanding what's going on in your application easier.
While the default grouping algorithm works for 99% of cases, there are some cases where you might want to customise it.
This can be done on an exception class basis by configuring the overridden_groupings array in your flare.php config file:
use Spatie\FlareClient\Enums\OverriddenGrouping;
// flare.php config file
'overridden_groupings' => [
SomeExceptionClass::class => OverriddenGrouping::ExceptionClass,
],
For example, an HTTP client may throw the same exception class for several external-service failures. If those failures have stable, distinct messages, group by both the class and message:
use Illuminate\Http\Client\ConnectionException;
use Spatie\FlareClient\Enums\OverriddenGrouping;
'overridden_groupings' => [
ConnectionException::class => OverriddenGrouping::ExceptionMessageAndClass,
],
Avoid message-based grouping when messages contain changing request IDs or timestamps, since those values would split every occurrence into a separate error. For applications outside Laravel, see customising grouping with the PHP SDK.
Available grouping strategies
| Strategy | Groups by | Use case |
|---|---|---|
ExceptionClass |
Exception class only | Group all exceptions of the same type together, regardless of message or stack trace |
ExceptionMessage |
Exception message only | Group by message content, useful when the exception class is generic |
ExceptionMessageAndClass |
Exception class + message | More granular grouping, but be careful as slightly different messages create separate groups |
FullStacktraceAndExceptionClassAndCode |
Full stacktrace + exception class + exception code | Useful for API exceptions like ClientException where the exception is always thrown from the same location, but you want to distinguish by HTTP status code |
Warning: Be careful when choosing a grouping strategy. If the values you group by are unique for every occurrence (e.g. exception messages containing timestamps or IDs), each occurrence will create a separate error in Flare.
On this page