From 05bb976c27e829014ede823a418ac2a4c899d976 Mon Sep 17 00:00:00 2001 From: Edward Hibbert Date: Thu, 24 Jun 2021 10:08:57 +0100 Subject: [PATCH 1/3] Enable Sentry for Laravel and Vue --- .env.example | 3 ++ app/Exceptions/Handler.php | 9 ++++++ composer.json | 3 +- config/sentry.php | 57 ++++++++++++++++++++++++++++++++++++++ package.json | 2 ++ resources/js/app.js | 12 ++++++++ 6 files changed, 85 insertions(+), 1 deletion(-) create mode 100644 config/sentry.php diff --git a/.env.example b/.env.example index 971d9ab75a..47680aec97 100644 --- a/.env.example +++ b/.env.example @@ -85,3 +85,6 @@ DRIP_ACCOUNT_ID= DRIP_CAMPAIGN_ID= CALENDAR_HASH=somehash + +SENTRY_LARAVEL_DSN=https://50fd2fa440af4bb4a230f40ca8d8cf90@o879179.ingest.sentry.io/5831645 +SENTRY_TRACES_SAMPLE_RATE=1 \ No newline at end of file diff --git a/app/Exceptions/Handler.php b/app/Exceptions/Handler.php index de1cdab2fe..2e124ad9a0 100644 --- a/app/Exceptions/Handler.php +++ b/app/Exceptions/Handler.php @@ -43,4 +43,13 @@ public function render($request, Exception $exception) return parent::render($request, $exception); } + + public function report(Exception $exception) + { + if (app()->bound('sentry') && $this->shouldReport($exception)) { + app('sentry')->captureException($exception); + } + + parent::report($exception); + } } diff --git a/composer.json b/composer.json index 413d5f69bc..0976c2f24b 100644 --- a/composer.json +++ b/composer.json @@ -17,7 +17,7 @@ "egulias/email-validator": "2.1.25", "fideloper/proxy": "^4.0", "filp/whoops": "^2.9", - "fzaninotto/faker": "1.9.1", + "fzaninotto/faker": "1.9.2", "guzzlehttp/guzzle": "^6.3", "hieu-le/wordpress-xmlrpc-client": "~2.0", "intervention/image": "^2.4", @@ -31,6 +31,7 @@ "mcamara/laravel-localization": "^1.3", "msurguy/honeypot": "^1.0", "owen-it/laravel-auditing": "^8.0", + "sentry/sentry-laravel": "^2.7", "soundasleep/html2text": "^1.1", "spatie/calendar-links": "^1.2", "spinen/laravel-discourse-sso": "^1.3", diff --git a/config/sentry.php b/config/sentry.php new file mode 100644 index 0000000000..0f2c2e1690 --- /dev/null +++ b/config/sentry.php @@ -0,0 +1,57 @@ + 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' => false, + + 'traces_sample_rate' => (float)(env('SENTRY_TRACES_SAMPLE_RATE', 0.0)), + + 'controllers_base_namespace' => env('SENTRY_CONTROLLERS_BASE_NAMESPACE', 'App\\Http\\Controllers'), + +]; diff --git a/package.json b/package.json index 01dacaee9d..0322975e9e 100644 --- a/package.json +++ b/package.json @@ -26,6 +26,8 @@ "webpack-shell-plugin": "^0.5.0" }, "dependencies": { + "@sentry/tracing": "^6.7.2", + "@sentry/vue": "^6.7.2", "ajv": "^6.5.4", "bootstrap-fileinput": "^4.4.9", "bootstrap-select": "^1.13.17", diff --git a/resources/js/app.js b/resources/js/app.js index c79b060f4b..2c22815694 100644 --- a/resources/js/app.js +++ b/resources/js/app.js @@ -29,6 +29,8 @@ import L from 'leaflet' import 'leaflet/dist/leaflet.css' import Multiselect from 'vue-multiselect' import 'vue-multiselect/dist/vue-multiselect.min.css' +import * as Sentry from "@sentry/vue"; +import { Integrations } from "@sentry/tracing"; // Without this, the default map marker doesn't appear in production. Fairly well-known problem. // eslint-disable-next-line @@ -1550,6 +1552,16 @@ jQuery(document).ready(function () { lastScrollPosition = currentScrollPosition }) + // Sentry error + Sentry.init({ + Vue, + dsn: "https://50fd2fa440af4bb4a230f40ca8d8cf90@o879179.ingest.sentry.io/5831645", + integrations: [new Integrations.BrowserTracing()], + + // We are low traffic, so we can capture all performance events. + tracesSampleRate: 1.0, + }); + // Vue. // // Create a mixin for translation. From 9a0a0481e194ac9b596e619ed6472b098ef76fc6 Mon Sep 17 00:00:00 2001 From: Edward Hibbert Date: Thu, 24 Jun 2021 10:24:17 +0100 Subject: [PATCH 2/3] Disable Sentry for Laravel development environment --- app/Exceptions/Handler.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Exceptions/Handler.php b/app/Exceptions/Handler.php index 2e124ad9a0..30c83fdb74 100644 --- a/app/Exceptions/Handler.php +++ b/app/Exceptions/Handler.php @@ -46,7 +46,7 @@ public function render($request, Exception $exception) public function report(Exception $exception) { - if (app()->bound('sentry') && $this->shouldReport($exception)) { + if (app()->bound('sentry') && app()->environment('production') && $this->shouldReport($exception)) { app('sentry')->captureException($exception); } From 3edd18bde2d50a246e3e8fb626e95435ae6f7688 Mon Sep 17 00:00:00 2001 From: Edward Hibbert Date: Thu, 24 Jun 2021 11:10:08 +0100 Subject: [PATCH 3/3] Disable Sentry for Vue development environment --- resources/js/app.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/resources/js/app.js b/resources/js/app.js index 2c22815694..784ab26bda 100644 --- a/resources/js/app.js +++ b/resources/js/app.js @@ -1560,6 +1560,13 @@ jQuery(document).ready(function () { // We are low traffic, so we can capture all performance events. tracesSampleRate: 1.0, + + beforeSend(event) { + // Suppress development logs.. + if (process.env.NODE_ENV === 'development') { + return null + } + } }); // Vue. @@ -1623,3 +1630,4 @@ jQuery(document).ready(function () { }) $(".vue-placeholder-large").hide() }) +