Skip to content

Commit

Permalink
Merge pull request #2 from justbetter/master
Browse files Browse the repository at this point in the history
Merge head repo
  • Loading branch information
DominicWatts committed Nov 19, 2019
2 parents e03cd0f + 8a5598e commit f0201aa
Show file tree
Hide file tree
Showing 14 changed files with 92 additions and 117 deletions.
19 changes: 19 additions & 0 deletions Block/Adminhtml/System/Config/DeploymentConfigInfo.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace JustBetter\Sentry\Block\Adminhtml\System\Config;

use Magento\Config\Block\System\Config\Form\Field;
use Magento\Framework\Data\Form\Element\AbstractElement;

class DeploymentConfigInfo extends Field
{
/**
* @var string
*/
protected $_template = 'system/config/deployment-config-info.phtml';

public function render(AbstractElement $element)
{
return $this->_toHtml();
}
}
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
CHANGELOG

2019-11-19 - 2.0.0

* Merged PR (https://github.com/justbetter/magento2-sentry/pull/29) thanks to https://github.com/michielgerritsen
* Merged PR (https://github.com/justbetter/magento2-sentry/pull/26) thanks to https://github.com/JosephMaxwell
* Merged PR (https://github.com/justbetter/magento2-sentry/pull/27) thanks to https://github.com/DominicWatts

2019-08-29 - 0.8.0

* Merged PR (https://github.com/justbetter/magento2-sentry/pull/24) thanks to https://github.com/kyriog
* Merged PR (https://github.com/justbetter/magento2-sentry/pull/22) thanks to https://github.com/fredden
* Merged PR (https://github.com/justbetter/magento2-sentry/pull/21) thanks to https://github.com/erikhansen

2019-06-19 - 0.7.2

* Reverted async attribute
Expand Down
4 changes: 3 additions & 1 deletion Controller/Adminhtml/Test/Sentry.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,9 @@ public function execute()
if ($sentryDomain && is_dir($composerBin)) {
try {
$result['status'] = true;
$result['content'] = nl2br(shell_exec($composerBin . 'sentry test ' . escapeshellarg($sentryDomain) . ' -v'));
$result['content'] = nl2br(shell_exec(
$composerBin . 'sentry test ' . escapeshellarg($sentryDomain) . ' -v'
));
} catch (\Exception $e) {
$result['content'] = $e->getMessage();
$this->logger->critical($e);
Expand Down
31 changes: 19 additions & 12 deletions Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Magento\Framework\App\Helper\AbstractHelper;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\App\ProductMetadataInterface;
use Magento\Framework\App\DeploymentConfig;

class Data extends AbstractHelper
{
Expand All @@ -25,12 +26,9 @@ class Data extends AbstractHelper
*/
protected $configKeys = [
'domain',
'enabled',
'log_level',
'mage_mode_development',
'environment',
'enable_script_tag',
'script_tag_placement',
];

/**
Expand All @@ -50,12 +48,18 @@ class Data extends AbstractHelper
* @param StoreManagerInterface $storeManager
* @param State $appState
*/
public function __construct(Context $context, StoreManagerInterface $storeManager, State $appState, ProductMetadataInterface $productMetadataInterface)
{
public function __construct(
Context $context,
StoreManagerInterface $storeManager,
State $appState,
ProductMetadataInterface $productMetadataInterface,
DeploymentConfig $deploymentConfig
) {
$this->storeManager = $storeManager;
$this->appState = $appState;
$this->scopeConfig = $context->getScopeConfig();
$this->productMetadataInterface = $productMetadataInterface;
$this->deploymentConfig = $deploymentConfig;
$this->collectModuleConfig();

parent::__construct($context);
Expand All @@ -66,15 +70,15 @@ public function __construct(Context $context, StoreManagerInterface $storeManage
*/
public function getDSN()
{
return $this->getGeneralConfig('domain');
return $this->config['domain'];
}

/**
* @return mixed
*/
public function getEnvironment()
{
return $this->getGeneralConfig('environment');
return $this->config['environment'];
}

/**
Expand Down Expand Up @@ -106,8 +110,10 @@ public function getGeneralConfig($code, $storeId = null)
*/
public function collectModuleConfig()
{
foreach ($this->configKeys as $key => $value) {
$this->config[ $value ] = $this->getGeneralConfig($value);
$this->config['enabled'] = $this->deploymentConfig->get('sentry') !== null;

foreach ($this->configKeys as $value) {
$this->config[$value] = $this->deploymentConfig->get('sentry/' . $value);
}

return $this->config;
Expand Down Expand Up @@ -172,7 +178,7 @@ public function getStore()
*/
public function useScriptTag()
{
return isset($this->config['enable_script_tag']) && $this->config['enable_script_tag'];
return $this->scopeConfig->isSetFlag(static::XML_PATH_SRS . 'enable_script_tag');
}

/**
Expand All @@ -181,11 +187,12 @@ public function useScriptTag()
*/
public function showScriptTagInThisBlock($blockName)
{
if (!isset($this->config['script_tag_placement'])) {
$config = $this->getGeneralConfig('script_tag_placement');
if (!$config) {
return false;
}

$name = 'sentry.' . $this->config['script_tag_placement'];
$name = 'sentry.' . $config;

return $name == $blockName;
}
Expand Down
1 change: 1 addition & 0 deletions Model/SentryLog.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class SentryLog extends Monolog
* @var array
*/
protected $config = [];

/** @var State */
private $appState;

Expand Down
7 changes: 4 additions & 3 deletions Plugin/GlobalExceptionCatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@

namespace JustBetter\Sentry\Plugin;

use JustBetter\Sentry\Helper\Data as SenteryHelper;
use Magento\Framework\App\Http;
use Magento\Framework\AppInterface;
use JustBetter\Sentry\Model\ReleaseIdentifier;
use JustBetter\Sentry\Model\SentryInteraction;
use Magento\Framework\App\Http;
use JustBetter\Sentry\Helper\Data as SenteryHelper;

class GlobalExceptionCatcher
{
Expand Down Expand Up @@ -34,7 +35,7 @@ public function __construct(
$this->sentryInteraction = $sentryInteraction;
}

public function aroundLaunch(\Magento\Framework\AppInterface $subject, callable $proceed)
public function aroundLaunch(AppInterface $subject, callable $proceed)
{
if (!$this->sentryHelper->isActive()) {
return $proceed();
Expand Down
64 changes: 0 additions & 64 deletions Plugin/HttpExceptionCatcher.php

This file was deleted.

20 changes: 15 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,21 @@ This Magento 2 module integrates the [Sentry sdk](https://github.com/getsentry/s
- `bin/magento setup:static-content:deploy`

## Configuration
- Options for the module are defined in the backend under Stores > Configuration > JustBetter > Sentry configuration
This module uses the [Magento Deployment Configuration](https://devdocs.magento.com/guides/v2.3/config-guide/config/config-php.html) for most it's configuration. This means that you need to add this array to your `app/etc/env.php`:

```
'sentry' => [
'domain' => 'example.com',
'environment' => null,
'log_level' => \Monolog\Logger::WARNING,
'isOverwriteProductionMode' => false,
]
```

Next to that there are some configuration options under Stores > Configuration > JustBetter > Sentry.

## 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`. Soon I'll integrate this in the module.
- 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`. Soon(2020-Q1) I'll integrate this in the module.

## Compability
The module is tested on Magento version 2.2.x & 2.3.x with sentry sdk version 2.x. Magento 2.1.x is not supported by us anymore, feel free to fork this project or make a pull request.
Expand All @@ -22,9 +33,8 @@ The module is tested on Magento version 2.2.x & 2.3.x with sentry sdk version 2.
Please create a [issue](https://github.com/justbetter/magento2-sentry/issues) or a [pull request](https://github.com/justbetter/magento2-sentry/pulls).

## Todo
- Integrate custom error pages in composer package
- Integrate feedback sentry form in error pages
- Integrate Raven Client options described here: [sentry-php](https://github.com/getsentry/sentry-php/blob/master/docs/config.rst)
- Integrate custom error pages in composer package - 2020-Q1
- Integrate feedback sentry form in error pages - 2020-Q1

## About us
We’re a innovative development agency from The Netherlands building awesome websites, webshops and web applications with Laravel and Magento. Check out our website [justbetter.nl](https://justbetter.nl) and our [open source projects](https://github.com/justbetter).
Expand Down
1 change: 0 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
"sentry/sdk": "^2.0",
"monolog/monolog": "*",
"magento/framework": "*",
"php-http/curl-client": "^2.0",
"nyholm/psr7": "^1.2"
},
"authors": [
Expand Down
28 changes: 5 additions & 23 deletions etc/adminhtml/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,40 +11,22 @@
<resource>JustBetter_Sentry::configuration</resource>
<group id="general" translate="label" type="text" sortOrder="10" showInDefault="1" showInWebsite="0" showInStore="0">
<label>Sentry general config</label>
<field id="enabled" translate="label" type="select" sortOrder="10" showInDefault="1" showInWebsite="0" showInStore="0">
<label>Sentry enabled</label>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
<field id="deployment_config_info" translate="label" type="select" sortOrder="10" showInDefault="1" showInWebsite="0" showInStore="0">
<label>Deployment config info</label>
<frontend_model>JustBetter\Sentry\Block\Adminhtml\System\Config\DeploymentConfigInfo</frontend_model>
</field>
<field id="enable_script_tag" translate="label" type="select" sortOrder="20" showInDefault="1" showInWebsite="0" showInStore="0">
<label>Enable Sentry script tag</label>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
</field>
<field id="mage_mode_development" translate="label" type="select" sortOrder="30" showInDefault="1" showInWebsite="0" showInStore="0">
<label>Send errors in development mode</label>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
</field>
<field id="domain" translate="label" type="text" sortOrder="40" showInDefault="1" showInWebsite="0" showInStore="0">
<label>Sentry domain</label>
<comment><![CDATA[The domain of sentry (Data Source Name). Sentry will provide this value once you create a project. Will be a string like <pre><code>https://7a83f8de8fe04f5194742a7bbd401ed8@sentry.io/1734931</code></pre>]]></comment>
</field>
<field id="environment" translate="label" type="text" sortOrder="50" showInDefault="1" showInWebsite="0" showInStore="0">
<label>Sentry environment</label>
<comment><![CDATA[The environment to send to Sentry (optional). Can be any arbitrary string (e.g., "staging" or "production"). Refer to the <a href="https://docs.sentry.io/enriching-error-data/environments/?platform=php
" target="_blank">Sentry documentation</a> for details.]]></comment>
</field>
<field id="script_tag_placement" translate="label" type="select" sortOrder="60" showInDefault="1" showInWebsite="0" showInStore="0">
<field id="script_tag_placement" translate="label" type="select" sortOrder="30" showInDefault="1" showInWebsite="0" showInStore="0">
<label>Script tag location</label>
<source_model>JustBetter\Sentry\Model\Config\Source\ScriptTagPlacement</source_model>
<depends>
<field id="enable_script_tag">1</field>
</depends>
</field>
<field id="log_level" translate="label" type="select" sortOrder="70" showInDefault="1" showInWebsite="0" showInStore="0">
<label>Log Level</label>
<comment>Minimum log level to send to Sentry</comment>
<source_model>JustBetter\Sentry\Model\Config\Source\LogLevel</source_model>
</field>
<field id="sent" translate="label" sortOrder="80" showInDefault="1" showInWebsite="1" showInStore="1">
<field id="sent" translate="label" sortOrder="40" showInDefault="1" showInWebsite="1" showInStore="1">
<button_label>Send sentry test event</button_label>
<button_url>justbetter_sentry/test/sentry</button_url>
<frontend_model>JustBetter\Sentry\Block\Adminhtml\System\Config\Button</frontend_model>
Expand Down
4 changes: 0 additions & 4 deletions etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,4 @@
<type name="Magento\Framework\AppInterface">
<plugin disabled="false" name="GlobalExceptionCatcher" type="JustBetter\Sentry\Plugin\GlobalExceptionCatcher" sortOrder="0"/>
</type>
<!-- I don't think this is still necessary -->
<!-- <type name="Magento\Framework\App\Http">-->
<!-- <plugin disabled="false" name="HttpExceptionCatcher" type="JustBetter\Sentry\Plugin\HttpExceptionCatcher" sortOrder="0"/>-->
<!-- </type>-->
</config>
2 changes: 2 additions & 0 deletions i18n/en_US.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
How to configure Sentry?,How to configure Sentry?
"This module uses the <a href="https://devdocs.magento.com/guides/v2.3/config-guide/config/config-php.html" target="_BLANK">Magento Deployment Configuration</a> for most it's configuration. This means that you need to add this array to your `app/etc/env.php`:","This module uses the <a href="https://devdocs.magento.com/guides/v2.3/config-guide/config/config-php.html" target="_BLANK">Magento Deployment Configuration</a> for most it's configuration. This means that you need to add this array to your `app/etc/env.php`:"
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<td></td>
<td>
<h2><?php echo __('How to configure Sentry?'); ?></h2>
<p><?php echo __('This module uses the <a href="https://devdocs.magento.com/guides/v2.3/config-guide/config/config-php.html" target="_BLANK">Magento Deployment Configuration</a> for most it\'s configuration. This means that you need to add this array to your `app/etc/env.php`:'); ?></p>

<pre>
<?php echo htmlentities("
'sentry' => [
'domain' => 'example.com',
'environment' => null,
'log_level' => \Monolog\Logger::WARNING,
'isOverwriteProductionMode' => false,
]"); ?>
</pre>
</td>
5 changes: 2 additions & 3 deletions view/frontend/templates/script/sentry.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
/** @var \JustBetter\Sentry\Helper\Data $helper */
$helper = $this->helper(\JustBetter\Sentry\Helper\Data::class);

if (
!$helper->isActive() ||
if (!$helper->isActive() ||
!$helper->useScriptTag() ||
!$helper->showScriptTagInThisBlock($block->getNameInLayout())
) {
Expand All @@ -14,4 +13,4 @@ if (
?>
<script src="https://cdn.polyfill.io/v2/polyfill.min.js?features=Promise" crossorigin></script>
<script src="https://browser.sentry-cdn.com/4.5.3/bundle.min.js" crossorigin></script>
<script>Sentry.init({ dsn: '<?php echo trim($helper->getGeneralConfig('domain')) ?>' });</script>
<script>Sentry.init({ dsn: '<?= trim($helper->getGeneralConfig('domain')) ?>' });</script>

0 comments on commit f0201aa

Please sign in to comment.