Skip to content

Commit 92f5c1a

Browse files
committed
Merge pull request #4 from jayelkaake/min_priority_config_and_parsing
Min priority config option+ logic to parse msgs + lib/sentry/raven (for convenience)
2 parents 18da643 + 27980b4 commit 92f5c1a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+10279
-11
lines changed

app/code/community/Hackathon/LoggerSentry/Model/Sentry.php

+51-8
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
set_include_path(get_include_path() . PATH_SEPARATOR . realpath(Mage::getBaseDir() . '/../vendor/raven/raven/lib'));
3+
set_include_path(get_include_path() . PATH_SEPARATOR . realpath(Mage::getBaseDir() .DS.'lib'.DS.'sentry'.DS.'raven'.DS.'lib'));
44

55
class Hackathon_LoggerSentry_Model_Sentry extends Zend_Log_Writer_Abstract
66
{
@@ -28,7 +28,6 @@ class Hackathon_LoggerSentry_Model_Sentry extends Zend_Log_Writer_Abstract
2828
7 => 'debug'
2929
);
3030

31-
3231
/**
3332
*
3433
*
@@ -45,26 +44,32 @@ public function __construct($filename)
4544
$options = array(
4645
'logger' => $helper->getLoggerConfig('sentry/logger_name')
4746
);
48-
$this->_sentryClient = new Raven_Client($helper->getLoggerConfig('sentry/apikey'), $options);
47+
try {
48+
$this->_sentryClient = new Raven_Client($helper->getLoggerConfig('sentry/apikey'), $options);
49+
} catch (Exception $e) {
50+
// Ignore errors so that it doesn't crush the website when/if Sentry goes down.
51+
}
52+
4953
}
5054

5155
/**
5256
* Places event line into array of lines to be used as message body.
5357
*
54-
* @param array $event Event data
58+
* @param FireGento_Logger_Model_Event $event Event data
5559
*
5660
* @throws Zend_Log_Exception
5761
* @return void
5862
*/
59-
protected function _write($event)
63+
protected function _write($eventObj)
6064
{
6165
try {
6266
/* @var $helper Hackathon_Logger_Helper_Data */
6367
$helper = Mage::helper('firegento_logger');
64-
$helper->addEventMetadata($event);
68+
$helper->addEventMetadata($eventObj);
6569

66-
$additional = array(
70+
$event = $eventObj->getEventDataArray();
6771

72+
$additional = array(
6873
'file' => $event['file'],
6974
'line' => $event['line'],
7075
);
@@ -75,15 +80,53 @@ protected function _write($event)
7580
}
7681
}
7782

83+
$this->_assumePriorityByMessage($event);
84+
85+
// if we still can't figure it out, assume it's an error
86+
$priority = isset($event['priority']) && !empty($event['priority']) ? $event['priority'] : 3;
87+
88+
if (!$this->_isHighEnoughPriorityToReport($priority)) {
89+
return $this; // Don't log anything warning or less severe.
90+
}
91+
7892
$this->_sentryClient->captureMessage(
79-
$event['message'], array(), $this->_priorityToLevelMapping[$event['priority']], true, $additional
93+
$event['message'], array(), $this->_priorityToLevelMapping[$priority], true, $additional
8094
);
8195

8296
} catch (Exception $e) {
8397
throw new Zend_Log_Exception($e->getMessage(), $e->getCode());
8498
}
8599
}
86100

101+
/**
102+
* @param int $priority
103+
* @return boolean True if we should be reporting this, false otherwise.
104+
*/
105+
protected function _isHighEnoughPriorityToReport($priority)
106+
{
107+
if ($priority > (int)Mage::helper('firegento_logger')->getLoggerConfig('sentry/priority')) {
108+
return false; // Don't log anything warning or less severe than configured.
109+
}
110+
return true;
111+
}
112+
113+
/**
114+
* Try to attach a priority # based on the error message string (since sometimes it is not specified)
115+
* @param FireGento_Logger_Model_Event &$event Event data
116+
* @return \Hackathon_LoggerSentry_Model_Sentry
117+
*/
118+
protected function _assumePriorityByMessage(&$event)
119+
{
120+
if (stripos($event['message'], "warn") === 0) {
121+
$event['priority'] = 4;
122+
}
123+
if (stripos($event['message'], "notice") === 0) {
124+
$event['priority'] = 5;
125+
}
126+
127+
return $this;
128+
}
129+
87130
/**
88131
* Satisfy newer Zend Framework
89132
*

app/code/community/Hackathon/LoggerSentry/etc/config.xml

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<config>
33
<modules>
44
<Hackathon_LoggerSentry>
5-
<version>1.0.0</version>
5+
<version>1.1.0</version>
66
</Hackathon_LoggerSentry>
77
</modules>
88
<global>
@@ -32,6 +32,7 @@
3232
<sentry>
3333
<apikey>https://XXXXXXXXXXXXXXX:[email protected]/7202</apikey>
3434
<logger_name>Magento Sentry Logger</logger_name>
35+
<priority>4</priority>
3536
</sentry>
3637
</logger>
3738
</default>

app/code/community/Hackathon/LoggerSentry/etc/system.xml

+10-2
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,27 @@
99
<sort_order>90</sort_order>
1010
<show_in_default>1</show_in_default>
1111
<fields>
12-
<apikey translate="label">
12+
<apikey translate="label comment">
1313
<label>API key</label>
1414
<frontend_type>textarea</frontend_type>
1515
<sort_order>0</sort_order>
1616
<show_in_default>1</show_in_default>
1717
<comment>Add here your API key</comment>
1818
</apikey>
19-
<logger_name>
19+
<logger_name translate="label">
2020
<label>Logger name</label>
2121
<frontend_type>text</frontend_type>
2222
<sort_order>10</sort_order>
2323
<show_in_default>1</show_in_default>
2424
</logger_name>
25+
<priority translate="label comment">
26+
<label>Priority Level Filter</label>
27+
<frontend_type>select</frontend_type>
28+
<source_model>firegento_logger/system_config_source_prioritydefault</source_model>
29+
<sort_order>20</sort_order>
30+
<show_in_default>1</show_in_default>
31+
<comment>Choose the lowest priority level to be sent to Sentry. If a log level is lower priority than this then it will not be sent to Sentry.</comment>
32+
</priority>
2533
</fields>
2634
</sentry>
2735
</groups>

lib/sentry/raven/.gitignore

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
*.lock
2+
package.xml
3+
/vendor
4+
.idea
5+
.php_cs.cache
6+
docs/_build

lib/sentry/raven/.gitmodules

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "docs/_sentryext"]
2+
path = docs/_sentryext
3+
url = https://github.com/getsentry/sentry-doc-support

lib/sentry/raven/.php_cs

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
$finder = Symfony\CS\Finder\DefaultFinder::create()
4+
->in(__DIR__)
5+
;
6+
7+
return Symfony\CS\Config\Config::create()
8+
->setUsingCache(true)
9+
->setUsingLinter(true)
10+
->level(Symfony\CS\FixerInterface::PSR2_LEVEL)
11+
->finder($finder)
12+
;

lib/sentry/raven/.travis.yml

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
language: php
2+
3+
php:
4+
- 5.3
5+
- 5.4
6+
- 5.5
7+
- 5.6
8+
- 7.0
9+
- hhvm
10+
11+
matrix:
12+
allow_failures:
13+
- php: hhvm
14+
- php: 7.0
15+
fast_finish: true
16+
17+
sudo: false
18+
19+
cache:
20+
directories:
21+
- $HOME/.composer/cache
22+
23+
before_install:
24+
- composer self-update
25+
26+
install: travis_retry composer install --no-interaction --prefer-source
27+
28+
script:
29+
- vendor/bin/php-cs-fixer fix --config-file=.php_cs --verbose --diff --dry-run
30+
- vendor/bin/phpunit

lib/sentry/raven/AUTHORS

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
The Raven PHP client was originally written by Michael van Tellingen
2+
and is maintained by the Sentry Team.
3+
4+
http://github.com/getsentry/raven-php/contributors

lib/sentry/raven/CHANGES

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
0.13.0
2+
------
3+
4+
- Updated API to use new style interfaces.
5+
- Remove session cookie in default processor.
6+
- Expand docs for Laravel, Symfony2, and Monolog.
7+
- Default error types can now be set as part of ErrorHandler configuration.
8+
9+
0.12.1
10+
------
11+
12+
- Dont send empty values for various context.
13+
14+
0.12.0
15+
------
16+
17+
- Bumped protocol version to 6.
18+
- Fixed an issue with the async curl handler (GH-216).
19+
- Removed UDP transport.
20+
21+
0.11.0
22+
------
23+
24+
- New configuration parameter: 'release'
25+
- New configuration parameter: 'message_limit'
26+
- New configuration parameter: 'curl_ssl_version'
27+
- New configuration parameter: 'curl_ipv4'
28+
- New configuration parameter: 'verify_ssl'
29+
- Updated remote endpoint to use modern project-based path.
30+
- Expanded default sanitizer support to include 'auth_pw' attribute.
31+
32+
0.10.0
33+
------
34+
35+
- Added a default certificate bundle which includes common root CA's
36+
as well as getsentry.com's CA.
37+
38+
0.9.1
39+
-----
40+
41+
- Change default curl connection to 'sync'
42+
- Improve CLI reporting
43+
44+
45+
0.9.0
46+
-----
47+
48+
- Protocol version 5
49+
- Default to asynchronous HTTP handler using curl_multi.
50+
51+
52+
(For previous versions see the commit history)

lib/sentry/raven/LICENSE

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
Copyright (c) 2012 Sentry Team and individual contributors.
2+
All rights reserved.
3+
4+
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
5+
6+
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
7+
8+
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
9+
10+
3. Neither the name of the Raven nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
11+
12+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

lib/sentry/raven/Makefile

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
.PHONY: test
2+
3+
develop:
4+
composer install --dev
5+
make setup-git
6+
7+
cs:
8+
vendor/bin/php-cs-fixer fix --config-file=.php_cs --verbose --diff
9+
10+
cs-dry-run:
11+
vendor/bin/php-cs-fixer fix --config-file=.php_cs --verbose --diff --dry-run
12+
13+
test:
14+
vendor/bin/phpunit
15+
16+
setup-git:
17+
git config branch.autosetuprebase always

0 commit comments

Comments
 (0)