From a3ee1d665936afd9a86b3bb5de519fa4420fad1a Mon Sep 17 00:00:00 2001 From: Leon Stam Date: Mon, 30 Sep 2019 15:07:30 +0200 Subject: [PATCH 1/2] Add the configuration option 'project_root'. This allows you to strip the deployment path from Bugsnag errors, normalising all paths across multiple deployments. See: https://docs.bugsnag.com/platforms/php/other/configuration-options/#project-root --- Helper/Config.php | 44 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 42 insertions(+), 2 deletions(-) diff --git a/Helper/Config.php b/Helper/Config.php index b59d8fd..f07c254 100644 --- a/Helper/Config.php +++ b/Helper/Config.php @@ -9,6 +9,7 @@ use Bugsnag\Configuration; use Magento\Framework\App\DeploymentConfig\Reader; use Magento\Framework\Config\File\ConfigFilePool; +use Magento\Framework\Filesystem\DirectoryList; class Config { @@ -19,6 +20,13 @@ class Config */ protected $deploymentConfig; + /** + * Magento's directory list used for fetching the root folder + * + * @var DirectoryList + */ + protected $directoryList; + /** * Full array of data from env.php * @@ -44,12 +52,18 @@ class Config * Config constructor * * @param Reader $deploymentConfig + * @param DirectoryList $directoryList + * + * @throws \Magento\Framework\Exception\FileSystemException + * @throws \Magento\Framework\Exception\RuntimeException */ public function __construct( - Reader $deploymentConfig + Reader $deploymentConfig, + DirectoryList $directoryList ) { $this->deploymentConfig = $deploymentConfig; + $this->directoryList = $directoryList; $this->env = $deploymentConfig->load(ConfigFilePool::APP_ENV); if(isset($this->env['bugsnag'])) { $this->bugsnagConfig = $this->env['bugsnag']; @@ -71,6 +85,12 @@ public function getConfiguration() if ($releaseStage) { $this->config->setReleaseStage($releaseStage); } + + $projectRoot = $this->getProjectRoot(); + if ($projectRoot) { + $this->config->setProjectRoot($projectRoot); + } + return $this->config; } } @@ -103,4 +123,24 @@ public function getReleaseStage() return false; } -} \ No newline at end of file + /** + * Get the project_root full path from env.php if existent. + * + * This can also be the boolval `true` if it should be resolved using Magento. + * + * @return bool|mixed|string + */ + public function getProjectRoot() { + if (array_key_exists('project_root', $this->bugsnagConfig)) { + $projectRoot = $this->bugsnagConfig['project_root']; + if ($projectRoot === true) { + // The root should be resolved by Magento + return $this->directoryList->getRoot(); + } else { + return $projectRoot; + } + } + return false; + } + +} From cd4cb990ba293b74e4f161b0decbd1a3968b5e28 Mon Sep 17 00:00:00 2001 From: Leon Stam Date: Mon, 30 Sep 2019 15:09:17 +0200 Subject: [PATCH 2/2] Update readme to mention project_root --- README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.md b/README.md index 37ecbfc..9d2317b 100644 --- a/README.md +++ b/README.md @@ -42,8 +42,13 @@ More information on [Release Stage](https://docs.bugsnag.com/platforms/php/other ... 'release_stage' => 'staging', ... + 'project_root' => true || '/path/to/magento', ), +You can set `project_root` to either `true` or the absolute path of the magento installation. +This will cause all paths in Bugsnag to be normalized across deployments and display the errors starting from the magento root. +When the value is set to true it will use Magento's DirectoryList to resolve the root folder. [See documentation on docs.bugsnag.com.](https://docs.bugsnag.com/platforms/php/other/configuration-options/#project-root) + # Support If you have any issues with this extension, open an issue on [GitHub](https://github.com/Interjar/bugsnag-magento2/issues).