Skip to content

Commit

Permalink
Upgrade Sentry SDK (#3418)
Browse files Browse the repository at this point in the history
* replace raven with sentry-sdk

* use sentry-sdk in celery

* use sentry-sdk with flask

* unify Flask and Celery initializations for Sentry

* extract sentry stuff to own module

* it's time for Sentry 0.7.2
  • Loading branch information
Omer Lachish authored Feb 10, 2019
1 parent 23908ed commit 71fb144
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 23 deletions.
18 changes: 4 additions & 14 deletions redash/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import urlparse
import urllib

import redis
import redis
from flask import Flask, current_app
from flask_sslify import SSLify
from werkzeug.contrib.fixers import ProxyFix
Expand Down Expand Up @@ -97,6 +97,9 @@ def create_app(load_admin=True):
from redash.handlers import chrome_logger
from redash.models import db, users
from redash.metrics.request import provision_app
from redash.utils import sentry

sentry.init()

app = Flask(__name__,
template_folder=settings.STATIC_ASSETS_PATH,
Expand All @@ -110,19 +113,6 @@ def create_app(load_admin=True):
if settings.ENFORCE_HTTPS:
SSLify(app, skips=['ping'])

if settings.SENTRY_DSN:
from raven import Client
from raven.contrib.flask import Sentry
from raven.handlers.logging import SentryHandler

client = Client(settings.SENTRY_DSN, release=__version__, install_logging_hook=False)
sentry = Sentry(app, client=client)
sentry.client.release = __version__

sentry_handler = SentryHandler(client=client)
sentry_handler.setLevel(logging.ERROR)
logging.getLogger().addHandler(sentry_handler)

# configure our database
app.config['SQLALCHEMY_DATABASE_URI'] = settings.SQLALCHEMY_DATABASE_URI
app.config.update(settings.all_settings())
Expand Down
26 changes: 26 additions & 0 deletions redash/utils/sentry.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import sentry_sdk
from sentry_sdk.integrations.flask import FlaskIntegration
from sentry_sdk.integrations.celery import CeleryIntegration
from redash import settings, __version__


NON_REPORTED_EXCEPTIONS = ['QueryExecutionError']


def before_send(event, hint):
if 'exc_info' in hint:
exc_type, exc_value, tb = hint['exc_info']
if any([(e in str(type(exc_value))) for e in NON_REPORTED_EXCEPTIONS]):
return None

return event


def init():
if settings.SENTRY_DSN:
sentry_sdk.init(
dsn=settings.SENTRY_DSN,
release=__version__,
before_send=before_send,
integrations=[FlaskIntegration(), CeleryIntegration()]
)
9 changes: 1 addition & 8 deletions redash/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from celery import Celery
from celery.schedules import crontab
from celery.signals import worker_process_init
from redash import __version__, safe_create_app, settings
from redash import safe_create_app, settings
from redash.metrics import celery as celery_metrics

celery = Celery('redash',
Expand Down Expand Up @@ -55,13 +55,6 @@
worker_log_format=settings.CELERYD_WORKER_LOG_FORMAT,
worker_task_log_format=settings.CELERYD_WORKER_TASK_LOG_FORMAT)

if settings.SENTRY_DSN:
from raven import Client
from raven.contrib.celery import register_signal

client = Client(settings.SENTRY_DSN, release=__version__, install_logging_hook=False)
register_signal(client)


# Create a new Task base class, that pushes a new Flask app context to allow DB connections if needed.
TaskBase = celery.Task
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ RestrictedPython==3.6.0
pysaml2==4.5.0
pycrypto==2.6.1
funcy==1.7.1
raven==6.0.0
sentry-sdk==0.7.2
semver==2.2.1
xlsxwriter==0.9.3
pystache==0.5.4
Expand Down

0 comments on commit 71fb144

Please sign in to comment.