← Back to team overview

savoirfairelinux-openerp team mailing list archive

[Merge] lp:~savoirfairelinux-openerp/server-env-tools/sentry into lp:server-env-tools

 

Sandy Carter (http://www.savoirfairelinux.com) has proposed merging lp:~savoirfairelinux-openerp/server-env-tools/sentry into lp:server-env-tools.

Requested reviews:
  Server Environment And Tools Core Editors (server-env-tools-core-editors)

For more details, see:
https://code.launchpad.net/~savoirfairelinux-openerp/server-env-tools/sentry/+merge/222547

Module for enabling raven initializing to report to sentry.

Based on feedback from my presentation at odoo days 2014
-- 
https://code.launchpad.net/~savoirfairelinux-openerp/server-env-tools/sentry/+merge/222547
Your team Savoir-faire Linux' OpenERP is subscribed to branch lp:~savoirfairelinux-openerp/server-env-tools/sentry.
=== added directory 'sentry'
=== added file 'sentry/__init__.py'
--- sentry/__init__.py	1970-01-01 00:00:00 +0000
+++ sentry/__init__.py	2014-06-09 19:41:10 +0000
@@ -0,0 +1,49 @@
+# -*- coding: utf-8 -*-
+###############################################################################
+#
+#    OpenERP, Open Source Management Solution
+#    This module copyright (C) 2010 - 2014 Savoir-faire Linux
+#    (<http://www.savoirfairelinux.com>).
+#
+#    This program is free software: you can redistribute it and/or modify
+#    it under the terms of the GNU Affero General Public License as
+#    published by the Free Software Foundation, either version 3 of the
+#    License, or (at your option) any later version.
+#
+#    This program is distributed in the hope that it will be useful,
+#    but WITHOUT ANY WARRANTY; without even the implied warranty of
+#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#    GNU Affero General Public License for more details.
+#
+#    You should have received a copy of the GNU Affero General Public License
+#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+#
+###############################################################################
+
+from openerp.tools import config
+from odoo_sentry_client import BzrClient
+from odoo_sentry_handler import OdooSentryHandler
+import logging
+import cgitb
+
+
+root_logger = logging.root
+
+processors = (
+    'raven.processors.SanitizePasswordsProcessor',
+    'raven_sanitize_openerp.OpenerpPasswordsProcessor'
+)
+if config.get(u'sentry_dsn'):
+    cgitb.enable()
+    # Get DSN info from config file or ~/.openerp_serverrc (recommended)
+    dsn = config.get('sentry_dsn')
+    # Create Client
+    client = BzrClient(
+        dsn=dsn,
+        processors=processors,
+    )
+    handler = OdooSentryHandler(client, level=logging.ERROR)
+    root_logger.addHandler(handler)
+else:
+    logging.get(__name__).warn(u"Sentry DSN not defined in config file")
+    client = None

=== added file 'sentry/__openerp__.py'
--- sentry/__openerp__.py	1970-01-01 00:00:00 +0000
+++ sentry/__openerp__.py	2014-06-09 19:41:10 +0000
@@ -0,0 +1,62 @@
+# -*- coding: utf-8 -*-
+##############################################################################
+#
+#    OpenERP, Open Source Management Solution
+#    This module copyright (C) 2010 - 2014 Savoir-faire Linux
+#    (<http://www.savoirfairelinux.com>).
+#
+#    This program is free software: you can redistribute it and/or modify
+#    it under the terms of the GNU Affero General Public License as
+#    published by the Free Software Foundation, either version 3 of the
+#    License, or (at your option) any later version.
+#
+#    This program is distributed in the hope that it will be useful,
+#    but WITHOUT ANY WARRANTY; without even the implied warranty of
+#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#    GNU Affero General Public License for more details.
+#
+#    You should have received a copy of the GNU Affero General Public License
+#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+#
+##############################################################################
+
+{
+    'name': "sentry",
+
+    'summary': "Sentry integration",
+    'description': """
+Sentry
+======
+
+Integration with Sentry Error reporting engine.
+
+Insert sentry DSN to ~/.openerp_serverrc with value:
+    sentry_dsn = sync+<Your Sentry DSN>
+
+Contributors
+------------
+* Sandy Carter (sandy.carter@xxxxxxxxxxxxxxxxxxxx)
+""",
+
+    'author': "Savoir-faire Linux",
+    'website': "http://www.savoirfairelinux.com";,
+
+    # Categories can be used to filter modules in modules listing
+    # Check <odoo>/addons/base/module/module_data.xml of the full list
+    'category': 'Extra Tools',
+    'version': '1.0',
+
+    # any module necessary for this one to work correctly
+    'depends': ['base'],
+    'external_dependencies': {
+        'python': ['raven', 'raven_sanitize_openerp', 'bzrlib'],
+    },
+    'data': [
+    ],
+
+    'demo': [
+    ],
+
+    'tests': [
+    ],
+}

=== added file 'sentry/odoo_sentry_client.py'
--- sentry/odoo_sentry_client.py	1970-01-01 00:00:00 +0000
+++ sentry/odoo_sentry_client.py	2014-06-09 19:41:10 +0000
@@ -0,0 +1,104 @@
+# -*- coding: utf-8 -*-
+###############################################################################
+#
+#    OpenERP, Open Source Management Solution
+#    This module copyright (C) 2010 - 2014 Savoir-faire Linux
+#    (<http://www.savoirfairelinux.com>).
+#
+#    This program is free software: you can redistribute it and/or modify
+#    it under the terms of the GNU Affero General Public License as
+#    published by the Free Software Foundation, either version 3 of the
+#    License, or (at your option) any later version.
+#
+#    This program is distributed in the hope that it will be useful,
+#    but WITHOUT ANY WARRANTY; without even the implied warranty of
+#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#    GNU Affero General Public License for more details.
+#
+#    You should have received a copy of the GNU Affero General Public License
+#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+#
+###############################################################################
+
+import logging
+import platform
+import os
+import sys
+from raven import Client
+from bzrlib.branch import Branch
+from bzrlib.errors import NotBranchError
+from openerp.tools import config
+
+_logger = logging.getLogger(__name__)
+
+
+class BzrClient(Client):
+    """Subclass raven.Client to be able to report Bazaar revno as Module
+    versions"""
+
+    def __init__(self, dsn=None, **options):
+        # Send the following library versions, include all eggs
+        include_paths = [
+            'openerp',
+            'sentry',
+            'raven',
+            'raven_sanitize_openerp',
+        ] + [os.path.basename(i).split('-')[0]
+             for i in sys.path if i.endswith('.egg')]
+        # Add tags, OS and bzr revisions for Server and Addons
+        tags = {
+            'OS': (" ".join(platform.linux_distribution()).strip() or
+                   " ".join(platform.win32_ver()).strip() or
+                   " ".join((platform.system(), platform.release(),
+                             platform.machine()))),
+        }
+        self.bzr_revs = {}
+        super(BzrClient, self).__init__(
+            dsn=dsn, include_paths=include_paths, tags=tags, **options)
+        self.set_rev_version(config.get(u'root_path') + u"/..", )
+        # Create and test message for Sentry
+        self.captureMessage(u'Sentry Tracking Activated!')
+
+    def set_rev_version(self, path):
+        """Given path, get source and revno, careful not to raise any
+        exceptions"""
+        try:
+            branch, rel_path = Branch.open_containing(path)
+            branch.lock_read()
+            # Clean name
+            name = (
+                branch.get_parent().replace(u'bazaar.launchpad.net/', u'lp:')
+                                   .replace(u'%7E', u'~')
+                                   .replace(u'%2Bbranch/', u'')
+                                   .replace(u'bzr+ssh://', u''))
+            self.bzr_revs[name] = u'r%i' % branch.revno()
+            branch.unlock()
+        except NotBranchError:
+            return
+        except:
+            if branch.is_locked():
+                branch.unlock()
+            return
+
+    def captureException(self, params=None, exc_info=None, **kwargs):
+        self.extra[u'params'] = params
+        # Store exc_info in case another exception is raised.
+        exc_info = sys.exc_info()
+        try:
+            # Using bzrlib find revision numbers for server and addons
+            for path in config.get(u'addons_path').split(u','):
+                self.set_rev_version(path)
+        finally:
+            pass
+        return super(BzrClient, self).captureException(
+            exc_info=exc_info, **kwargs)
+
+    def build_msg(self, event_type, data=None, date=None,
+                  time_spent=None, extra=None, stack=None, public_key=None,
+                  tags=None, **kwargs):
+        """Add bzr revnos to msg's modules"""
+        res = super(BzrClient, self).build_msg(
+            event_type, data, date, time_spent, extra, stack, public_key,
+            tags, **kwargs)
+        res['modules'] = dict(res['modules'].items() + self.bzr_revs.items())
+        return res

=== added file 'sentry/odoo_sentry_handler.py'
--- sentry/odoo_sentry_handler.py	1970-01-01 00:00:00 +0000
+++ sentry/odoo_sentry_handler.py	2014-06-09 19:41:10 +0000
@@ -0,0 +1,32 @@
+# -*- coding: utf-8 -*-
+# ##############################################################################
+#
+#    OpenERP, Open Source Management Solution
+#    This module copyright (C) 2010 - 2014 Savoir-faire Linux
+#    (<http://www.savoirfairelinux.com>).
+#
+#    This program is free software: you can redistribute it and/or modify
+#    it under the terms of the GNU Affero General Public License as
+#    published by the Free Software Foundation, either version 3 of the
+#    License, or (at your option) any later version.
+#
+#    This program is distributed in the hope that it will be useful,
+#    but WITHOUT ANY WARRANTY; without even the implied warranty of
+#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#    GNU Affero General Public License for more details.
+#
+#    You should have received a copy of the GNU Affero General Public License
+#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+#
+###############################################################################
+
+from openerp.osv.orm import except_orm
+from raven.handlers.logging import SentryHandler
+
+
+class OdooSentryHandler(SentryHandler, object):
+
+    def can_record(self, record):
+        if record.exc_info and record.exc_info[0] is except_orm:
+            return False
+        return super(OdooSentryHandler, self).can_record(record)