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
  • Introduction
  • Customise error report
  • Customising error grouping
  • Linking to errors
  • Logs
  • Introduction
  • Levels
  • With errors
  • Performance
  • Introduction
  • Sampling
  • Limits
  • Modify spans and span events
  • Data Collection
  • Application info
  • Cache events
  • Console commands
  • Custom context
  • 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

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');

The next time an error is reported, a trace is flushed, or a log is sent, this value will be included and available in the "Context" tab.

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.

Console commands Database transactions
  • On this page
  • Adding context

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