Browse Source

[MIG] sentry: Backports to Odoo 8.0

pull/1023/head
Naglis Jonaitis 7 years ago
parent
commit
af88d88802
No known key found for this signature in database GPG Key ID: 4748835F585390F5
  1. 25
      sentry/README.rst
  2. 4
      sentry/__init__.py
  3. 2
      sentry/__openerp__.py
  4. 23
      sentry/const.py
  5. 4
      sentry/logutils.py
  6. 22
      sentry/tests/test_client.py
  7. 4
      sentry/tests/test_logutils.py

25
sentry/README.rst

@ -47,18 +47,17 @@ configuration file:
``sentry_exclude_loggers`` A string of comma-separated logger names which should be excluded ``werkzeug`` ``sentry_exclude_loggers`` A string of comma-separated logger names which should be excluded ``werkzeug``
from Sentry. from Sentry.
``sentry_ignored_exceptions`` A string of comma-separated exceptions which should be ignored. ``odoo.exceptions.AccessDenied,
You can use a star symbol (*) at the end, to ignore all exceptions odoo.exceptions.AccessError,
from a module, eg.: *odoo.exceptions.**. odoo.exceptions.DeferredException,
odoo.exceptions.MissingError,
odoo.exceptions.RedirectWarning,
odoo.exceptions.UserError,
odoo.exceptions.ValidationError,
odoo.exceptions.Warning,
odoo.exceptions.except_orm``
``sentry_ignored_exceptions`` A string of comma-separated exceptions which should be ignored. ``openerp.exceptions.AccessDenied,
You can use a star symbol (*) at the end, to ignore all exceptions openerp.exceptions.AccessError,
from a module, eg.: *openerp.exceptions.**. openerp.exceptions.DeferredException,
openerp.exceptions.MissingError,
openerp.exceptions.RedirectWarning,
openerp.exceptions.ValidationError,
openerp.exceptions.Warning,
openerp.exceptions.except_orm``
``sentry_processors`` A string of comma-separated processor classes which will be applied ``raven.processors.SanitizePasswordsProcessor, ``sentry_processors`` A string of comma-separated processor classes which will be applied ``raven.processors.SanitizePasswordsProcessor,
on an event before sending it to Sentry. odoo.addons.sentry.logutils.SanitizeOdooCookiesProcessor``
on an event before sending it to Sentry. openerp.addons.sentry.logutils.SanitizeOdooCookiesProcessor``
``sentry_transport`` Transport class which will be used to send events to Sentry. ``threaded`` ``sentry_transport`` Transport class which will be used to send events to Sentry. ``threaded``
Possible values: *threaded*: spawns an async worker for processing Possible values: *threaded*: spawns an async worker for processing
@ -93,8 +92,8 @@ Below is an example of Odoo configuration file with *Odoo Sentry* options::
sentry_enabled = true sentry_enabled = true
sentry_logging_level = warn sentry_logging_level = warn
sentry_exclude_loggers = werkzeug sentry_exclude_loggers = werkzeug
sentry_ignore_exceptions = odoo.exceptions.AccessDenied,odoo.exceptions.AccessError,odoo.exceptions.MissingError,odoo.exceptions.RedirectWarning,odoo.exceptions.UserError,odoo.exceptions.ValidationError,odoo.exceptions.Warning,odoo.exceptions.except_orm
sentry_processors = raven.processors.SanitizePasswordsProcessor,odoo.addons.sentry.logutils.SanitizeOdooCookiesProcessor
sentry_ignore_exceptions = openerp.exceptions.AccessDenied,openerp.exceptions.AccessError,openerp.exceptions.MissingError,openerp.exceptions.RedirectWarning,openerp.exceptions.ValidationError,openerp.exceptions.Warning,openerp.exceptions.except_orm
sentry_processors = raven.processors.SanitizePasswordsProcessor,openerp.addons.sentry.logutils.SanitizeOdooCookiesProcessor
sentry_transport = threaded sentry_transport = threaded
sentry_include_context = true sentry_include_context = true
sentry_environment = production sentry_environment = production
@ -109,7 +108,7 @@ above the configured Sentry logging level, no additional actions are necessary.
.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas .. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas
:alt: Try me on Runbot :alt: Try me on Runbot
:target: https://runbot.odoo-community.org/runbot/149/10.0
:target: https://runbot.odoo-community.org/runbot/149/8.0
Known issues / Roadmap Known issues / Roadmap
====================== ======================

4
sentry/__init__.py

@ -4,8 +4,8 @@
import logging import logging
from odoo.service import wsgi_server
from odoo.tools import config as odoo_config
from openerp.service import wsgi_server
from openerp.tools import config as odoo_config
from . import const from . import const
from .logutils import LoggerNameFilter, OdooSentryHandler from .logutils import LoggerNameFilter, OdooSentryHandler

2
sentry/__manifest__.py → sentry/__openerp__.py

@ -4,7 +4,7 @@
{ {
'name': 'Sentry', 'name': 'Sentry',
'summary': 'Report Odoo errors to Sentry', 'summary': 'Report Odoo errors to Sentry',
'version': '10.0.1.0.0',
'version': '8.0.1.0.0',
'category': 'Extra Tools', 'category': 'Extra Tools',
'website': 'https://odoo-community.org/', 'website': 'https://odoo-community.org/',
'author': 'Mohammed Barsi,' 'author': 'Mohammed Barsi,'

23
sentry/const.py

@ -5,7 +5,7 @@
import collections import collections
import logging import logging
import odoo.loglevels
import openerp.loglevels
_logger = logging.getLogger(__name__) _logger = logging.getLogger(__name__)
try: try:
@ -27,27 +27,26 @@ SentryOption = collections.namedtuple(
# Mapping of Odoo logging level -> Python stdlib logging library log level. # Mapping of Odoo logging level -> Python stdlib logging library log level.
LOG_LEVEL_MAP = dict([ LOG_LEVEL_MAP = dict([
(getattr(odoo.loglevels, 'LOG_%s' % x), getattr(logging, x))
(getattr(openerp.loglevels, 'LOG_%s' % x), getattr(logging, x))
for x in ('CRITICAL', 'ERROR', 'WARNING', 'INFO', 'DEBUG', 'NOTSET') for x in ('CRITICAL', 'ERROR', 'WARNING', 'INFO', 'DEBUG', 'NOTSET')
]) ])
DEFAULT_LOG_LEVEL = 'warn' DEFAULT_LOG_LEVEL = 'warn'
ODOO_USER_EXCEPTIONS = [ ODOO_USER_EXCEPTIONS = [
'odoo.exceptions.AccessDenied',
'odoo.exceptions.AccessError',
'odoo.exceptions.DeferredException',
'odoo.exceptions.MissingError',
'odoo.exceptions.RedirectWarning',
'odoo.exceptions.UserError',
'odoo.exceptions.ValidationError',
'odoo.exceptions.Warning',
'odoo.exceptions.except_orm',
'openerp.exceptions.AccessDenied',
'openerp.exceptions.AccessError',
'openerp.exceptions.DeferredException',
'openerp.exceptions.MissingError',
'openerp.exceptions.RedirectWarning',
'openerp.exceptions.ValidationError',
'openerp.exceptions.Warning',
'openerp.exceptions.except_orm',
] ]
DEFAULT_IGNORED_EXCEPTIONS = ','.join(ODOO_USER_EXCEPTIONS) DEFAULT_IGNORED_EXCEPTIONS = ','.join(ODOO_USER_EXCEPTIONS)
PROCESSORS = ( PROCESSORS = (
'raven.processors.SanitizePasswordsProcessor', 'raven.processors.SanitizePasswordsProcessor',
'odoo.addons.sentry.logutils.SanitizeOdooCookiesProcessor',
'openerp.addons.sentry.logutils.SanitizeOdooCookiesProcessor',
) )
DEFAULT_PROCESSORS = ','.join(PROCESSORS) DEFAULT_PROCESSORS = ','.join(PROCESSORS)

4
sentry/logutils.py

@ -5,7 +5,7 @@
import logging import logging
import urlparse import urlparse
import odoo.http
import openerp.http
_logger = logging.getLogger(__name__) _logger = logging.getLogger(__name__)
try: try:
@ -38,7 +38,7 @@ def get_extra_context():
''' '''
Extracts additional context from the current request (if such is set). Extracts additional context from the current request (if such is set).
''' '''
request = odoo.http.request
request = openerp.http.request
try: try:
session = getattr(request, 'session', {}) session = getattr(request, 'session', {})
except RuntimeError: except RuntimeError:

22
sentry/tests/test_client.py

@ -4,11 +4,11 @@
import logging import logging
import sys import sys
import unittest
import unittest2
import raven import raven
from odoo import exceptions
from openerp import exceptions
from .. import initialize_raven from .. import initialize_raven
from ..logutils import OdooSentryHandler from ..logutils import OdooSentryHandler
@ -59,16 +59,16 @@ class InMemoryClient(raven.Client):
return False return False
class TestClientSetup(unittest.TestCase):
class TestClientSetup(unittest2.TestCase):
def setUp(self): def setUp(self):
super(TestClientSetup, self).setUp() super(TestClientSetup, self).setUp()
self.logger = logging.getLogger(__name__) self.logger = logging.getLogger(__name__)
# Sentry is enabled by default, so the default handler will be added
# when the module is loaded. After that, subsequent calls to
# setup_logging will not re-add our handler. We explicitly remove
# OdooSentryHandler handler so we can test with our in-memory client.
def tearDown(self):
super(TestClientSetup, self).tearDown()
# Remove our logging handler to avoid interfering with tests of other
# modules.
remove_logging_handler('', OdooSentryHandler) remove_logging_handler('', OdooSentryHandler)
def assertEventCaptured(self, client, event_level, event_msg): def assertEventCaptured(self, client, event_level, event_msg):
@ -105,9 +105,9 @@ class TestClientSetup(unittest.TestCase):
config = { config = {
'sentry_enabled': True, 'sentry_enabled': True,
'sentry_dsn': 'http://public:secret@example.com/1', 'sentry_dsn': 'http://public:secret@example.com/1',
'sentry_ignore_exceptions': 'odoo.exceptions.UserError',
'sentry_ignore_exceptions': 'openerp.exceptions.ValidationError',
} }
level, msg = logging.WARNING, 'Test UserError'
level, msg = logging.WARNING, 'Test ValidationError'
client = initialize_raven(config, client_cls=InMemoryClient) client = initialize_raven(config, client_cls=InMemoryClient)
handlers = list( handlers = list(
@ -116,8 +116,8 @@ class TestClientSetup(unittest.TestCase):
self.assertTrue(handlers) self.assertTrue(handlers)
handler = handlers[0] handler = handlers[0]
try: try:
raise exceptions.UserError(msg)
except exceptions.UserError:
raise exceptions.ValidationError(msg)
except exceptions.ValidationError:
exc_info = sys.exc_info() exc_info = sys.exc_info()
record = logging.LogRecord( record = logging.LogRecord(
__name__, level, __file__, 42, msg, (), exc_info) __name__, level, __file__, 42, msg, (), exc_info)

4
sentry/tests/test_logutils.py

@ -2,14 +2,14 @@
# Copyright 2016-2017 Versada <https://versada.eu/> # Copyright 2016-2017 Versada <https://versada.eu/>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
import unittest
import unittest2
import mock import mock
from ..logutils import SanitizeOdooCookiesProcessor from ..logutils import SanitizeOdooCookiesProcessor
class TestOdooCookieSanitizer(unittest.TestCase):
class TestOdooCookieSanitizer(unittest2.TestCase):
def test_cookie_as_string(self): def test_cookie_as_string(self):
data = { data = {

Loading…
Cancel
Save