-
Notifications
You must be signed in to change notification settings - Fork 8
/
sentry.py
34 lines (26 loc) · 820 Bytes
/
sentry.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#enconding:utf-8
from os.path import join
import logging
import yaml
from raven import Client
from raven.handlers.logging import SentryHandler
from raven.conf import setup_logging
with open(join('config', 'sentry.yml')) as config_file:
config = yaml.load(config_file.read())
if 'sentry_secret' in config:
client = Client(config['sentry_secret'], auto_log_stacks=True)
handler = SentryHandler(client)
setup_logging(handler)
else:
client = None
logging.info('Sentry.io not loaded')
def report_error(fn):
def wrapper(*args, **kwargs):
try:
fn(*args, **kwargs)
except Exception:
if client: # has sentry instance
client.captureException()
else:
logging.exception('Exception Ignored.')
return wrapper