Merge lp:~savoirfairelinux-openerp/server-env-tools/sentry into lp:~server-env-tools-core-editors/server-env-tools/7.0

Status: Needs review
Proposed branch: lp:~savoirfairelinux-openerp/server-env-tools/sentry
Merge into: lp:~server-env-tools-core-editors/server-env-tools/7.0
Diff against target: 267 lines (+247/-0)
4 files modified
sentry/__init__.py (+49/-0)
sentry/__openerp__.py (+62/-0)
sentry/odoo_sentry_client.py (+104/-0)
sentry/odoo_sentry_handler.py (+32/-0)
To merge this branch: bzr merge lp:~savoirfairelinux-openerp/server-env-tools/sentry
Reviewer Review Type Date Requested Status
Server Environment And Tools Core Editors Pending
Review via email: mp+222547@code.launchpad.net

Description of the change

Module for enabling raven initializing to report to sentry.

Based on feedback from my presentation at odoo days 2014

To post a comment you must log in.
79. By Sandy Carter (http://www.savoirfairelinux.com)

Add sentry integration module

Unmerged revisions

79. By Sandy Carter (http://www.savoirfairelinux.com)

Add sentry integration module

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== added directory 'sentry'
=== added file 'sentry/__init__.py'
--- sentry/__init__.py 1970-01-01 00:00:00 +0000
+++ sentry/__init__.py 2014-06-10 19:58:30 +0000
@@ -0,0 +1,49 @@
1# -*- coding: utf-8 -*-
2###############################################################################
3#
4# OpenERP, Open Source Management Solution
5# This module copyright (C) 2010 - 2014 Savoir-faire Linux
6# (<http://www.savoirfairelinux.com>).
7#
8# This program is free software: you can redistribute it and/or modify
9# it under the terms of the GNU Affero General Public License as
10# published by the Free Software Foundation, either version 3 of the
11# License, or (at your option) any later version.
12#
13# This program is distributed in the hope that it will be useful,
14# but WITHOUT ANY WARRANTY; without even the implied warranty of
15# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16# GNU Affero General Public License for more details.
17#
18# You should have received a copy of the GNU Affero General Public License
19# along with this program. If not, see <http://www.gnu.org/licenses/>.
20#
21###############################################################################
22
23from openerp.tools import config
24from odoo_sentry_client import BzrClient
25from odoo_sentry_handler import OdooSentryHandler
26import logging
27import cgitb
28
29
30root_logger = logging.root
31
32processors = (
33 'raven.processors.SanitizePasswordsProcessor',
34 'raven_sanitize_openerp.OpenerpPasswordsProcessor'
35)
36if config.get(u'sentry_dsn'):
37 cgitb.enable()
38 # Get DSN info from config file or ~/.openerp_serverrc (recommended)
39 dsn = config.get('sentry_dsn')
40 # Create Client
41 client = BzrClient(
42 dsn=dsn,
43 processors=processors,
44 )
45 handler = OdooSentryHandler(client, level=logging.ERROR)
46 root_logger.addHandler(handler)
47else:
48 root_logger.get(__name__).warn(u"Sentry DSN not defined in config file")
49 client = None
050
=== added file 'sentry/__openerp__.py'
--- sentry/__openerp__.py 1970-01-01 00:00:00 +0000
+++ sentry/__openerp__.py 2014-06-10 19:58:30 +0000
@@ -0,0 +1,62 @@
1# -*- coding: utf-8 -*-
2##############################################################################
3#
4# OpenERP, Open Source Management Solution
5# This module copyright (C) 2010 - 2014 Savoir-faire Linux
6# (<http://www.savoirfairelinux.com>).
7#
8# This program is free software: you can redistribute it and/or modify
9# it under the terms of the GNU Affero General Public License as
10# published by the Free Software Foundation, either version 3 of the
11# License, or (at your option) any later version.
12#
13# This program is distributed in the hope that it will be useful,
14# but WITHOUT ANY WARRANTY; without even the implied warranty of
15# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16# GNU Affero General Public License for more details.
17#
18# You should have received a copy of the GNU Affero General Public License
19# along with this program. If not, see <http://www.gnu.org/licenses/>.
20#
21##############################################################################
22
23{
24 'name': "sentry",
25
26 'summary': "Sentry integration",
27 'description': """
28Sentry
29======
30
31Integration with Sentry Error reporting engine.
32
33Insert sentry DSN to ~/.openerp_serverrc with value:
34 sentry_dsn = sync+<Your Sentry DSN>
35
36Contributors
37------------
38* Sandy Carter (sandy.carter@savoirfairelinux.com)
39""",
40
41 'author': "Savoir-faire Linux",
42 'website': "http://www.savoirfairelinux.com",
43
44 # Categories can be used to filter modules in modules listing
45 # Check <odoo>/addons/base/module/module_data.xml of the full list
46 'category': 'Extra Tools',
47 'version': '1.0',
48
49 # any module necessary for this one to work correctly
50 'depends': ['base'],
51 'external_dependencies': {
52 'python': ['raven', 'raven_sanitize_openerp', 'bzrlib'],
53 },
54 'data': [
55 ],
56
57 'demo': [
58 ],
59
60 'tests': [
61 ],
62}
063
=== 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-10 19:58:30 +0000
@@ -0,0 +1,104 @@
1# -*- coding: utf-8 -*-
2###############################################################################
3#
4# OpenERP, Open Source Management Solution
5# This module copyright (C) 2010 - 2014 Savoir-faire Linux
6# (<http://www.savoirfairelinux.com>).
7#
8# This program is free software: you can redistribute it and/or modify
9# it under the terms of the GNU Affero General Public License as
10# published by the Free Software Foundation, either version 3 of the
11# License, or (at your option) any later version.
12#
13# This program is distributed in the hope that it will be useful,
14# but WITHOUT ANY WARRANTY; without even the implied warranty of
15# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16# GNU Affero General Public License for more details.
17#
18# You should have received a copy of the GNU Affero General Public License
19# along with this program. If not, see <http://www.gnu.org/licenses/>.
20#
21###############################################################################
22
23import logging
24import platform
25import os
26import sys
27from raven import Client
28from bzrlib.branch import Branch
29from bzrlib.errors import NotBranchError
30from openerp.tools import config
31
32_logger = logging.getLogger(__name__)
33
34
35class BzrClient(Client):
36 """Subclass raven.Client to be able to report Bazaar revno as Module
37 versions"""
38
39 def __init__(self, dsn=None, **options):
40 # Send the following library versions, include all eggs
41 include_paths = [
42 'openerp',
43 'sentry',
44 'raven',
45 'raven_sanitize_openerp',
46 ] + [os.path.basename(i).split('-')[0]
47 for i in sys.path if i.endswith('.egg')]
48 # Add tags, OS and bzr revisions for Server and Addons
49 tags = {
50 'OS': (" ".join(platform.linux_distribution()).strip() or
51 " ".join(platform.win32_ver()).strip() or
52 " ".join((platform.system(), platform.release(),
53 platform.machine()))),
54 }
55 self.bzr_revs = {}
56 super(BzrClient, self).__init__(
57 dsn=dsn, include_paths=include_paths, tags=tags, **options)
58 self.set_rev_version(config.get(u'root_path') + u"/..", )
59 # Create and test message for Sentry
60 self.captureMessage(u'Sentry Tracking Activated!')
61
62 def set_rev_version(self, path):
63 """Given path, get source and revno, careful not to raise any
64 exceptions"""
65 try:
66 branch, rel_path = Branch.open_containing(path)
67 branch.lock_read()
68 # Clean name
69 name = (
70 branch.get_parent().replace(u'bazaar.launchpad.net/', u'lp:')
71 .replace(u'%7E', u'~')
72 .replace(u'%2Bbranch/', u'')
73 .replace(u'bzr+ssh://', u''))
74 self.bzr_revs[name] = u'r%i' % branch.revno()
75 branch.unlock()
76 except NotBranchError:
77 return
78 except:
79 if branch.is_locked():
80 branch.unlock()
81 return
82
83 def captureException(self, params=None, exc_info=None, **kwargs):
84 self.extra[u'params'] = params
85 # Store exc_info in case another exception is raised.
86 exc_info = sys.exc_info()
87 try:
88 # Using bzrlib find revision numbers for server and addons
89 for path in config.get(u'addons_path').split(u','):
90 self.set_rev_version(path)
91 finally:
92 pass
93 return super(BzrClient, self).captureException(
94 exc_info=exc_info, **kwargs)
95
96 def build_msg(self, event_type, data=None, date=None,
97 time_spent=None, extra=None, stack=None, public_key=None,
98 tags=None, **kwargs):
99 """Add bzr revnos to msg's modules"""
100 res = super(BzrClient, self).build_msg(
101 event_type, data, date, time_spent, extra, stack, public_key,
102 tags, **kwargs)
103 res['modules'] = dict(res['modules'].items() + self.bzr_revs.items())
104 return res
0105
=== 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-10 19:58:30 +0000
@@ -0,0 +1,32 @@
1# -*- coding: utf-8 -*-
2# ##############################################################################
3#
4# OpenERP, Open Source Management Solution
5# This module copyright (C) 2010 - 2014 Savoir-faire Linux
6# (<http://www.savoirfairelinux.com>).
7#
8# This program is free software: you can redistribute it and/or modify
9# it under the terms of the GNU Affero General Public License as
10# published by the Free Software Foundation, either version 3 of the
11# License, or (at your option) any later version.
12#
13# This program is distributed in the hope that it will be useful,
14# but WITHOUT ANY WARRANTY; without even the implied warranty of
15# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16# GNU Affero General Public License for more details.
17#
18# You should have received a copy of the GNU Affero General Public License
19# along with this program. If not, see <http://www.gnu.org/licenses/>.
20#
21###############################################################################
22
23from openerp.osv.orm import except_orm
24from raven.handlers.logging import SentryHandler
25
26
27class OdooSentryHandler(SentryHandler, object):
28
29 def can_record(self, record):
30 if record.exc_info and record.exc_info[0] is except_orm:
31 return False
32 return super(OdooSentryHandler, self).can_record(record)