Filament tracer is a flexible filament plugin to report and view exceptions and traces with a generic table schema to be able to store traces from other programming languages.
The purpose of this package is to have a common tables to report/log errors throughout your applications, independent of what programming language you use so long as your application has a connection to the database, you can store the traces then later view them in filament dashboard.
This plugin requires Filament v3.0+, it does not work in older version!
Install the package via composer:
composer require entensy/filament-tracer
You could also use direct repository url in your composer.json
:
"require": {
"entensy/filament-tracer": "dev-main"
}
"repositories": [
{
"type": "git",
"url": "https://github.com/entensy/filament-tracer.git"
}
]
Register the plugin in your desired filament panel:
public function panel(Panel $panel): Panel
{
return $panel
...
->plugins([
FilamentTracerPlugin::make()
// You may define how you would like to get tab badge numbers, these must return int type
->tracesCounterUsing(fn($record) => count( explode(PHP_EOL, $record->traces) ) ?? 0)
->queriesCounterUsing(fn($record) => /** return int value */)
->bodyCounterUsing(fn($record) => /** return int value */)
->headersCounterUsing(fn($record) => /** return int value */)
->cookiesCounterUsing(fn($record) => /** return int value */)
]);
}
To register capturing exceptions and errors, go to your
app\Exceptions\Handler.php
file and put the following snippet into register
method:
$this->reportable(function (Throwable $e) {
if ($this->shouldReport($e)) {
\Entensy\FilamentTracer\FilamentTracer::capture($e, request());
}
});
You may change the palette colors in your Filament Panel Service Provider:
$panel
->colors([
'danger' => Color::Rose,
'primary' => Color::Red,
'success' => Color::Green,
'warning' => Color::Yellow,
'gray' => Color::Gray,
'info' => Color::Blue,
])
You may publish configuration using Laravel's publish command:
# Publish config file
php artisan vendor:publish --tag=filament-tracer-config
# Publish views
php artisan vendor:publish --tag=filament-tracer-views
# Publish translations
php artisan vendor:publish --tag=filament-tracer-translations
# Publish migrations
php artisan vendor:publish --tag=filament-tracer-migrations
You may write your own tracer class by changing the default class in the plugin
config file. If you don't have this file, you may publish it with
php artisan vendor:publish --tag=filament-tracer-config
file:
[
...
// You may implement your own tracer by implementing Tracerable interface
'tracer' => \Entensy\FilamentTracer\DefaultTracer::class,
...
]
Defining a custom Tracer class has to implement Tracerable
interface.
use Entensy\FilamentTracer\Contracts\Tracerable;
class MyCustomTracer implements Tracerable
{
//
}
If you would like to change how an error being stored, you may overwrite this
implementation by implementing HasStore
interface in your custom tracer class
then add your implementation in store
method
use Entensy\FilamentTracer\Contracts\HasStore;
use Entensy\FilamentTracer\Contracts\Tracerable;
class MyCustomTracer implements Tracerable, HasStore
{
public function store(): mixed
{
$err = $this->getThrowable():
// just log the trace and don't store it in database
logger()->error($err);
return true;
}
}
composer test
Please see CHANGELOG for more information what has changed recently.
Please see CONTRIBUTING for details.
Please email [email protected]
for any security issues.
This repository is under MIT License (MIT).