Flare by Spatie
  • Features
  • Pricing
  • Docs
  • Blog
  • LOG IN
  • START TRACKING
  • Home
  • Features
  • Pricing
  • Docs
  • Blog
    • Try Flare for free
    • Sign in
Flare Flare Laravel Laravel PHP PHP JavaScript JavaScript
  • General
  • Introduction
  • Installation
  • Censoring collected data
  • Ignoring collected data
  • Errors
  • Adding custom context
  • Customising error grouping
  • Handling errors
  • Linking to errors
  • Reporting errors
  • Performance
  • Introduction
  • Sampling
  • Limits
  • Modify spans and events
  • Data Collection
  • Application info
  • Application lifecycle
  • Cache events
  • Console commands
  • Customise error report
  • Database transactions
  • Dumps
  • Errors when tracing
  • Exception context
  • External http requests
  • Filesystem operations
  • Git information
  • Glows
  • Identifying users
  • Logs
  • Queries
  • Redis commands
  • Requests
  • Routing
  • Server info
  • Solutions
  • Spans
  • Stacktrace arguments
  • Views
  • Older Packages
  • Flare Client PHP V1

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:

$config->collectFlareMiddleware([
    MyMiddleware::class => [],
]);

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

$config->collectFlareMiddleware([
    MyMiddleware::class => [
        'mark_every_error_handled' => false,
    ],
]);

The middleware can get these config values as follows:

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

class MyMiddleware implements FlareMiddleware
{
    public function __construct(
        protected bool $markEveryErrorHandled = false,
    ) {}
    
    public static function register(Container $container, array $config): Closure
    {
        return fn() => new self(
            $config['mark_every_error_handled'] ?? false,
        );
    }

    public function handle(ReportFactory $report, Closure $next): ReportFactory;
    {
        $report->handled($this->config['mark_every_error_handled']);

        return $next($report);
    }
}

Since the framework-agnostic version of Flare does not have an auto wiring container, you'll need to register the middleware manually. During the registration, you'll receive a config array with the options that were passed to the middleware.

Console commands Database transactions

Monitor your web apps and sites from errors to slowdowns with Flare, the easiest application monitoring platform for Laravel, PHP & Javascript.

  • Platform
  • Error Tracking
  • Performance Monitoring
  • Pricing
  • Support
  • Resources
  • Blog
  • Changelog
  • Documentation
  • Affiliate program
  • Service status
  • Terms of use
  • DPA
  • Privacy & Cookie Policy
Flare