Laravel 11 recently introduced a nice new feature called Context. Both Ignition and Flare have been updated to collect and show all context.
What is Context?
Laravel's latest feature allows you to set some contextual values anywhere in your app. This allows you to store and exchange information across different requests, jobs, and commands in your application. This information is written alongside logs, aiding in understanding the sequence of events leading up to the log entry or error.
use Illuminate\Support\Facades\Context;
Context::add('url', $request->url());
Context::add('trace_id', Str::uuid()->toString());
You can easily retrieve these values anywhere in your app.
use Illuminate\Support\Facades\Context;
Context::all(); // returns all context
Now, this isn’t all that special. With the examples given above, you’d be right to think that Context is just some array-backed cache.
But the special thing that Context does is make all of this information available to any job dispatched in the request where context was set.
dispatch(new MyJob()); // this job will receive the context
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Support\Facades\Context;
class MyJob implements ShouldQueue
{
public function handle()
{
// returns the context that was
// set in the request that dispatched
// this job
$allContent = Context::all();
// do some work
// ...
}
}
Context in Ignition and Flare
Ignition, the error page we created and used in Laravel by default, now displays all set context.
Here’s what that looks like in Ignition.
Of course, Flare now collects and displays context as well. Here’s what that looks like when you have an exception in a request or job that holds context.
Continue reading
Lessons from the deep end
20 months ago, we started building Performance Monitoring as Flare’s next big feature, never expecting Laravel’s rapid commercial growth to put us in direct competition with their own tools. This is our honest take on those 20 months went, how we’re adapting to this new reality, and where we’re heading next while staying true to who we are. A dive into the deep end, without knowing how far down it goes.
Alex
Connect your AI agent to Flare to automatically fix production and performance problems in PHP and Laravel projects
You can now use our MCP server to connect your AI agent to Flare. This way your AI has all context it needs to diagnose and fix production and performance problems.
Freek
Subscribe to Backtrace, our quarterly Flare newsletter
No spam, just news & product updates