added sentry and bugsnag

This commit is contained in:
Denis Duliçi 2022-10-17 14:19:42 +03:00
parent 79dc3891a3
commit 350d189ea9
7 changed files with 1455 additions and 57 deletions

View File

@ -48,6 +48,40 @@ class Handler extends ExceptionHandler
'password_confirmation',
];
/**
* Register the exception handling callbacks for the application.
*
* @return void
*/
public function register()
{
$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') {
app('bugsnag')->registerCallback(function ($report) {
$report->setMetaData([
'akaunting' => [
'company_id' => (string) company_id(),
'locale' => (string) app()->getLocale(),
'timezone' => (string) config('app.timezone'),
]
]);
});
app('bugsnag')->setAppVersion(version('short'));
}
});
}
/**
* Report or log an exception.
*

View File

@ -44,6 +44,7 @@
"barryvdh/laravel-dompdf": "^2.0",
"barryvdh/laravel-ide-helper": "^2.9",
"bkwld/cloner": "^3.10",
"bugsnag/bugsnag-laravel": "^2.24",
"doctrine/dbal": "^3.1",
"fruitcake/laravel-cors": "^2.0",
"genealabs/laravel-model-caching": "0.12.*",
@ -67,6 +68,7 @@
"plank/laravel-mediable": "^5.4",
"riverskies/laravel-mobile-detect": "^1.3",
"santigarcor/laratrust": "^7.0",
"sentry/sentry-laravel": "^2.14",
"simple-icons/simple-icons": "^6.0",
"simshaun/recurr": "^5.0",
"staudenmeir/belongs-to-through": "^2.12",

1056
composer.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -180,6 +180,7 @@ return [
/*
* Package Service Providers...
*/
Bugsnag\BugsnagLaravel\BugsnagServiceProvider::class,
Laravel\Tinker\TinkerServiceProvider::class,
/*

352
config/bugsnag.php Normal file
View File

@ -0,0 +1,352 @@
<?php
return [
/*
|--------------------------------------------------------------------------
| API Key
|--------------------------------------------------------------------------
|
| You can find your API key on your Bugsnag dashboard.
|
| This api key points the Bugsnag notifier to the project in your account
| which should receive your application's uncaught exceptions.
|
*/
'api_key' => env('BUGSNAG_API_KEY', ''),
/*
|--------------------------------------------------------------------------
| App Type
|--------------------------------------------------------------------------
|
| Set the type of application executing the current code.
|
*/
'app_type' => env('BUGSNAG_APP_TYPE'),
/*
|--------------------------------------------------------------------------
| App Version
|--------------------------------------------------------------------------
|
| Set the version of application executing the current code.
|
*/
'app_version' => env('BUGSNAG_APP_VERSION'),
/*
|--------------------------------------------------------------------------
| Batch Sending
|--------------------------------------------------------------------------
|
| Set to true to send the errors through to Bugsnag when the PHP process
| shuts down, in order to prevent your app waiting on HTTP requests.
|
| Setting this to false will send an HTTP request straight away for each
| error.
|
*/
'batch_sending' => env('BUGSNAG_BATCH_SENDING', true),
/*
|--------------------------------------------------------------------------
| Endpoint
|--------------------------------------------------------------------------
|
| Set what server the Bugsnag notifier should send errors to. By default
| this is set to 'https://notify.bugsnag.com', but for Bugsnag Enterprise
| this should be the URL to your Bugsnag instance.
|
*/
'endpoint' => env('BUGSNAG_ENDPOINT'),
/*
|--------------------------------------------------------------------------
| Filters
|--------------------------------------------------------------------------
|
| Use this if you want to ensure you don't send sensitive data such as
| passwords, and credit card numbers to our servers. Any keys which
| contain these strings will be filtered.
|
| This option has been deprecated in favour of 'redacted_keys'
|
*/
'filters' => empty(env('BUGSNAG_FILTERS')) ? null : explode(',', str_replace(' ', '', env('BUGSNAG_FILTERS'))),
/*
|--------------------------------------------------------------------------
| Hostname
|--------------------------------------------------------------------------
|
| You can set the hostname of your server to something specific for you to
| identify it by if needed.
|
*/
'hostname' => env('BUGSNAG_HOSTNAME', env('APP_URL')),
/*
|--------------------------------------------------------------------------
| Proxy
|--------------------------------------------------------------------------
|
| This is where you can set the proxy settings you'd like us to use when
| communicating with Bugsnag when reporting errors.
|
*/
'proxy' => array_filter([
'http' => env('HTTP_PROXY'),
'https' => env('HTTPS_PROXY'),
'no' => empty(env('NO_PROXY')) ? null : explode(',', str_replace(' ', '', env('NO_PROXY'))),
]),
/*
|--------------------------------------------------------------------------
| Project Root
|--------------------------------------------------------------------------
|
| Bugsnag marks stacktrace lines as in-project if they come from files
| inside your “project root”. You can set this here.
|
| If this is not set, we will automatically try to detect it.
|
*/
'project_root' => env('BUGSNAG_PROJECT_ROOT'),
/*
|--------------------------------------------------------------------------
| Project Root Regex
|--------------------------------------------------------------------------
|
| Bugsnag marks stacktrace lines as in-project if they come from files
| inside your “project root”. You can set this here.
|
| This option allows you to set it as a regular expression and will take
| precedence over "project_root" if both are defined.
|
*/
'project_root_regex' => env('BUGSNAG_PROJECT_ROOT_REGEX'),
/*
|--------------------------------------------------------------------------
| Strip Path
|--------------------------------------------------------------------------
|
| The strip path is a path to be trimmed from the start of any filepaths in
| your stacktraces.
|
| If this is not set, we will automatically try to detect it.
|
*/
'strip_path' => env('BUGSNAG_STRIP_PATH'),
/*
|--------------------------------------------------------------------------
| Strip Path Regex
|--------------------------------------------------------------------------
|
| The strip path is a path to be trimmed from the start of any filepaths in
| your stacktraces.
|
| This option allows you to set it as a regular expression and will take
| precedence over "strip_path" if both are defined.
|
*/
'strip_path_regex' => env('BUGSNAG_STRIP_PATH_REGEX'),
/*
|--------------------------------------------------------------------------
| Query
|--------------------------------------------------------------------------
|
| Enable this if you'd like us to automatically record all queries executed
| as breadcrumbs.
|
*/
'query' => env('BUGSNAG_QUERY', true),
/*
|--------------------------------------------------------------------------
| Bindings
|--------------------------------------------------------------------------
|
| Enable this if you'd like us to include the query bindings in our query
| breadcrumbs.
|
*/
'bindings' => env('BUGSNAG_QUERY_BINDINGS', false),
/*
|--------------------------------------------------------------------------
| Release Stage
|--------------------------------------------------------------------------
|
| Set the release stage to use when sending notifications to Bugsnag.
|
| Leaving this unset will default to using the application environment.
|
*/
'release_stage' => env('BUGSNAG_RELEASE_STAGE'),
/*
|--------------------------------------------------------------------------
| Notify Release Stages
|--------------------------------------------------------------------------
|
| Set which release stages should send notifications to Bugsnag.
|
*/
'notify_release_stages' => empty(env('BUGSNAG_NOTIFY_RELEASE_STAGES')) ? null : explode(',', str_replace(' ', '', env('BUGSNAG_NOTIFY_RELEASE_STAGES'))),
/*
|--------------------------------------------------------------------------
| Send Code
|--------------------------------------------------------------------------
|
| Bugsnag automatically sends a small snippet of the code that crashed to
| help you diagnose even faster from within your dashboard. If you dont
| want to send this snippet, then set this to false.
|
*/
'send_code' => env('BUGSNAG_SEND_CODE', true),
/*
|--------------------------------------------------------------------------
| Callbacks
|--------------------------------------------------------------------------
|
| Enable this if you'd like us to enable our default set of notification
| callbacks. These add things like the cookie information and session
| details to the error to be sent to Bugsnag.
|
| If you'd like to add your own callbacks, you can call the
| Bugsnag::registerCallback method from the boot method of your app
| service provider.
|
*/
'callbacks' => env('BUGSNAG_CALLBACKS', true),
/*
|--------------------------------------------------------------------------
| User
|--------------------------------------------------------------------------
|
| Enable this if you'd like us to set the current user logged in via
| Laravel's authentication system.
|
| If you'd like to add your own user resolver, you can do this by using
| callbacks via Bugsnag::registerCallback.
|
*/
'user' => env('BUGSNAG_USER', true),
/*
|--------------------------------------------------------------------------
| Logger Notify Level
|--------------------------------------------------------------------------
|
| This sets the level at which a logged message will trigger a notification
| to Bugsnag. By default this level will be 'notice'.
|
| Must be one of the Psr\Log\LogLevel levels from the Psr specification.
|
*/
'logger_notify_level' => env('BUGSNAG_LOGGER_LEVEL'),
/*
|--------------------------------------------------------------------------
| Auto Capture Sessions
|--------------------------------------------------------------------------
|
| Enable this to start tracking sessions and deliver them to Bugsnag.
|
*/
'auto_capture_sessions' => env('BUGSNAG_CAPTURE_SESSIONS', false),
/*
|--------------------------------------------------------------------------
| Sessions Endpoint
|--------------------------------------------------------------------------
|
| Sets a url to send tracked sessions to.
|
*/
'session_endpoint' => env('BUGSNAG_SESSION_ENDPOINT'),
/*
|--------------------------------------------------------------------------
| Builds Endpoint
|--------------------------------------------------------------------------
|
| Sets a url to send build reports to.
|
*/
'build_endpoint' => env('BUGSNAG_BUILD_ENDPOINT'),
/*
|--------------------------------------------------------------------------
| Discard Classes
|--------------------------------------------------------------------------
|
| An array of classes that should not be sent to Bugsnag.
|
| This can contain both fully qualified class names and regular expressions.
|
*/
'discard_classes' => empty(env('BUGSNAG_DISCARD_CLASSES')) ? null : explode(',', env('BUGSNAG_DISCARD_CLASSES')),
/*
|--------------------------------------------------------------------------
| Redacted Keys
|--------------------------------------------------------------------------
|
| An array of metadata keys that should be redacted.
|
*/
'redacted_keys' => empty(env('BUGSNAG_REDACTED_KEYS')) ? null : explode(',', env('BUGSNAG_REDACTED_KEYS')),
/*
|--------------------------------------------------------------------------
| Feature flags
|--------------------------------------------------------------------------
|
| An array of feature flags to add to all reports.
|
| Each element in the array must have a "name" key and can optionally have a
| "variant" key, for example:
|
| [
| ['name' => 'example without a variant'],
| ['name' => 'example with a variant', 'variant' => 'example of a variant'],
| ]
|
*/
'feature_flags' => [],
];

View File

@ -128,6 +128,16 @@ return [
'path' => storage_path('logs/laravel.log'),
],
'bugsnag' => [
'driver' => 'bugsnag',
'level' => env('LOG_LEVEL', 'debug'),
],
'sentry' => [
'driver' => 'sentry',
'level' => env('LOG_LEVEL', 'debug'),
],
],
];

57
config/sentry.php Normal file
View File

@ -0,0 +1,57 @@
<?php
return [
'dsn' => env('SENTRY_LARAVEL_DSN', env('SENTRY_DSN')),
// capture release as git sha
// 'release' => trim(exec('git --git-dir ' . base_path('.git') . ' log --pretty="%h" -n1 HEAD'))
// When left empty or `null` the Laravel environment will be used
'environment' => env('SENTRY_ENVIRONMENT'),
'breadcrumbs' => [
// Capture Laravel logs in breadcrumbs
'logs' => true,
// Capture SQL queries in breadcrumbs
'sql_queries' => true,
// Capture bindings on SQL queries logged in breadcrumbs
'sql_bindings' => true,
// Capture queue job information in breadcrumbs
'queue_info' => true,
// Capture command information in breadcrumbs
'command_info' => true,
],
'tracing' => [
// Trace queue jobs as their own transactions
'queue_job_transactions' => env('SENTRY_TRACE_QUEUE_ENABLED', false),
// Capture queue jobs as spans when executed on the sync driver
'queue_jobs' => true,
// Capture SQL queries as spans
'sql_queries' => true,
// Try to find out where the SQL query originated from and add it to the query spans
'sql_origin' => true,
// Capture views as spans
'views' => true,
// Indicates if the tracing integrations supplied by Sentry should be loaded
'default_integrations' => true,
],
// @see: https://docs.sentry.io/platforms/php/configuration/options/#send-default-pii
'send_default_pii' => env('SENTRY_SEND_DEFAULT_PII', true),
'traces_sample_rate' => (float)(env('SENTRY_TRACES_SAMPLE_RATE', 1.0)),
'controllers_base_namespace' => env('SENTRY_CONTROLLERS_BASE_NAMESPACE', 'App\\Http\\Controllers'),
];