Flare Error tracking made for Laravel
Features Pricing Docs Blog Log in Start free trial Free trial
  • Docs
  • Videos

Documentation

  • General

    • Welcome
    • Projects
    • Errors
    • Error occurrences
    • Using the API
    • Sharing error occurrences
    • Spike protection
    • GitHub integration
  • Ignition for Laravel

    • Installation
    • Configuration
    • Security
    • Controlling collected data
    • Sending logs to Flare
    • Linking to errors
    • Identifying users
    • Adding custom context
    • Adding glows
    • Writing custom middleware
  • Flare for generic PHP projects

    • Installation
    • Controlling collected data
    • Identifying users
    • Linking to errors
    • Adding custom context
    • Adding glows
    • Writing custom middleware
  • Javascript error tracking

    • Installation
    • Framework integrations
    • Resolving Bundled Code
    • Reporting errors
    • Client hooks
    • Adding custom context
    • Adding glows
    • Solution Providers
  • Solutions

    • Introduction
    • Adding custom solutions
    • Making solutions runnable
    • Using solution providers
    • Writing good solutions
  • Notifications

    • Configuring notifications
    • Mail
    • Slack
    • Telegram
    • SMS
    • Webhooks
    • Discord
    • Microsoft Teams
  • Team management

    • Using multiple teams
    • Subscribing to a plan
    • Receiving invoices
    • Managing team members
    • Inviting guests to projects

Writing custom middleware

Before Flare receives the data that was collected from your local exception, we give you the ability to call custom middleware methods. These methods retrieve the report that should be sent to Flare and allow you to add custom information to that report.

Just like with the Flare client itself, you can add custom context information to your report as well. This allows you to structure your code so that you have all context related changes in one place.

You can register a custom middleware by using the registerMiddleware method on the Facade\FlareClient\Flare class, like this:

use Spatie\FlareClient\Report;
use Spatie\LaravelIgnition\Facades\Flare;

Flare::registerMiddleware(function (Report $report, $next) {
    // Add custom information to the report
    $report->context('key', 'value');

    return $next($report);
});

A middleware can either be a callable, as seen above, or a custom class that implements a handle method. This class can make use of dependency injection in its constructor:

Here is an example:

use Spatie\LaravelIgnition\Facades\Flare;

Flare::registerMiddleware(FlareMiddleware::class);

To create a middleware that, for example, removes all the session data before your report gets sent to Flare, the middleware implementation might look like this:

use Spatie\FlareClient\Report;

class FlareMiddleware
{
    public function handle(Report $report, $next)
    {
	    $context = $report->allContext();

	    $context['session'] = null;

	    $report->userProvidedContext($context);

	    return $next($report);
    }
}
Previous topic Next topic

About Flare

  • Home
  • Features
  • Pricing
  • Support

Resources

  • Blog
  • Changelog
  • Docs
  • Ignition

App

  • Log in
  • Start free trial
SPATIE
  • Service status
  • Terms of use
  • Privacy & cookie policy