Download the PHP package spatie/flare-client-php without Composer
On this page you can find all versions of the php package spatie/flare-client-php. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package flare-client-php
Send PHP errors to Flare
This repository contains the PHP client to send errors and exceptions to Flare. The client can be installed using composer and works for PHP 8.0 and above.
Using Laravel? You probably want to use Ignition for Laravel. It comes with a beautiful error page and has the Flare client built in.
Documentation
When creating a new project on Flare, we'll display installation instructions for your PHP app. Even though the default settings will work fine for all projects, we offer some customization options that you might like.
Ignoring errors
The Flare client will always send all exceptions to Flare, you can change this behaviour by filtering the exceptions with a callable:
Additionally, you can provide a callable to the Flare::filterReportsUsing
method to stop a report from being sent to Flare. Compared to filterExceptionsCallable
, this can also prevent logs and errors from being sent.
Finally, it is also possible to set the levels of errors reported to Flare as such:
Controlling collected data
Just like the Laravel configuration, the generic PHP client allows you to configure which information should be sent to Flare.
Anonymizing IPs
By default, the Flare client collects information about the IP address of your application users. If you want to disable this information, you can call the anonymizeIp()
method on your Flare client instance.
Censoring request body fields
When an exception occurs in a web request, the Flare client will pass on any request fields that are present in the body.
In some cases, such as a login page, these request fields may contain a password that you don't want to send to Flare.
To censor out values of certain fields, you can use call censorRequestBodyFields
. You should pass it the names of the fields you wish to censor.
This will replace the value of any sent fields named "password" with the value "
Identifying users
When reporting an error to Flare, you can tell the Flare client, what information you have about the currently authenticated user. You can do this by providing a user
group that holds all the information you want to share.
Linking to errors
When an error occurs in web request, your application will likely display a minimal error page when it's in production.
If a user sees this page and wants to report this error to you, the user usually only reports the URL and the time the error was seen.
To let your users pinpoint the exact error they saw, you can display the UUID of the error sent to Flare.
You can do this by displaying the UUID returned by Flare::sentReports()->latestUuid()
in your view. Optionally, you can use Flare::sentReports()->latestUrl()
to get a link to the error in Flare. That link isn't publicly accessible, it is only visible to Flare users that have access to the project on Flare.
In certain cases, multiple error can be reported to Flare in a single request. To get a hold of the UUIDs of all sent errors, you can call Flare::sentReports()->uuids()
. You can get links to all sent errors with Flare::sentReports()->urls()
.
It is possible to search for certain errors in Flare using the UUID, you can find more information about that here.
Adding custom context
When you send an error to Flare within a non-Laravel application, we do not collect your application information - since we don't know about your specific application. In order to provide more information, you can add custom context to your application that will be sent along with every exception that happens in your application. This can be very useful if you want to provide key-value related information that furthermore helps you to debug a possible exception.
The Flare client allows you to set custom context items like this:
This could for example be set automatically in a Laravel service provider or an event. So the next time an exception happens, this value will be sent along to Flare and you can find it on the "Context" tab.
Grouping multiple context items
Sometimes you may want to group your context items by a key that you provide to have an easier visual differentiation when you look at your custom context items.
The Flare client allows you to also provide your own custom context groups like this:
Adding glows
In addition to custom context items, you can also add "Glows" to your application. Glows allow you to add little pieces of information, that can later be found in a chronological order in the "Debug" tab of your application.
You can think of glows as breadcrumbs that can help you track down which parts of your code an exception went through.
The Flare PHP client allows you to add a glows to your application like this:
Stacktrace arguments
When an error occurs in your application, Flare will send the stacktrace of the error to Flare. This stacktrace contains the file and line number where the error occurred and the argument values passed to the function or method that caused the error.
These argument values have been significantly reduced to make them easier to read and reduce the amount of data sent to Flare, which means that the arguments are not always complete. To see the full arguments, you can always use a glow to send the whole parameter to Flare.
For example, let's say you have the following Carbon object:
Flare will automatically reduce this to the following:
It is possible to configure how these arguments are reduced. You can even implement your own reducers!
By default, the following reducers are used:
- BaseTypeArgumentReducer
- ArrayArgumentReducer
- StdClassArgumentReducer
- EnumArgumentReducer
- ClosureArgumentReducer
- DateTimeArgumentReducer
- DateTimeZoneArgumentReducer
- SymphonyRequestArgumentReducer
- StringableArgumentReducer
Implementing your reducer
Each reducer implements Spatie\FlareClient\Arguments\Reducers\ArgumentReducer
. This interface contains a single method, execute
which provides the original argument value:
In the end, three types of values can be returned:
When the reducer could not reduce this type of argument value:
When the reducer could reduce the argument value, but a part was truncated due to the size:
When the reducer could reduce the full argument value:
For example, the DateTimeArgumentReducer
from the example above looks like this:
Configuring the reducers
Reducers can be added as such:
Reducers are executed from top to bottom. The first reducer which doesn't return an UnReducedArgument
will be used. Always add the default reducers when you want to define your own reducer. Otherwise, a very rudimentary reduced argument value will be used.
Disabling stack frame arguments
If you don't want to send any arguments to Flare, you can turn off this behavior as such:
Missing arguments?
- Make sure you've got the latest version of Flare / Ignition
- Check that
withStackFrameArguments
is not disabled - Check your ini file whether
zend.exception_ignore_args
is enabled, it should be0
Handling exceptions
When an exception is thrown in an application, the application stops executing and the exception is reported to Flare. However, there are cases where you might want to handle the exception so that the application can continue running. And the user isn't presented with an error message.
In such cases it might still be useful to report the exception to Flare, so you'll have a correct overview of what's going on within your application. We call such exceptions "handled exceptions".
When you've caught an exception in PHP it can still be reported to Flare:
In Flare, we'll show that the exception was handled, it is possible to filter these exceptions. You'll find more about filtering exceptions here.
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 Spatie\FlareClient\Flare
class, like this:
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:
Identifying users
When reporting an error to Flare, you can tell the Flare client, what information you have about the currently authenticated user. You can do this by providing a user
group that holds all the information you want to share.
Customizing error grouping
Flare has a special grouping algorithm that groups similar error occurrences into errors to make understanding what's going on in your application easier.
While the default grouping algorithm works for 99% of the cases, there are some cases where you might want to customize the grouping.
This can be done on an exception class base, you can tell Flare to group all exceptions of a specific class together:
In this case every exception of the SomeExceptionClass
will be grouped together no matter what the message or stack trace is.
It is also possible to group exceptions of the same class together, but also take the message into account:
Be careful when grouping by class and message, since every occurrence might have a slightly different message, this could lead to a lot of different errors.
Changelog
Please see CHANGELOG for more information on what has changed recently.
Testing
Contributing
Please see CONTRIBUTING for details.
Security
If you discover any security related issues, please email [email protected] instead of using the issue tracker.
License
The MIT License (MIT). Please see License File for more information.
All versions of flare-client-php with dependencies
illuminate/pipeline Version ^8.0|^9.0|^10.0|^11.0|^12.0
spatie/backtrace Version ^1.6.1
symfony/http-foundation Version ^5.2|^6.0|^7.0
symfony/mime Version ^5.2|^6.0|^7.0
symfony/process Version ^5.2|^6.0|^7.0
symfony/var-dumper Version ^5.2|^6.0|^7.0