improved error tracking
This commit is contained in:
parent
79380dc3e8
commit
808955294d
@ -56,28 +56,8 @@ class Handler extends ExceptionHandler
|
|||||||
public function register()
|
public function register()
|
||||||
{
|
{
|
||||||
$this->reportable(function (Throwable $e) {
|
$this->reportable(function (Throwable $e) {
|
||||||
if (config('logging.default') == 'sentry') {
|
|
||||||
app('sentry')->configureScope(function ($scope) {
|
|
||||||
$scope->setTag('company_id', (string) company_id());
|
|
||||||
$scope->setTag('locale', (string) app()->getLocale());
|
|
||||||
$scope->setTag('timezone', (string) config('app.timezone'));
|
|
||||||
});
|
|
||||||
|
|
||||||
//define('SENTRY_RELEASE', version('short'));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (config('logging.default') == 'bugsnag') {
|
if (config('logging.default') == 'bugsnag') {
|
||||||
app('bugsnag')->registerCallback(function ($report) {
|
call_user_func(config('bugsnag.before_send'), $e);
|
||||||
$report->setMetaData([
|
|
||||||
'akaunting' => [
|
|
||||||
'company_id' => (string) company_id(),
|
|
||||||
'locale' => (string) app()->getLocale(),
|
|
||||||
'timezone' => (string) config('app.timezone'),
|
|
||||||
]
|
|
||||||
]);
|
|
||||||
});
|
|
||||||
|
|
||||||
app('bugsnag')->setAppVersion(version('short'));
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
23
app/Exceptions/Trackers/Bugsnag.php
Normal file
23
app/Exceptions/Trackers/Bugsnag.php
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Exceptions\Trackers;
|
||||||
|
|
||||||
|
use Throwable;
|
||||||
|
|
||||||
|
class Bugsnag
|
||||||
|
{
|
||||||
|
public static function beforeSend(Throwable $e): void
|
||||||
|
{
|
||||||
|
app('bugsnag')->setAppVersion(version('short'));
|
||||||
|
|
||||||
|
app('bugsnag')->registerCallback(function ($report) {
|
||||||
|
$report->setMetaData([
|
||||||
|
'akaunting' => [
|
||||||
|
'company_id' => (string) company_id(),
|
||||||
|
'locale' => (string) app()->getLocale(),
|
||||||
|
'timezone' => (string) config('app.timezone'),
|
||||||
|
]
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
50
app/Exceptions/Trackers/Sentry.php
Normal file
50
app/Exceptions/Trackers/Sentry.php
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Exceptions\Trackers;
|
||||||
|
|
||||||
|
use Illuminate\Support\Str;
|
||||||
|
use Sentry\Event;
|
||||||
|
use Sentry\EventHint;
|
||||||
|
use Sentry\Tracing\SamplingContext;
|
||||||
|
|
||||||
|
class Sentry
|
||||||
|
{
|
||||||
|
public static function beforeSend(Event $event, ?EventHint $hint): ?Event
|
||||||
|
{
|
||||||
|
$event->setRelease(version('short'));
|
||||||
|
|
||||||
|
$event->setTags([
|
||||||
|
'company_id' => (string) company_id(),
|
||||||
|
'locale' => (string) app()->getLocale(),
|
||||||
|
'timezone' => (string) config('app.timezone'),
|
||||||
|
]);
|
||||||
|
|
||||||
|
return $event;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function tracesSampler(SamplingContext $context): float
|
||||||
|
{
|
||||||
|
if (static::filterAgent()) {
|
||||||
|
return 0.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return config('sentry.traces_sample_rate');
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function filterAgent(): bool
|
||||||
|
{
|
||||||
|
$user_agent = request()->userAgent();
|
||||||
|
|
||||||
|
$filter_agents = explode(',', env('SENTRY_TRACES_FILTER_AGENTS'));
|
||||||
|
|
||||||
|
foreach ($filter_agents as $filter_agent) {
|
||||||
|
if (! Str::contains($user_agent, $filter_agent)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
@ -349,4 +349,16 @@ return [
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
'feature_flags' => [],
|
'feature_flags' => [],
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Before send
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| An array of callback class and method.
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
'before_send' => [env('BUGSNAG_BEFORE_SEND_CLASS', 'App\\Exceptions\\Trackers\\Bugsnag'), 'beforeSend'],
|
||||||
|
|
||||||
];
|
];
|
||||||
|
@ -54,4 +54,8 @@ return [
|
|||||||
|
|
||||||
'controllers_base_namespace' => env('SENTRY_CONTROLLERS_BASE_NAMESPACE', 'App\\Http\\Controllers'),
|
'controllers_base_namespace' => env('SENTRY_CONTROLLERS_BASE_NAMESPACE', 'App\\Http\\Controllers'),
|
||||||
|
|
||||||
|
'before_send' => [env('SENTRY_BEFORE_SEND_CLASS', 'App\\Exceptions\\Trackers\\Sentry'), 'beforeSend'],
|
||||||
|
|
||||||
|
'traces_sampler' => [env('SENTRY_TRACES_SAMPLER_CLASS', 'App\\Exceptions\\Trackers\\Sentry'), 'tracesSampler'],
|
||||||
|
|
||||||
];
|
];
|
||||||
|
Loading…
x
Reference in New Issue
Block a user