Flare by Spatie
    • Error Tracking
    • Performance Monitoring
    • Logs Coming soon
  • Pricing
  • Docs
  • Insights
  • Changelog
  • Back to Flare ⌘↵ Shortcut: Command or Control Enter
  • Sign in
  • Try Flare for free
  • Error Tracking
  • Performance Monitoring
  • Logs Coming soon
  • Pricing
  • Docs
  • Insights
  • Changelog
    • Back to Flare ⌘↵ Shortcut: Command or Control Enter
    • Try Flare for free
    • Sign in
Flare Flare Laravel Laravel PHP PHP JavaScript JavaScript React React Vue Vue Protocol Protocol
  • General
  • Installation
  • Censoring collected data
  • Ignoring collected data
  • Flare daemon
  • Laravel Octane
  • Laravel Vapor
  • Errors
  • Adding custom context
  • Customise error report
  • Customising error grouping
  • Handling errors
  • Linking to errors
  • Reporting errors
  • Logs
  • Introduction
  • Levels
  • With errors
  • Performance
  • Introduction
  • Sampling
  • Limits
  • Modify spans and span events
  • Data Collection
  • Application info
  • Cache events
  • Console commands
  • Database transactions
  • Dumps
  • Errors when tracing
  • Exception context
  • External http requests
  • Filesystem operations
  • Git information
  • Glows
  • Identifying users
  • Jobs and queues
  • Laravel context
  • Livewire
  • Queries
  • Redis commands
  • Requests
  • Server info
  • Spans
  • Stacktrace arguments
  • Views
  • Older Packages
  • Laravel Flare V2
  • Laravel Flare V1
  • Ignition

Customise the error report

Before Flare receives the data collected from your local exception, we allow you to call custom middleware methods.

These methods retrieve the report factory that will eventually be sent to Flare and allow you to add custom information to that report.

You can create a Flare middleware as such:

use Spatie\FlareClient\FlareMiddleware\FlareMiddleware;
use Spatie\FlareClient\ReportFactory;

class MyMiddleware implements FlareMiddleware
{
    public function handle(ReportFactory $report, Closure $next): ReportFactory
    {
        $report->handled(true);

        return $next($report);
    }
}

You need to register the middleware as follows in the flare.php config file:

use Spatie\FlareClient\Enums\CollectType;

'collects' => FlareConfig::defaultCollects(
    extra: [
        CollectType::FlareMiddleware->value => [
            'flare_middleware' => [
                MyMiddleware::class => [],
            ],
        ],
    ]
),

You can also pass additional options to the middleware as such:

'collects' => FlareConfig::defaultCollects(
    extra: [
        CollectType::FlareMiddleware->value => [
            'flare_middleware' => [
                MyMiddleware::class => ['mark_every_error_handled' => false],
            ],
        ],
    ]
),

The middleware will get a $config array injected within its constructor. You can use this to get the options that were passed to the middleware:

class MyMiddleware implements FlareMiddleware
{
    protected bool $markEveryErrorHandled = false;

    public function __construct(
        array $config
    ) {
        $this->markEveryErrorHandled = $config['mark_every_error_handled'] ?? false;
    }

    public function handle(ReportFactory $report, Closure $next): ReportFactory
    {
        $report->handled($this->markEveryErrorHandled);

        return $next($report);
    }
}
Adding custom context Customising error grouping

Catch errors and fix slowdowns with Flare, the full-stack application monitoring platform for Laravel, PHP & JavaScript.

  • Platform
  • Error Tracking
  • Performance Monitoring
  • Pricing
  • Support
  • Resources
  • Insights
  • Newsletter
  • Changelog
  • Documentation
  • Affiliate program
  • uptime status badge Service status
  • Terms of use
  • DPA
  • Privacy & cookie Policy
Made in by
Flare