spatie/flare-debug-sender
Debug sender for Flare payloads, mainly for internal testing. Swap Flare’s sender to log, inspect, and optionally passthrough errors/traces/zipkin, replace tracing IDs/timestamps, and print parts or the full payload via configurable channels.
composer require spatie/flare-debug-sender
php artisan vendor:publish --tag=flare-config
config/flare.php:
'sender' => [
'class' => \Spatie\FlareDebugSender\FlareDebugSender::class,
'config' => [
'channel' => \Spatie\FlareDebugSender\Channels\RayDebugChannel::class,
'passthrough_errors' => true,
],
],
\Flare::send(new \Exception('Test error for debugging'));
Use this to reproduce production-like errors without deploying to staging. Example:
// Simulate a failed API call
$exception = new \Exception('Failed to fetch from third-party API', 0, null, 'https://api.example.com/endpoint');
\Flare::send($exception);
Check Ray for the formatted payload.
flare.php with your preferred channel (e.g., RayDebugChannel for visual debugging).throw new \Exception('Debug me');).phpunit with Flare::send() in assertions).LaravelLogDebugChannel or FileDebugChannel for non-interactive debugging.Handler to auto-send Flare payloads for specific exceptions:
public function register()
{
$this->renderable(function (\Some\CustomException $e) {
\Flare::send($e);
return response()->view('errors.custom');
});
}
// Test middleware
$payload = \Flare::send(new \Exception('Test'))->getPayload();
$this->assertArrayHasKey('custom_field', $payload['context']);
\Mockery::mock('overload:' . ThirdPartyClient::class)
->shouldReceive('fetch')
->andThrow(new \Exception('Mocked API failure'));
\Flare::send(new \Exception('API call failed'));
Extend \Spatie\FlareDebugSender\Channels\DebugChannel to integrate with:
Example:
class SlackDebugChannel extends DebugChannel
{
public function log(string $message): void
{
$webhook = new \GuzzleHttp\Client();
$webhook->post('https://hooks.slack.com/...', [
'json' => ['text' => $message],
]);
}
}
Payload Size Limits:
print_full_payload: false to debug incrementally.FileDebugChannel for large payloads.SSL Verification:
CURLOPT_SSL_VERIFYPEER => 0) is required for local testing but unsafe for production. Ensure this is not committed to shared repos.'sender_config' => [
'curl_options' => config('app.debug') ? [
CURLOPT_SSL_VERIFYPEER => 0,
] : [],
],
Channel-Specific Quirks:
php artisan ray:start). Debugging fails silently if Ray isn’t active.storage_path('logs/flare-debug.log') for Laravel-friendly paths.storage/logs/laravel.log but may be overwhelmed in high-traffic apps.Passthrough Behavior:
passthrough_errors: true sends payloads to both the debug channel and the default Flare sender. Disable this in production-like tests to avoid duplicate payloads.Inspect Raw Payloads:
Use print_full_payload: true to debug payload structure, then disable it for cleaner output:
'config' => [
'print_full_payload' => env('DEBUG_FLARE_RAW') === 'true',
],
Trace ID Replacement:
Enable replace_tracing_ids: true to humanize trace IDs in logs (e.g., span-123 → span-abc). Useful for correlating logs across services.
Time Formatting:
replace_tracing_times: true converts timestamps to relative durations (e.g., 100ms), making performance debugging easier.
Endpoint/Resource Printing:
Use print_endpoint: true or print_resource: true to highlight which API routes or database queries triggered the error.
Custom Senders:
Replace CurlSender with a queue-based sender for async debugging:
'sender' => \Spatie\FlareDebugSender\Senders\QueueSender::class,
'sender_config' => [
'queue' => 'flare-debug',
],
Implement \Spatie\FlareDebugSender\Sender to add support for:
Payload Filtering:
Override \Spatie\FlareDebugSender\FlareDebugSender::preparePayload() to:
protected function preparePayload(array $payload): array
{
$payload['context']['debug'] = [
'environment' => app()->environment(),
'commit' => shell_exec('git rev-parse --short HEAD'),
];
return $payload;
}
Conditional Debugging: Use Laravel’s service providers to enable debugging only in specific environments:
if (app()->environment('local')) {
$this->app->bind(\Spatie\Flare\Flare::class, function () {
$flare = new \Spatie\Flare\Flare();
$flare->sendUsing(\Spatie\FlareDebugSender\FlareDebugSender::class, [/* config */]);
return $flare;
});
}
How can I help you explore Laravel packages today?