Overview of Flare PHP client
mainspatie/flare-client-php package is a client designed to send PHP errors and exceptions/traces to Flare. It is a standalone client for general PHP applications.repository·main·Indexed 41 days ago
https://github.com/spatie/flare-client-phpA standalone PHP client for sending errors, traces, and logs to Flare. It provides tools for distributed tracing via the Tracer class, error reporting through the ReportFactory, and environmental context enrichment using the Resource class. Requires PHP 8.2 or higher.
spatie/flare-client-php package is a client designed to send PHP errors and exceptions/traces to Flare. It is a standalone client for general PHP applications.v3 introduces Dedicated logging as a first-class feature via $flare->log(). This replaces the deprecated reportMessage() method and records messages in the OpenTelemetry log format. Log levels now use Monolog's Level enum.
Standalone logging is opt-in. It is recommended to pair it with the Flare daemon to ensure logs are buffered in memory and flushed asynchronously, keeping delivery off the request thread.
use Monolog\Level;
use Spatie\FlareClient\FlareConfig;
use Spatie\FlareClient\Senders\DaemonSender;
FlareConfig::make('your-api-key')
->log(minimalLevel: Level::Info)
->sendUsing(DaemonSender::class);In v3, recorders no longer accept loose arguments (like request objects or status codes) directly. Instead, they use Attribute Providers that implement specific contracts (e.g., RequestAttributesProvider, ResponseAttributesProvider).
Recorders provide helper methods (e.g., recordStartFromSymfonyRequest()) to simplify creating these providers from common framework objects.
// Request Recording Example
// Before
$flare->request()->recordStart(
request: $request,
route: '/users/{id}',
entryPointClass: UserController::class,
);
// After (using provider)
$flare->request()->recordStart(
new SymfonyRequestAttributesProvider($redactor, $request),
);
// After (using helper)
$flare->request()->recordStartFromSymfonyRequest($request);In version 2, you can no longer add middleware inline using a closure. You must register middleware classes via the Flare config object using the collectFlareMiddleware method.
$config->collectFlareMiddleware([
MyMiddleware::class => [],
]);spatie/laravel-flare, you can skip the 'Framework integrator changes' section of the migration guide.The Flare PHP client can be installed via Composer. It requires PHP 8.2 or higher.
Note for Laravel users: If you are using the Laravel framework, it is recommended to use Flare for Laravel instead of this standalone client.
composer require spatie/flare-client-phpIn version 2, the group method has been removed. To add context data, use the context() method. You can add a single item or an associative array of multiple items.
// Single item
$flare->context('key', 'value');
// Multiple items
$flare->context([
'key' => 'value',
'key2' => 'value2',
]);In version 3.1, the way you initialize the Flare client in framework-agnostic applications has changed. You must replace the registerFlareHandlers() method with $flare->start(). Calling start() is required to open the lifecycle for the client.
Note: If you are using the spatie/laravel-flare package, no changes are required as the integrator handles this automatically.
$flare = Flare::make($config)->start();$config->collectSolutions(), $flare->withSolutionProvider(), $config->ignoreSolutions(), and the AddSolutions middleware. The spatie/error-solutions dependency can also be removed.Upgrading from version 1 to version 2 involves a complete rewrite of the package. Key changes include:
anonymizeIp() is now censorClientIps()censorRequestBodyFields() is now censorBodyFields()reportErrorLevels()overrideGrouping()context() method instead of the group() method.MessageLevels is now an enum. The syntax for adding glows has changed.argumentReducers() has been removed. Use collectStackFrameArguments() on the Flare config object instead.// New context usage
$flare->context('key', 'value');
$flare->context(['key' => 'value', 'key2' => 'value2']);
// New glow usage
$flare->glow()->record('This is a message from glow!', MessageLevels::Debug);
// New middleware registration
$config->collectFlareMiddleware([
MyMiddleware::class => [],
]);For applications running in subtask mode, such as queue workers or other long-running processes, continue to use $flare->lifecycle->startSubtask() for every individual unit of work to ensure proper trace separation.
$flare->lifecycle->startSubtask();In version 2, MessageLevels is an enum and the method chain for adding glows has changed. Instead of calling glow() with arguments, you must call glow() and then record().
// New way to add a glow
$flare->glow()->record('This is a message from glow!', MessageLevels::Debug);