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
1=== added directory 'sentry'
2=== added file 'sentry/__init__.py'
3--- sentry/__init__.py 1970-01-01 00:00:00 +0000
4+++ sentry/__init__.py 2014-06-10 19:58:30 +0000
5@@ -0,0 +1,49 @@
6+# -*- coding: utf-8 -*-
7+###############################################################################
8+#
9+# OpenERP, Open Source Management Solution
10+# This module copyright (C) 2010 - 2014 Savoir-faire Linux
11+# (<http://www.savoirfairelinux.com>).
12+#
13+# This program is free software: you can redistribute it and/or modify
14+# it under the terms of the GNU Affero General Public License as
15+# published by the Free Software Foundation, either version 3 of the
16+# License, or (at your option) any later version.
17+#
18+# This program is distributed in the hope that it will be useful,
19+# but WITHOUT ANY WARRANTY; without even the implied warranty of
20+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21+# GNU Affero General Public License for more details.
22+#
23+# You should have received a copy of the GNU Affero General Public License
24+# along with this program. If not, see <http://www.gnu.org/licenses/>.
25+#
26+###############################################################################
27+
28+from openerp.tools import config
29+from odoo_sentry_client import BzrClient
30+from odoo_sentry_handler import OdooSentryHandler
31+import logging
32+import cgitb
33+
34+
35+root_logger = logging.root
36+
37+processors = (
38+ 'raven.processors.SanitizePasswordsProcessor',
39+ 'raven_sanitize_openerp.OpenerpPasswordsProcessor'
40+)
41+if config.get(u'sentry_dsn'):
42+ cgitb.enable()
43+ # Get DSN info from config file or ~/.openerp_serverrc (recommended)
44+ dsn = config.get('sentry_dsn')
45+ # Create Client
46+ client = BzrClient(
47+ dsn=dsn,
48+ processors=processors,
49+ )
50+ handler = OdooSentryHandler(client, level=logging.ERROR)
51+ root_logger.addHandler(handler)
52+else:
53+ root_logger.get(__name__).warn(u"Sentry DSN not defined in config file")
54+ client = None
55
56=== added file 'sentry/__openerp__.py'
57--- sentry/__openerp__.py 1970-01-01 00:00:00 +0000
58+++ sentry/__openerp__.py 2014-06-10 19:58:30 +0000
59@@ -0,0 +1,62 @@
60+# -*- coding: utf-8 -*-
61+##############################################################################
62+#
63+# OpenERP, Open Source Management Solution
64+# This module copyright (C) 2010 - 2014 Savoir-faire Linux
65+# (<http://www.savoirfairelinux.com>).
66+#
67+# This program is free software: you can redistribute it and/or modify
68+# it under the terms of the GNU Affero General Public License as
69+# published by the Free Software Foundation, either version 3 of the
70+# License, or (at your option) any later version.
71+#
72+# This program is distributed in the hope that it will be useful,
73+# but WITHOUT ANY WARRANTY; without even the implied warranty of
74+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
75+# GNU Affero General Public License for more details.
76+#
77+# You should have received a copy of the GNU Affero General Public License
78+# along with this program. If not, see <http://www.gnu.org/licenses/>.
79+#
80+##############################################################################
81+
82+{
83+ 'name': "sentry",
84+
85+ 'summary': "Sentry integration",
86+ 'description': """
87+Sentry
88+======
89+
90+Integration with Sentry Error reporting engine.
91+
92+Insert sentry DSN to ~/.openerp_serverrc with value:
93+ sentry_dsn = sync+<Your Sentry DSN>
94+
95+Contributors
96+------------
97+* Sandy Carter (sandy.carter@savoirfairelinux.com)
98+""",
99+
100+ 'author': "Savoir-faire Linux",
101+ 'website': "http://www.savoirfairelinux.com",
102+
103+ # Categories can be used to filter modules in modules listing
104+ # Check <odoo>/addons/base/module/module_data.xml of the full list
105+ 'category': 'Extra Tools',
106+ 'version': '1.0',
107+
108+ # any module necessary for this one to work correctly
109+ 'depends': ['base'],
110+ 'external_dependencies': {
111+ 'python': ['raven', 'raven_sanitize_openerp', 'bzrlib'],
112+ },
113+ 'data': [
114+ ],
115+
116+ 'demo': [
117+ ],
118+
119+ 'tests': [
120+ ],
121+}
122
123=== added file 'sentry/odoo_sentry_client.py'
124--- sentry/odoo_sentry_client.py 1970-01-01 00:00:00 +0000
125+++ sentry/odoo_sentry_client.py 2014-06-10 19:58:30 +0000
126@@ -0,0 +1,104 @@
127+# -*- coding: utf-8 -*-
128+###############################################################################
129+#
130+# OpenERP, Open Source Management Solution
131+# This module copyright (C) 2010 - 2014 Savoir-faire Linux
132+# (<http://www.savoirfairelinux.com>).
133+#
134+# This program is free software: you can redistribute it and/or modify
135+# it under the terms of the GNU Affero General Public License as
136+# published by the Free Software Foundation, either version 3 of the
137+# License, or (at your option) any later version.
138+#
139+# This program is distributed in the hope that it will be useful,
140+# but WITHOUT ANY WARRANTY; without even the implied warranty of
141+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
142+# GNU Affero General Public License for more details.
143+#
144+# You should have received a copy of the GNU Affero General Public License
145+# along with this program. If not, see <http://www.gnu.org/licenses/>.
146+#
147+###############################################################################
148+
149+import logging
150+import platform
151+import os
152+import sys
153+from raven import Client
154+from bzrlib.branch import Branch
155+from bzrlib.errors import NotBranchError
156+from openerp.tools import config
157+
158+_logger = logging.getLogger(__name__)
159+
160+
161+class BzrClient(Client):
162+ """Subclass raven.Client to be able to report Bazaar revno as Module
163+ versions"""
164+
165+ def __init__(self, dsn=None, **options):
166+ # Send the following library versions, include all eggs
167+ include_paths = [
168+ 'openerp',
169+ 'sentry',
170+ 'raven',
171+ 'raven_sanitize_openerp',
172+ ] + [os.path.basename(i).split('-')[0]
173+ for i in sys.path if i.endswith('.egg')]
174+ # Add tags, OS and bzr revisions for Server and Addons
175+ tags = {
176+ 'OS': (" ".join(platform.linux_distribution()).strip() or
177+ " ".join(platform.win32_ver()).strip() or
178+ " ".join((platform.system(), platform.release(),
179+ platform.machine()))),
180+ }
181+ self.bzr_revs = {}
182+ super(BzrClient, self).__init__(
183+ dsn=dsn, include_paths=include_paths, tags=tags, **options)
184+ self.set_rev_version(config.get(u'root_path') + u"/..", )
185+ # Create and test message for Sentry
186+ self.captureMessage(u'Sentry Tracking Activated!')
187+
188+ def set_rev_version(self, path):
189+ """Given path, get source and revno, careful not to raise any
190+ exceptions"""
191+ try:
192+ branch, rel_path = Branch.open_containing(path)
193+ branch.lock_read()
194+ # Clean name
195+ name = (
196+ branch.get_parent().replace(u'bazaar.launchpad.net/', u'lp:')
197+ .replace(u'%7E', u'~')
198+ .replace(u'%2Bbranch/', u'')
199+ .replace(u'bzr+ssh://', u''))
200+ self.bzr_revs[name] = u'r%i' % branch.revno()
201+ branch.unlock()
202+ except NotBranchError:
203+ return
204+ except:
205+ if branch.is_locked():
206+ branch.unlock()
207+ return
208+
209+ def captureException(self, params=None, exc_info=None, **kwargs):
210+ self.extra[u'params'] = params
211+ # Store exc_info in case another exception is raised.
212+ exc_info = sys.exc_info()
213+ try:
214+ # Using bzrlib find revision numbers for server and addons
215+ for path in config.get(u'addons_path').split(u','):
216+ self.set_rev_version(path)
217+ finally:
218+ pass
219+ return super(BzrClient, self).captureException(
220+ exc_info=exc_info, **kwargs)
221+
222+ def build_msg(self, event_type, data=None, date=None,
223+ time_spent=None, extra=None, stack=None, public_key=None,
224+ tags=None, **kwargs):
225+ """Add bzr revnos to msg's modules"""
226+ res = super(BzrClient, self).build_msg(
227+ event_type, data, date, time_spent, extra, stack, public_key,
228+ tags, **kwargs)
229+ res['modules'] = dict(res['modules'].items() + self.bzr_revs.items())
230+ return res
231
232=== added file 'sentry/odoo_sentry_handler.py'
233--- sentry/odoo_sentry_handler.py 1970-01-01 00:00:00 +0000
234+++ sentry/odoo_sentry_handler.py 2014-06-10 19:58:30 +0000
235@@ -0,0 +1,32 @@
236+# -*- coding: utf-8 -*-
237+# ##############################################################################
238+#
239+# OpenERP, Open Source Management Solution
240+# This module copyright (C) 2010 - 2014 Savoir-faire Linux
241+# (<http://www.savoirfairelinux.com>).
242+#
243+# This program is free software: you can redistribute it and/or modify
244+# it under the terms of the GNU Affero General Public License as
245+# published by the Free Software Foundation, either version 3 of the
246+# License, or (at your option) any later version.
247+#
248+# This program is distributed in the hope that it will be useful,
249+# but WITHOUT ANY WARRANTY; without even the implied warranty of
250+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
251+# GNU Affero General Public License for more details.
252+#
253+# You should have received a copy of the GNU Affero General Public License
254+# along with this program. If not, see <http://www.gnu.org/licenses/>.
255+#
256+###############################################################################
257+
258+from openerp.osv.orm import except_orm
259+from raven.handlers.logging import SentryHandler
260+
261+
262+class OdooSentryHandler(SentryHandler, object):
263+
264+ def can_record(self, record):
265+ if record.exc_info and record.exc_info[0] is except_orm:
266+ return False
267+ return super(OdooSentryHandler, self).can_record(record)