From eb756d0c8dcb73950966e020d8ed9b94836ae578 Mon Sep 17 00:00:00 2001 From: Frederik Rommel Date: Wed, 7 Aug 2024 17:48:10 +0200 Subject: [PATCH] implement profiling --- Helper/Data.php | 6 ++++++ Plugin/GlobalExceptionCatcher.php | 4 ++++ README.md | 4 ++++ 3 files changed, 14 insertions(+) diff --git a/Helper/Data.php b/Helper/Data.php index 0f8d2cf..ed301b2 100644 --- a/Helper/Data.php +++ b/Helper/Data.php @@ -50,6 +50,7 @@ class Data extends AbstractHelper 'tracing_sample_rate', 'performance_tracking_enabled', 'performance_tracking_excluded_areas', + 'profiles_sample_rate', 'ignore_js_errors', ]; @@ -95,6 +96,11 @@ public function getTracingSampleRate(): float return (float) $this->config['tracing_sample_rate'] ?? 0.2; } + public function getPhpProfileSampleRate(): float + { + return (float) ($this->config['profiles_sample_rate'] ?? 0); + } + /** * @return array|null */ diff --git a/Plugin/GlobalExceptionCatcher.php b/Plugin/GlobalExceptionCatcher.php index 986606c..45e66b3 100755 --- a/Plugin/GlobalExceptionCatcher.php +++ b/Plugin/GlobalExceptionCatcher.php @@ -58,6 +58,10 @@ public function aroundLaunch(AppInterface $subject, callable $proceed) $config->setTracesSampleRate($this->sentryHelper->getTracingSampleRate()); } + if ($rate = $this->sentryHelper->getPhpProfileSampleRate()) { + $config->setData('profiles_sample_rate', $rate); + } + $this->eventManager->dispatch('sentry_before_init', [ 'config' => $config, ]); diff --git a/README.md b/README.md index dc30521..275302c 100644 --- a/README.md +++ b/README.md @@ -28,6 +28,7 @@ This module uses the [Magento Deployment Configuration](https://devdocs.magento. 'tracing_sample_rate' => 0.5, 'performance_tracking_enabled' => true, 'performance_tracking_excluded_areas' => ['adminhtml', 'crontab'], + 'profiles_sample_rate' => 0.5, 'ignore_js_errors' => [] ] ``` @@ -46,6 +47,7 @@ Next to that there are some configuration options under Stores > Configuration > * `tracing_sample_rate` if tracing is enabled, you should also set the sample rate. Default: `0.2` * `performance_tracking_enabled` if performance tracking is enabled, a performance report got generated for the request. Default: `false` * `performance_tracking_excluded_areas`: if `performance_tracking_enabled` is enabled, we recommend to exclude the `adminhtml` & `crontab` area. Default `['adminhtml', 'crontab']` +* `profiles_sample_rate` if this option is larger than 0 (zero), the module will create a profile of the request. Please note that you have to install [Excimer](https://www.mediawiki.org/wiki/Excimer) on your server to use profiling. [Sentry documentation](https://docs.sentry.io/platforms/php/profiling/). You have to enable tracing too. Default `0` (disabled) * `ignore_js_errors` array of javascript error messages, which should be not send to Sentry. (see also `ignoreErrors` in [Sentry documentation](https://docs.sentry.io/clients/javascript/config/)) ### Configuration for Adobe Cloud @@ -70,6 +72,8 @@ using the "Variables" in Adobe Commerce using the following variables: The following configuration settings can be overridden in the Magento admin. This is limited to ensure that changes to particular config settings can only be done on server level and can't be broken by changes in the admin. +Please note, that it is not possible to use profiling within the Adobe Cloud. + ## Optional error page configuration - Optional you can configure custom error pages in pub/errors. You can use the sentry feedback form and insert here the sentry log ID. The Sentry Log Id is captured in de customer session and can be retrieved in `processor.php`.