Akaunting/app/Exceptions/Trackers/Sentry.php

53 lines
1.1 KiB
PHP
Raw Normal View History

2022-10-18 22:29:40 +00:00
<?php
namespace App\Exceptions\Trackers;
2023-10-25 09:40:52 +00:00
use Akaunting\Version\Version;
use App\Traits\Trackers as Base;
2022-10-18 22:29:40 +00:00
use Illuminate\Support\Str;
use Sentry\Event;
use Sentry\EventHint;
use Sentry\Tracing\SamplingContext;
class Sentry
{
use Base;
2022-10-18 22:29:40 +00:00
public static function beforeSend(Event $event, ?EventHint $hint): ?Event
{
2023-10-25 09:40:52 +00:00
$event->setRelease(Version::short());
2022-10-18 22:29:40 +00:00
2022-11-22 12:00:33 +00:00
$tags = static::getTrackerTags();
$event->setTags($tags);
2022-10-18 22:29:40 +00:00
return $event;
}
public static function tracesSampler(SamplingContext $context): float
{
2022-10-19 06:25:18 +00:00
if (static::shouldFilterAgent()) {
2022-10-18 22:29:40 +00:00
return 0.0;
}
return config('sentry.traces_sample_rate');
}
2022-10-19 06:25:18 +00:00
public static function shouldFilterAgent(): bool
2022-10-18 22:29:40 +00: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;
}
}