2022-10-19 01:29:40 +03:00
|
|
|
<?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'),
|
2022-10-19 09:25:18 +03:00
|
|
|
'app_type' => (string) static::getAppType(),
|
2022-10-19 14:41:56 +03:00
|
|
|
'route_name' => (string) static::getRouteName(),
|
2022-10-19 01:29:40 +03:00
|
|
|
]);
|
|
|
|
|
|
|
|
return $event;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function tracesSampler(SamplingContext $context): float
|
|
|
|
{
|
2022-10-19 09:25:18 +03:00
|
|
|
if (static::shouldFilterAgent()) {
|
2022-10-19 01:29:40 +03:00
|
|
|
return 0.0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return config('sentry.traces_sample_rate');
|
|
|
|
}
|
|
|
|
|
2022-10-19 09:25:18 +03:00
|
|
|
public static function shouldFilterAgent(): bool
|
2022-10-19 01:29:40 +03:00
|
|
|
{
|
|
|
|
$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;
|
|
|
|
}
|
2022-10-19 09:25:18 +03:00
|
|
|
|
2022-10-19 09:26:30 +03:00
|
|
|
public static function getAppType(): string
|
2022-10-19 09:25:18 +03:00
|
|
|
{
|
|
|
|
$hostname = gethostname();
|
|
|
|
|
|
|
|
if (Str::contains($hostname, '-queue-')) {
|
|
|
|
$app_type = 'queue';
|
|
|
|
} elseif (Str::contains($hostname, '-cron-')) {
|
|
|
|
$app_type = 'cron';
|
|
|
|
} elseif (request()->isApi()) {
|
|
|
|
$app_type = 'api';
|
|
|
|
} elseif (app()->runningInConsole()) {
|
|
|
|
$app_type = 'console';
|
|
|
|
} else {
|
|
|
|
$app_type = 'ui';
|
|
|
|
}
|
|
|
|
|
|
|
|
return $app_type;
|
|
|
|
}
|
2022-10-19 14:41:56 +03:00
|
|
|
|
|
|
|
public static function getRouteName(): ?string
|
|
|
|
{
|
2022-10-19 15:40:46 +03:00
|
|
|
return request()->route()?->getName();
|
2022-10-19 14:41:56 +03:00
|
|
|
}
|
2022-10-19 01:29:40 +03:00
|
|
|
}
|