Skip to content

Commit

Permalink
add flare integration
Browse files Browse the repository at this point in the history
  • Loading branch information
empiricompany committed May 2, 2024
1 parent 41799b5 commit 7f6d7ab
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 4 deletions.
30 changes: 30 additions & 0 deletions app/code/community/MM/Ignition/Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ class MM_Ignition_Helper_Data extends Mage_Core_Helper_Abstract
const XML_PATH_OVERRIDE_CONFIG = 'dev/mm_ignition/override_config';
const XML_PATH_OPENAI_ENABLED = 'dev/mm_ignition/enable_openai';
const XML_PATH_OPENAI_KEY = 'dev/mm_ignition/openai_api_key';
const XML_PATH_FLARE_ENABLED = 'dev/mm_ignition/enable_flare';
const XML_PATH_FLARE_API_KEY = 'dev/mm_ignition/flare_api_key';
const XML_PATH_FLARE_ANONYMIZE_IP = 'dev/mm_ignition/flare_anonymize_ip';

/**
* Allowed keys for settings
Expand Down Expand Up @@ -154,4 +157,31 @@ public function getOpenAiKey()
return Mage::getStoreConfig(self::XML_PATH_OPENAI_KEY);
}

/**
* Check if Flare is enabled
* @return bool
*/
public function isFlareEnabled()
{
return Mage::getStoreConfigFlag(self::XML_PATH_FLARE_ENABLED);
}

/**
* Check if Flare should anonymize IP
* @return bool
*/
public function shouldAnonymizeIp()
{
return Mage::getStoreConfigFlag(self::XML_PATH_FLARE_ANONYMIZE_IP);
}

/**
* Get Flare API key
* @return string
*/
public function getFlareApiKey()
{
return Mage::getStoreConfig(self::XML_PATH_FLARE_API_KEY);
}

}
19 changes: 16 additions & 3 deletions app/code/community/MM/Ignition/Model/Observer.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
use Spatie\Ignition\Config\IgnitionConfig;
use Spatie\Ignition\Ignition;
use Spatie\Ignition\Solutions\OpenAi\OpenAiSolutionProvider;
use Spatie\FlareClient\Flare;

class MM_Ignition_Model_Observer extends Mage_Core_Model_Observer
{
Expand All @@ -14,7 +15,7 @@ class MM_Ignition_Model_Observer extends Mage_Core_Model_Observer
*/
public function handleIgnitionRegister(Varien_Event_Observer $observer)
{
if (!$this->getHelper()->shouldPrintIgnition()) {
if (!$this->getHelper()->shouldPrintIgnition() && !$this->getHelper()->isFlareEnabled()) {
return;
}

Expand All @@ -30,14 +31,16 @@ public function handleIgnitionRegister(Varien_Event_Observer $observer)
*/
public function handleIgnitionException(Varien_Event_Observer $observer)
{
if (!$this->getHelper()->shouldPrintIgnition()) {
if (!$this->getHelper()->shouldPrintIgnition() && !$this->getHelper()->isFlareEnabled()) {
return;
}

$e = $observer->getEvent()->getException();
$this->getIgnitionInstance()->handleException($e);

die();
if ($this->getHelper()->shouldPrintIgnition()) {
die();
}
}

/**
Expand All @@ -48,6 +51,7 @@ public function handleIgnitionException(Varien_Event_Observer $observer)
protected function getIgnitionInstance()
{
$_ignition = Ignition::make()
->runningInProductionEnvironment(!Mage::getIsDeveloperMode())
->setConfig($this->getIgnitionConfig())
->applicationPath(Mage::getBaseDir());

Expand All @@ -61,6 +65,15 @@ protected function getIgnitionInstance()
]);
}

if ($this->getHelper()->isFlareEnabled() && !empty($this->getHelper()->getFlareApiKey())) {
$_ignition->sendToFlare($this->getHelper()->getFlareApiKey());
if ($this->getHelper()->shouldAnonymizeIp()) {
$_ignition->configureFlare(function(Flare $flare) {
$flare->anonymizeIp();
});
}
}

return $_ignition;
}

Expand Down
2 changes: 1 addition & 1 deletion app/code/community/MM/Ignition/etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<config>
<modules>
<MM_Ignition>
<version>1.3.0</version>
<version>1.4.0</version>
</MM_Ignition>
</modules>
<global>
Expand Down
35 changes: 35 additions & 0 deletions app/code/community/MM/Ignition/etc/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,41 @@
<enable_openai>1</enable_openai>
</depends>
</openai_api_key>
<enable_flare>
<label>Enable Flare</label>
<comment>Enable Flare Error Tracking</comment>
<frontend_type>select</frontend_type>
<source_model>adminhtml/system_config_source_yesno</source_model>
<sort_order>50</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
</enable_flare>
<flare_api_key>
<label>Flare API Key</label>
<comment>API key for Flare provided when you created a new project</comment>
<frontend_type>password</frontend_type>
<sort_order>70</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
<depends>
<enable_flare>1</enable_flare>
</depends>
</flare_api_key>
<flare_anonymize_ip>
<label>Anonymize IP</label>
<comment>Enable to anonymize IP addresses sent to Flare</comment>
<frontend_type>select</frontend_type>
<source_model>adminhtml/system_config_source_yesno</source_model>
<sort_order>80</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
<depends>
<enable_flare>1</enable_flare>
</depends>
</flare_anonymize_ip>
</fields>
</mm_ignition>
</groups>
Expand Down

0 comments on commit 7f6d7ab

Please sign in to comment.