Changed javascipt exception tracker method..
This commit is contained in:
parent
8602a1f478
commit
1c93c7a11e
@ -2,28 +2,23 @@
|
|||||||
|
|
||||||
namespace App\Exceptions\Trackers;
|
namespace App\Exceptions\Trackers;
|
||||||
|
|
||||||
|
use App\Traits\Trackers as Base;
|
||||||
use Throwable;
|
use Throwable;
|
||||||
|
|
||||||
class Bugsnag
|
class Bugsnag
|
||||||
{
|
{
|
||||||
|
use Base;
|
||||||
|
|
||||||
public static function beforeSend(Throwable $e): void
|
public static function beforeSend(Throwable $e): void
|
||||||
{
|
{
|
||||||
app('bugsnag')->setAppVersion(version('short'));
|
app('bugsnag')->setAppVersion(version('short'));
|
||||||
|
|
||||||
app('bugsnag')->registerCallback(function ($report) {
|
$tags = $this->getTrackerTags();
|
||||||
|
|
||||||
|
app('bugsnag')->registerCallback(function ($report) use($tags) {
|
||||||
$report->setMetaData([
|
$report->setMetaData([
|
||||||
'akaunting' => [
|
'akaunting' => $tags
|
||||||
'company_id' => (string) company_id(),
|
|
||||||
'locale' => (string) app()->getLocale(),
|
|
||||||
'timezone' => (string) config('app.timezone'),
|
|
||||||
'route_name' => (string) static::getRouteName(),
|
|
||||||
]
|
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getRouteName(): ?string
|
|
||||||
{
|
|
||||||
return request()->route()?->getName();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace App\Exceptions\Trackers;
|
namespace App\Exceptions\Trackers;
|
||||||
|
|
||||||
|
use App\Traits\Trackers as Base;
|
||||||
use Illuminate\Support\Str;
|
use Illuminate\Support\Str;
|
||||||
use Sentry\Event;
|
use Sentry\Event;
|
||||||
use Sentry\EventHint;
|
use Sentry\EventHint;
|
||||||
@ -9,17 +10,15 @@ use Sentry\Tracing\SamplingContext;
|
|||||||
|
|
||||||
class Sentry
|
class Sentry
|
||||||
{
|
{
|
||||||
|
use Base;
|
||||||
|
|
||||||
public static function beforeSend(Event $event, ?EventHint $hint): ?Event
|
public static function beforeSend(Event $event, ?EventHint $hint): ?Event
|
||||||
{
|
{
|
||||||
$event->setRelease(version('short'));
|
$event->setRelease(version('short'));
|
||||||
|
|
||||||
$event->setTags([
|
$tags = $this->getTrackerTags();
|
||||||
'company_id' => (string) company_id(),
|
|
||||||
'locale' => (string) app()->getLocale(),
|
$event->setTags($tags);
|
||||||
'timezone' => (string) config('app.timezone'),
|
|
||||||
'app_type' => (string) static::getAppType(),
|
|
||||||
'route_name' => (string) static::getRouteName(),
|
|
||||||
]);
|
|
||||||
|
|
||||||
return $event;
|
return $event;
|
||||||
}
|
}
|
||||||
@ -49,28 +48,4 @@ class Sentry
|
|||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getAppType(): string
|
|
||||||
{
|
|
||||||
$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;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function getRouteName(): ?string
|
|
||||||
{
|
|
||||||
return request()->route()?->getName();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
43
app/Traits/Trackers.php
Normal file
43
app/Traits/Trackers.php
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Traits;
|
||||||
|
|
||||||
|
use Illuminate\Support\Str;
|
||||||
|
|
||||||
|
trait Trackers
|
||||||
|
{
|
||||||
|
public function getTrackerTags(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'company_id' => (string) company_id(),
|
||||||
|
'locale' => (string) app()->getLocale(),
|
||||||
|
'timezone' => (string) config('app.timezone'),
|
||||||
|
'app_type' => (string) static::getAppType(),
|
||||||
|
'route_name' => (string) static::getRouteName(),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getAppType(): string
|
||||||
|
{
|
||||||
|
$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;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getRouteName(): ?string
|
||||||
|
{
|
||||||
|
return request()->route()?->getName();
|
||||||
|
}
|
||||||
|
}
|
132
app/View/Components/Script/Exceptions/Trackers.php
Normal file
132
app/View/Components/Script/Exceptions/Trackers.php
Normal file
@ -0,0 +1,132 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\View\Components\Script\Exceptions;
|
||||||
|
|
||||||
|
use App\Abstracts\View\Component;
|
||||||
|
use App\Utilities\Info;
|
||||||
|
use App\Traits\Trackers as Base;
|
||||||
|
use Illuminate\Support\Str;
|
||||||
|
|
||||||
|
class Trackers extends Component
|
||||||
|
{
|
||||||
|
use Base;
|
||||||
|
|
||||||
|
public $channel;
|
||||||
|
|
||||||
|
public $action;
|
||||||
|
|
||||||
|
public $ip;
|
||||||
|
|
||||||
|
public $tags;
|
||||||
|
|
||||||
|
public $params;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new component instance.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function __construct(
|
||||||
|
string $channel = null, string $action = null, string $ip = null, $tags = [], $params = []
|
||||||
|
) {
|
||||||
|
$this->channel = $this->getChannel($channel);
|
||||||
|
$this->action = $this->getAction($action);
|
||||||
|
$this->ip = $this->getIp($ip);
|
||||||
|
$this->tags = $this->getTags($tags);
|
||||||
|
$this->params = $this->getParams($params);
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Get the view / contents that represent the component.
|
||||||
|
*
|
||||||
|
* @return \Illuminate\Contracts\View\View|string
|
||||||
|
*/
|
||||||
|
public function render()
|
||||||
|
{
|
||||||
|
return view('components.script.exceptions.trackers');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getChannel($channel)
|
||||||
|
{
|
||||||
|
if (! empty($channel)) {
|
||||||
|
return $channel;
|
||||||
|
}
|
||||||
|
|
||||||
|
return config('logging.default');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getAction($action)
|
||||||
|
{
|
||||||
|
if (! empty($action)) {
|
||||||
|
return $action;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch ($this->channel) {
|
||||||
|
case 'bugsnag':
|
||||||
|
$action = config('bugsnag.api_key');
|
||||||
|
break;
|
||||||
|
case 'sentry':
|
||||||
|
$action = config('sentry.dsn');
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $action;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getIp($ip)
|
||||||
|
{
|
||||||
|
if (! empty($ip)) {
|
||||||
|
return $ip;
|
||||||
|
}
|
||||||
|
|
||||||
|
return Info::ip();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getTags($tags)
|
||||||
|
{
|
||||||
|
if (! empty($tags)) {
|
||||||
|
return $tags;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->getTrackerTags();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getParams($params)
|
||||||
|
{
|
||||||
|
if (! empty($params)) {
|
||||||
|
return $params;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch ($this->channel) {
|
||||||
|
case 'bugsnag':
|
||||||
|
$params = [
|
||||||
|
'app_version' => version('short'),
|
||||||
|
];
|
||||||
|
break;
|
||||||
|
case 'sentry':
|
||||||
|
$params = [
|
||||||
|
'release' => version('short'),
|
||||||
|
'traces_sample_rate' => $this->sentryTracesSampleRate(),
|
||||||
|
];
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $params;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function sentryTracesSampleRate()
|
||||||
|
{
|
||||||
|
$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 0.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (float) config('sentry.traces_sample_rate', 1.0);
|
||||||
|
}
|
||||||
|
}
|
1
resources/assets/js/exceptions/trackers/bugsnag.js
vendored
Normal file
1
resources/assets/js/exceptions/trackers/bugsnag.js
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
// Will added as soon as possible
|
34
resources/assets/js/exceptions/trackers/sentry.js
vendored
Normal file
34
resources/assets/js/exceptions/trackers/sentry.js
vendored
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
import * as Sentry from "@sentry/vue";
|
||||||
|
import { BrowserTracing } from "@sentry/tracing";
|
||||||
|
|
||||||
|
export default {
|
||||||
|
install(Vue) {
|
||||||
|
alert(exception_tracker.params.traces_sample_rate);
|
||||||
|
|
||||||
|
Sentry.init({
|
||||||
|
Vue,
|
||||||
|
dsn: exception_tracker.action,
|
||||||
|
logErrors: true,
|
||||||
|
integrations: [
|
||||||
|
new BrowserTracing({
|
||||||
|
tracingOrigins: [],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
// Set tracesSampleRate to 1.0 to capture 100%
|
||||||
|
// of transactions for performance monitoring.
|
||||||
|
// We recommend adjusting this value in production
|
||||||
|
tracesSampleRate: exception_tracker.params.traces_sample_rate,
|
||||||
|
});
|
||||||
|
|
||||||
|
Sentry.setUser({
|
||||||
|
id: exception_tracker.user.id,
|
||||||
|
username: exception_tracker.user.name,
|
||||||
|
email: exception_tracker.user.email,
|
||||||
|
ip_address: exception_tracker.ip,
|
||||||
|
});
|
||||||
|
|
||||||
|
for (const [key, value] of Object.entries(exception_tracker.tags)) {
|
||||||
|
Sentry.setTag(key, value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
34
resources/assets/js/mixins/global.js
vendored
34
resources/assets/js/mixins/global.js
vendored
@ -38,30 +38,20 @@ import GLightbox from 'glightbox';
|
|||||||
|
|
||||||
Swiper.use([Navigation, Pagination]);
|
Swiper.use([Navigation, Pagination]);
|
||||||
|
|
||||||
//sentry integration
|
import Bugsnag from './../exceptions/trackers/bugsnag';
|
||||||
import * as Sentry from "@sentry/vue";
|
import Sentry from './../exceptions/trackers/sentry';
|
||||||
import { BrowserTracing } from "@sentry/tracing";
|
|
||||||
|
|
||||||
if (sentry_dsn && sentry_dsn != '' && sentry_dsn != undefined) {
|
// Exception Tracket start here!!s
|
||||||
Sentry.init({
|
if (typeof exception_tracker != 'undefined') {
|
||||||
Vue,
|
switch (exception_tracker.channel) {
|
||||||
dsn: sentry_dsn,
|
case 'bugsnag':
|
||||||
logErrors: true,
|
Vue.use(Bugsnag);
|
||||||
integrations: [
|
break;
|
||||||
new BrowserTracing({
|
case 'sentry':
|
||||||
tracingOrigins: [],
|
Vue.use(Sentry);
|
||||||
}),
|
break;
|
||||||
],
|
}
|
||||||
// Set tracesSampleRate to 1.0 to capture 100%
|
|
||||||
// of transactions for performance monitoring.
|
|
||||||
// We recommend adjusting this value in production
|
|
||||||
tracesSampleRate: 1.0,
|
|
||||||
});
|
|
||||||
|
|
||||||
Sentry.setUser(sentry_user[0]);
|
|
||||||
Sentry.setTag("sentry_tag", "here");
|
|
||||||
}
|
}
|
||||||
//sentry integration
|
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
components: {
|
components: {
|
||||||
|
@ -41,17 +41,10 @@
|
|||||||
var url = '{{ url("/" . company_id()) }}';
|
var url = '{{ url("/" . company_id()) }}';
|
||||||
var app_url = '{{ config("app.url") }}';
|
var app_url = '{{ config("app.url") }}';
|
||||||
var aka_currency = {!! !empty($currency) ? $currency : 'false' !!};
|
var aka_currency = {!! !empty($currency) ? $currency : 'false' !!};
|
||||||
var sentry_dsn = "https://9ffc5a5f104d4087911f60714e8bdbe9@o4503982427078656.ingest.sentry.io/4503999793594368";
|
|
||||||
var sentry_user = [
|
|
||||||
{
|
|
||||||
id: 34,
|
|
||||||
email: "burak@akaunting.com",
|
|
||||||
username: "brkcvn",
|
|
||||||
ip_address: "http://akaunting_v5.test/1"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
//--></script>
|
//--></script>
|
||||||
|
|
||||||
|
<x-script.exceptions.trackers />
|
||||||
|
|
||||||
@stack('js')
|
@stack('js')
|
||||||
|
|
||||||
<script type="text/javascript"><!--
|
<script type="text/javascript"><!--
|
||||||
|
@ -61,9 +61,10 @@
|
|||||||
var app_home = '{{ route("apps.home.index") }}';
|
var app_home = '{{ route("apps.home.index") }}';
|
||||||
var app_url = '{{ config("app.url") }}';
|
var app_url = '{{ config("app.url") }}';
|
||||||
var aka_currency = {!! !empty($currency) ? $currency : 'false' !!};
|
var aka_currency = {!! !empty($currency) ? $currency : 'false' !!};
|
||||||
var sentry_dsn = "https://9ffc5a5f104d4087911f60714e8bdbe9@o4503982427078656.ingest.sentry.io/4503999793594368";
|
|
||||||
//--></script>
|
//--></script>
|
||||||
|
|
||||||
|
<x-script.exceptions.trackers />
|
||||||
|
|
||||||
@stack('js')
|
@stack('js')
|
||||||
|
|
||||||
<script type="text/javascript"><!--
|
<script type="text/javascript"><!--
|
||||||
|
@ -40,9 +40,10 @@
|
|||||||
var url = '{{ url("/" . company_id()) }}';
|
var url = '{{ url("/" . company_id()) }}';
|
||||||
var app_url = '{{ config("app.url") }}';
|
var app_url = '{{ config("app.url") }}';
|
||||||
var aka_currency = {!! !empty($currency) ? $currency : 'false' !!};
|
var aka_currency = {!! !empty($currency) ? $currency : 'false' !!};
|
||||||
var sentry_dsn = "https://9ffc5a5f104d4087911f60714e8bdbe9@o4503982427078656.ingest.sentry.io/4503999793594368";
|
|
||||||
//--></script>
|
//--></script>
|
||||||
|
|
||||||
|
<x-script.exceptions.trackers />
|
||||||
|
|
||||||
@stack('js')
|
@stack('js')
|
||||||
|
|
||||||
<script type="text/javascript"><!--
|
<script type="text/javascript"><!--
|
||||||
|
@ -40,9 +40,10 @@
|
|||||||
var url = '{{ url("/" . company_id()) }}';
|
var url = '{{ url("/" . company_id()) }}';
|
||||||
var app_url = '{{ config("app.url") }}';
|
var app_url = '{{ config("app.url") }}';
|
||||||
var aka_currency = {!! !empty($currency) ? $currency : 'false' !!};
|
var aka_currency = {!! !empty($currency) ? $currency : 'false' !!};
|
||||||
var sentry_dsn = "https://9ffc5a5f104d4087911f60714e8bdbe9@o4503982427078656.ingest.sentry.io/4503999793594368";
|
|
||||||
//--></script>
|
//--></script>
|
||||||
|
|
||||||
|
<x-script.exceptions.trackers />
|
||||||
|
|
||||||
@stack('js')
|
@stack('js')
|
||||||
|
|
||||||
<script type="text/javascript"><!--
|
<script type="text/javascript"><!--
|
||||||
|
@ -40,9 +40,10 @@
|
|||||||
var url = '{{ url("/" . company_id()) }}';
|
var url = '{{ url("/" . company_id()) }}';
|
||||||
var app_url = '{{ config("app.url") }}';
|
var app_url = '{{ config("app.url") }}';
|
||||||
var aka_currency = {!! !empty($currency) ? $currency : 'false' !!};
|
var aka_currency = {!! !empty($currency) ? $currency : 'false' !!};
|
||||||
var sentry_dsn = "https://9ffc5a5f104d4087911f60714e8bdbe9@o4503982427078656.ingest.sentry.io/4503999793594368";
|
|
||||||
//--></script>
|
//--></script>
|
||||||
|
|
||||||
|
<x-script.exceptions.trackers />
|
||||||
|
|
||||||
@stack('js')
|
@stack('js')
|
||||||
|
|
||||||
<script type="text/javascript"><!--
|
<script type="text/javascript"><!--
|
||||||
|
@ -37,9 +37,10 @@
|
|||||||
var url = '{{ url("/" . company_id()) }}';
|
var url = '{{ url("/" . company_id()) }}';
|
||||||
var app_url = '{{ config("app.url") }}';
|
var app_url = '{{ config("app.url") }}';
|
||||||
var aka_currency = {!! !empty($currency) ? $currency : 'false' !!};
|
var aka_currency = {!! !empty($currency) ? $currency : 'false' !!};
|
||||||
var sentry_dsn = "https://9ffc5a5f104d4087911f60714e8bdbe9@o4503982427078656.ingest.sentry.io/4503999793594368";
|
|
||||||
//--></script>
|
//--></script>
|
||||||
|
|
||||||
|
<x-script.exceptions.trackers />
|
||||||
|
|
||||||
@stack('js')
|
@stack('js')
|
||||||
|
|
||||||
<script type="text/javascript"><!--
|
<script type="text/javascript"><!--
|
||||||
|
@ -0,0 +1,16 @@
|
|||||||
|
@if (in_array($channel, ['bugsnag', 'sentry']))
|
||||||
|
<script type="text/javascript"><!--
|
||||||
|
var exception_tracker = {
|
||||||
|
channel: '{{ $channel }}',
|
||||||
|
action: '{{ $action }}',
|
||||||
|
user: {
|
||||||
|
id: '{{ user_id() }}',
|
||||||
|
name: '{{ user()?->name }}',
|
||||||
|
email: '{{ user()?->email }}',
|
||||||
|
},
|
||||||
|
ip: '{{ $ip }}',
|
||||||
|
tags: {!! json_encode($tags) !!},
|
||||||
|
params: {!! json_encode($params) !!},
|
||||||
|
};
|
||||||
|
//--></script>
|
||||||
|
@endif
|
Loading…
x
Reference in New Issue
Block a user