Insights
Enhancing error reporting with custom context and glows
When it comes to debugging errors in your Laravel applications, Flare already collects several Laravel and user-specific information to send along with the error. However, an additional layer of customization is available that can provide even deeper insights into your application's state when the error or the exception arises: custom context.
Adding custom context
Implementing custom context in Flare is relatively straightforward. You can set context items using the provided Flare facade within your Laravel application in the service provider or an event:
use Spatie\LaravelIgnition\Facades\Flare;
Flare::context('Tenant', 'My-Tenant-Identifier');
Once set, the next time an exception happens, the custom value will be in the error's context tab on the Flare dashboard.
Adding a group of context items
But what if you have multiple items of custom context to include? Flare allows you to group related context items under a common label. Here's how you can create custom context groups:
use Spatie\LaravelIgnition\Facades\Flare;
Flare::group('Custom information', [
'key' => 'value',
'another key' => 'another value',
]);
Adding a glow
While adding context is already very useful, we can take error reporting even further. To understand what happened in your application before each error, it can be helpful to log short statements, also known as glows. Glows would be especially useful to log events that might happen multiple times during the request, for example, when calling a payment provider API.
You can set up glows in your Laravel's service provider:
use Spatie\LaravelIgnition\Facades\Flare;
use Spatie\FlareClient\Enums\MessageLevels;
Flare::glow('This is a message from glow!', MessageLevels::DEBUG, func_get_args());
Once enabled, glows can be found in chronological order in the Debug tab of the error on the Flare dashboard.
Flare already excels at capturing essential data for error diagnosis, but leveraging custom context and glows allows you to debug the errors even better. If that sounds like something you want to explore, you can try Flare for free! New customers get a 10-day trial, and no credit card is required to sign up. Check out our documentation for more information.
Continue reading
One core, many clients: the new Flare JavaScript client architecture
We recently reshaped the Flare JavaScript client from a single browser library and a few thin framework specific packages into a small family of packages built on a shared, platform-agnostic core. This post explains why we did it, what the core package exposes, how the browser and Node SDKs are built on top of it, why the React, Vue, and Svelte packages sit one level higher, and how anyone can use the same core to write a Flare JS client for a platform we do not ship ourselves.
Dries
Logging is here!
Logging is now available for all Flare users! Send any log from your app to Flare and use our polished interface to filter and search your logs in real-time.
Jimi
Subscribe to Backtrace, our quarterly Flare newsletter
No spam, just news & product updates