11# -*- coding: utf-8 -*-
22# This file is part of openerp-sentry. The COPYRIGHT file at the top level of
33# this repository contains the full copyright notices and license terms.
4-
4+ import os
55from osv import osv
66from tools import config
7- from tools .translate import _
87import pooler
8+ import netsvc
99
1010from raven import Client
1111
1212
13+ def log (msg , level = netsvc .LOG_INFO ):
14+ logger = netsvc .Logger ()
15+ logger .notifyChannel ('sentry' , netsvc .LOG_INFO , msg )
16+
17+
1318class SentyDispatcherException (Exception ):
1419 def __init__ (self , exception , traceback ):
1520 # Ugly hack to know wich type of exception it is.
@@ -26,10 +31,7 @@ def __init__(self, exception, traceback):
2631
2732
2833def monkeypatch ():
29- import netsvc
30- logger = netsvc .Logger ()
31- logger .notifyChannel ('sentry' , netsvc .LOG_INFO ,
32- u'Monkeypatching OpenERPDispatcherException!' )
34+ log (u'Monkeypatching OpenERPDispatcherException!' )
3335 netsvc .OpenERPDispatcherException = SentyDispatcherException
3436
3537
@@ -39,16 +41,19 @@ class SentrySetup(osv.osv):
3941 _name = 'sentry.setup'
4042
4143 def __init__ (self , pool , cursor ):
42- if not config .get ('sentry_dsn' , False ):
43- raise osv .except_osv (
44- _ (u'Error' ),
45- _ (u'No sentry DSN configured in config file.' )
46- )
4744 processors = (
4845 'raven.processors.SanitizePasswordsProcessor' ,
4946 'raven_sanitize_openerp.OpenerpPasswordsProcessor'
5047 )
51- self .client = Client (dsn = config ['sentry_dsn' ], processors = processors )
48+ dsn_env = os .getenv ('SENTRY_DSN' )
49+ dsn = config .get ('sentry_dsn' )
50+ if dsn_env :
51+ config ['sentry_dsn' ] = dsn_env
52+ log ('Updating sentry_dsn=%s conf from environment var' % dsn_env )
53+ elif dsn :
54+ os .environ ['SENTRY_DSN' ] = dsn
55+ log ('Setting up SENTRY_DSN=%s environment var' % dsn )
56+ self .client = Client (processors = processors )
5257 monkeypatch ()
5358 super (SentrySetup , self ).__init__ (pool , cursor )
5459
0 commit comments