Custom context
Flare collects a lot of Laravel and user specific information for you automatically. On top of that, you can attach your own key/value data so it shows up on every error report, trace, and log Flare receives.
This is especially useful in applications that serve multiple tenants, or whenever you want a value (like the active tenant, an experiment variant, or a feature flag state) to be available everywhere without having to remember to add it at the call site.
Adding context
Use the Flare facade to add a context item:
use Spatie\LaravelFlare\Facades\Flare;
Flare::context('tenant', 'My-Tenant-Identifier');
This value is included with every error report, trace, and log collected after this call during the current request, command, or job. You can find it in the "Context" tab. Reporting an exception does not clear this shared context.
To attach data only to a specific exception, define a context() method on that exception.
You can also set multiple context items at once:
use Spatie\LaravelFlare\Facades\Flare;
Flare::context([
'tenant_id' => 'My-Tenant-Identifier',
'tenant_name' => 'My-Tenant-Name',
]);
A common place to set custom context is in a service provider or a middleware, so the values are populated for the rest of the request, command, or job.
On this page