|
|
@ -11,10 +11,12 @@ from . import const |
|
|
|
from .logutils import LoggerNameFilter, OdooSentryHandler |
|
|
|
|
|
|
|
_logger = logging.getLogger(__name__) |
|
|
|
HAS_RAVEN = True |
|
|
|
try: |
|
|
|
import raven |
|
|
|
from raven.middleware import Sentry |
|
|
|
except ImportError: |
|
|
|
HAS_RAVEN = False |
|
|
|
_logger.debug('Cannot import "raven". Please make sure it is installed.') |
|
|
|
|
|
|
|
|
|
|
@ -29,25 +31,25 @@ def get_odoo_commit(odoo_dir): |
|
|
|
u'Odoo directory: "%s" not a valid git repository', odoo_dir) |
|
|
|
|
|
|
|
|
|
|
|
def initialize_raven(config, client_cls=raven.Client): |
|
|
|
def initialize_raven(config, client_cls=None): |
|
|
|
''' |
|
|
|
Setup an instance of :class:`raven.Client`. |
|
|
|
|
|
|
|
:param config: Sentry configuration |
|
|
|
:param client: class used to instantiate the raven client. |
|
|
|
''' |
|
|
|
enabled = config.get('sentry_enabled', False) |
|
|
|
if not (HAS_RAVEN and enabled): |
|
|
|
return |
|
|
|
options = { |
|
|
|
'release': get_odoo_commit(config.get('sentry_odoo_dir')), |
|
|
|
} |
|
|
|
for option in const.SENTRY_OPTIONS: |
|
|
|
for option in const.get_sentry_options(): |
|
|
|
value = config.get('sentry_%s' % option.key, option.default) |
|
|
|
if callable(option.converter): |
|
|
|
value = option.converter(value) |
|
|
|
options[option.key] = value |
|
|
|
|
|
|
|
client = client_cls(**options) |
|
|
|
|
|
|
|
enabled = config.get('sentry_enabled', True) |
|
|
|
level = config.get('sentry_logging_level', const.DEFAULT_LOG_LEVEL) |
|
|
|
exclude_loggers = const.split_multiple( |
|
|
|
config.get('sentry_exclude_loggers', const.DEFAULT_EXCLUDE_LOGGERS) |
|
|
@ -55,7 +57,8 @@ def initialize_raven(config, client_cls=raven.Client): |
|
|
|
if level not in const.LOG_LEVEL_MAP: |
|
|
|
level = const.DEFAULT_LOG_LEVEL |
|
|
|
|
|
|
|
if enabled: |
|
|
|
client_cls = client_cls or raven.Client |
|
|
|
client = client_cls(**options) |
|
|
|
handler = OdooSentryHandler( |
|
|
|
config.get('sentry_include_context', True), |
|
|
|
client=client, |
|
|
@ -68,8 +71,8 @@ def initialize_raven(config, client_cls=raven.Client): |
|
|
|
wsgi_server.application = Sentry( |
|
|
|
wsgi_server.application, client=client) |
|
|
|
|
|
|
|
client.captureMessage('Starting Odoo Server') |
|
|
|
return client |
|
|
|
|
|
|
|
|
|
|
|
sentry_client = initialize_raven(odoo_config) |
|
|
|
sentry_client.captureMessage('Starting Odoo Server') |