11import logging
22from logging .handlers import RotatingFileHandler , SMTPHandler
3+ import raven
34import raven .base
45import raven .contrib .flask
56import raven .transport .threaded_requests
67
7- sentry_client = None
8+
9+ class MissingRavenClient (raven .Client ):
10+ """Raven client class that is used as a placeholder.
11+ This is done to make sure that calls to functions in the client don't fail
12+ even if the client is not initialized. Sentry server might be missing, but
13+ we don't want to check if it actually exists in every place exception is
14+ captured.
15+ """
16+ captureException = lambda self , * args , ** kwargs : None
17+ captureMessage = lambda self , * args , ** kwargs : None
18+
19+
20+ _sentry_client = MissingRavenClient () # type: raven.Client
821
922
1023def add_file_handler (app , filename , max_bytes = 512 * 1024 , backup_count = 100 ):
@@ -54,8 +67,8 @@ def add_sentry(app, dsn, level=logging.WARNING, **options):
5467 """
5568 app .config ["SENTRY_TRANSPORT" ] = raven .transport .threaded_requests .ThreadedRequestsHTTPTransport
5669 app .config ["SENTRY_CONFIG" ] = options
57- global sentry_client
58- sentry_client = raven .contrib .flask .Sentry (
70+ global _sentry_client
71+ _sentry_client = raven .contrib .flask .Sentry (
5972 app = app ,
6073 dsn = dsn ,
6174 level = level ,
@@ -64,5 +77,4 @@ def add_sentry(app, dsn, level=logging.WARNING, **options):
6477
6578
6679def get_sentry_client ():
67- global sentry_client
68- return sentry_client
80+ return _sentry_client
0 commit comments