plugin/raven: Fix paster's celery config issue
[mediagoblin.git] / mediagoblin / plugins / raven / __init__.py
1 # GNU MediaGoblin -- federated, autonomous media hosting
2 # Copyright (C) 2011, 2012 MediaGoblin contributors. See AUTHORS.
3 #
4 # This program is free software: you can redistribute it and/or modify
5 # it under the terms of the GNU Affero General Public License as published by
6 # the Free Software Foundation, either version 3 of the License, or
7 # (at your option) any later version.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU Affero General Public License for more details.
13 #
14 # You should have received a copy of the GNU Affero General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
16
17 import os
18 import logging
19
20 from mediagoblin.tools import pluginapi
21
22 _log = logging.getLogger(__name__)
23
24
25 def setup_plugin():
26 if not os.environ.get('CELERY_CONFIG_MODULE'):
27 # Exit early if we're (seemingly) not called from the celery process
28 return
29
30 from raven import Client
31 from raven.contrib.celery import register_signal
32 config = pluginapi.get_config('mediagoblin.plugins.raven')
33
34 _log.info('Setting up raven for celery...')
35
36 sentry_dsn = config.get('sentry_dsn')
37
38 if sentry_dsn:
39 _log.info('Setting up raven from plugin config: {0}'.format(
40 sentry_dsn))
41 client = Client(sentry_dsn)
42 elif os.environ.get('SENTRY_DSN'):
43 _log.info('Setting up raven from SENTRY_DSN environment variable: {0}'\
44 .format(os.environ.get('SENTRY_DSN')))
45 client = Client() # Implicitly looks for SENTRY_DSN
46 else:
47 _log.error('Could not set up client, missing sentry DSN')
48 return
49
50 register_signal(client)
51
52
53 hooks = {
54 'setup': setup_plugin,
55 }