Skip to content
This repository was archived by the owner on Nov 18, 2024. It is now read-only.

Commit 154a036

Browse files
committed
Use SENTRY_DSN environment variable
1 parent cf06b70 commit 154a036

File tree

1 file changed

+17
-12
lines changed

1 file changed

+17
-12
lines changed

sentry/sentry.py

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,20 @@
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
55
from osv import osv
66
from tools import config
7-
from tools.translate import _
87
import pooler
8+
import netsvc
99

1010
from 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+
1318
class 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

2833
def 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

Comments
 (0)