Customizing error grouping
For Flare, we've spent a lot of time optimizing our grouping algorithm. This algorithm groups occurrences of errors or exceptions together into one error.
Without such an algorithm, it would be impossible to use Flare since every time your application throws an exception or error, a new error is created in Flare, making oversight impossible.
We're quite proud of our algorithm since it works for 99% of the cases, but sometimes, in our support channel, we get the question if it would be possible to have a little more control over how errors are grouped.
We've implemented such a feature recently!
For example, let's say you're using an HTTP client to contact an external service, which returns a response with an error message when something is going wrong.
You're probably not implementing an HTTP client yourself, Guzzle or Laravel's HTTP client are perfect options for making HTTP requests without having to think about the rabbit hole of problems that might arise when sending HTTP requests.
The HTTP client package will make the request and throw an exception when something is wrong. The problem is that Flare's grouping algorithm will group all these exceptions even if the message differs.
That's for a reason. While exception messages might often look the same, as soon as a uuid, integer, email, or other user-specific information is present within the message, it would create a completely different error item within Flare (if we would group based upon the exception message).
When Flare processes an error, we examine its stack trace and a few other properties and intelligently group it.
Now, there are cases where we want to group by exception message, as mentioned above. This is possible starting today when using the latest version of the laravel-flare or flare-client-php package.
In the Laravel package, you'll find a new config value:
'overridden_groupings' => [
// Illuminate\Http\Client\ConnectionException::class => Spatie\FlareClient\Enums\OverriddenGrouping::ExceptionMessageAndClass,
],
In this array, you can define exception classes that should be grouped based on:
- ExceptionClass: group all exceptions with the same exception class together
- ExceptionMessage: group all exceptions with the same message together
- ExceptionClassAndMessage: group all exceptions with the same message and exception class together
In the framework agnostic Flare client, you can add overrides as such:
$flare->overrideGrouping(SomeExceptionClass::class, OverriddenGrouping::ExceptionMessageAndClass);
We're constantly innovating Flare to improve the developer experience, and we'll share our biggest update within a few weeks. See you then!