Modifying the configuration
Most of Flare's behaviour is configured through the config/flare.php file. Some things cannot be expressed there, for example a closure that adds custom attributes to the resource, or swapping out a recorder. For those cases you can register a callback that receives the FlareConfig before Flare boots.
use Spatie\FlareClient\Resources\Resource;
use Spatie\LaravelFlare\FlareConfig;
use Spatie\LaravelFlare\FlareServiceProvider;
FlareServiceProvider::configure(function (FlareConfig $config) {
$config->configureResource(
fn (Resource $resource) => $resource->addAttribute('team.owner', 'payments'),
);
});
The callback can change anything on the FlareConfig, so besides the resource you can also adjust recorders, sampling, or the sender.
Where to register the callback
Flare's service provider registers before your application's own providers, so registering the callback in a service provider is too late. Register it in bootstrap/app.php, next to Flare::handles(), which runs before Flare boots:
use Spatie\FlareClient\Resources\Resource;
use Spatie\LaravelFlare\Facades\Flare;
use Spatie\LaravelFlare\FlareConfig;
use Spatie\LaravelFlare\FlareServiceProvider;
->withExceptions(function (Exceptions $exceptions) {
Flare::handles($exceptions);
FlareServiceProvider::configure(function (FlareConfig $config) {
$config->configureResource(
fn (Resource $resource) => $resource->addAttribute('team.owner', 'payments'),
);
});
})
On this page