Skip to content

Commit 504d429

Browse files
committed
Add a placeholder class for a missing Sentry client value
1 parent 87f2156 commit 504d429

1 file changed

Lines changed: 17 additions & 5 deletions

File tree

brainzutils/flask/loggers.py

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,23 @@
11
import logging
22
from logging.handlers import RotatingFileHandler, SMTPHandler
3+
import raven
34
import raven.base
45
import raven.contrib.flask
56
import 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

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

6679
def get_sentry_client():
67-
global sentry_client
68-
return sentry_client
80+
return _sentry_client

0 commit comments

Comments
 (0)