From 78dccb27abe50c167dacbab3883bd1bd01d373d4 Mon Sep 17 00:00:00 2001 From: Uddeshya Singh Date: Wed, 29 May 2019 13:45:54 +0530 Subject: [PATCH 1/4] implement new sentry sdk --- app/__init__.py | 5 +++-- app/views/sentry.py | 3 --- requirements/common.txt | 2 +- 3 files changed, 4 insertions(+), 6 deletions(-) delete mode 100644 app/views/sentry.py diff --git a/app/__init__.py b/app/__init__.py index 442743aa22..4796713cc6 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -36,12 +36,13 @@ from app.models.event import Event from app.models.role_invite import RoleInvite from app.views.healthcheck import health_check_celery, health_check_db, health_check_migrations, check_migrations -from app.views.sentry import sentry from app.views.elastic_search import client from app.views.elastic_cron_helpers import sync_events_elasticsearch, cron_rebuild_events_elasticsearch from app.views.redis_store import redis_store from app.views.celery_ import celery from app.templates.flask_ext.jinja.filters import init_filters +import sentry_sdk +from sentry_sdk.integrations.flask import FlaskIntegration BASE_DIR = os.path.dirname(os.path.abspath(__file__)) @@ -157,7 +158,7 @@ def create_app(): # sentry if not app_created and 'SENTRY_DSN' in app.config: - sentry.init_app(app, dsn=app.config['SENTRY_DSN']) + sentry_sdk.init(app.config['SENTRY_DSN'], integrations=[FlaskIntegration()]) # redis redis_store.init_app(app) diff --git a/app/views/sentry.py b/app/views/sentry.py deleted file mode 100644 index 20ddeef3cd..0000000000 --- a/app/views/sentry.py +++ /dev/null @@ -1,3 +0,0 @@ -from raven.contrib.flask import Sentry - -sentry = Sentry() diff --git a/requirements/common.txt b/requirements/common.txt index 5c4dab50a3..e5ea16a4ea 100644 --- a/requirements/common.txt +++ b/requirements/common.txt @@ -48,7 +48,7 @@ wtforms~=2.2 flask-admin~=1.5 google-compute-engine~=2.8 factory_boy~=2.12 -raven[flask]~=6.10 +sentry-sdk[flask] healthcheck~=1.3 elasticsearch-dsl~=7.0 flask-redis~=0.3 From 73fe982494f3a217e50c440e01daf0ba79d01042 Mon Sep 17 00:00:00 2001 From: Uddeshya Singh Date: Wed, 29 May 2019 14:00:04 +0530 Subject: [PATCH 2/4] modify healthchecks with new sentry --- app/api/events.py | 2 +- app/views/healthcheck.py | 17 ++++++++--------- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/app/api/events.py b/app/api/events.py index 02f2cf06ab..849765b58c 100644 --- a/app/api/events.py +++ b/app/api/events.py @@ -49,7 +49,7 @@ from app.models.user import User, ATTENDEE, ORGANIZER, COORGANIZER from app.models.users_events_role import UsersEventsRoles from app.models.stripe_authorization import StripeAuthorization - +from sentry_sdk import capture_exception def validate_event(user, modules, data): if not user.can_create_event(): diff --git a/app/views/healthcheck.py b/app/views/healthcheck.py index dc6b524ff5..08c4b9dc44 100644 --- a/app/views/healthcheck.py +++ b/app/views/healthcheck.py @@ -5,8 +5,7 @@ from redis.exceptions import ConnectionError from app.models import db -from app.views.sentry import sentry - +from sentry_sdk import capture_exception, capture_message def health_check_celery(): """ @@ -16,22 +15,22 @@ def health_check_celery(): try: d = inspect().stats() if not d: - sentry.captureMessage('No running Celery workers were found.') + capture_message('No running Celery workers were found.') return False, 'No running Celery workers were found.' except ConnectionError as e: - sentry.captureException() + capture_exception(e) return False, 'cannot connect to redis server' except IOError as e: msg = "Error connecting to the backend: " + str(e) if len(e.args) > 0 and errorcode.get(e.args[0]) == 'ECONNREFUSED': msg += ' Check that the Redis server is running.' - sentry.captureException() + capture_exception(e) return False, msg except ImportError as e: - sentry.catureException() + capture_exception(e) return False, str(e) except Exception: - sentry.captureException() + capture_exception() return False, 'celery not ok' return True, 'celery ok' @@ -45,7 +44,7 @@ def health_check_db(): db.session.execute('SELECT 1') return True, 'database ok' except: - sentry.captureException() + capture_exception() return False, 'Error connecting to database' @@ -71,7 +70,7 @@ def check_migrations(): try: db.session.query(model).first() except: - sentry.captureException() + capture_exception() return 'failure,{} model out of date with migrations'.format(model) return 'success,database up to date with migrations' From 9b4915e17558b8e0fb9ad2595c22fe72e8468d6d Mon Sep 17 00:00:00 2001 From: Uddeshya Singh Date: Wed, 29 May 2019 14:01:22 +0530 Subject: [PATCH 3/4] remove sentry import in api route (test) --- app/api/events.py | 1 - 1 file changed, 1 deletion(-) diff --git a/app/api/events.py b/app/api/events.py index 849765b58c..a3e512f75a 100644 --- a/app/api/events.py +++ b/app/api/events.py @@ -49,7 +49,6 @@ from app.models.user import User, ATTENDEE, ORGANIZER, COORGANIZER from app.models.users_events_role import UsersEventsRoles from app.models.stripe_authorization import StripeAuthorization -from sentry_sdk import capture_exception def validate_event(user, modules, data): if not user.can_create_event(): From a96bfcf0102521ebea3d40b7c64abe9ef6ebd315 Mon Sep 17 00:00:00 2001 From: Uddeshya Singh Date: Wed, 29 May 2019 14:53:53 +0530 Subject: [PATCH 4/4] Update common.txt --- requirements/common.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements/common.txt b/requirements/common.txt index e5ea16a4ea..f92f0ee448 100644 --- a/requirements/common.txt +++ b/requirements/common.txt @@ -48,7 +48,7 @@ wtforms~=2.2 flask-admin~=1.5 google-compute-engine~=2.8 factory_boy~=2.12 -sentry-sdk[flask] +sentry-sdk[flask]~=0.8 healthcheck~=1.3 elasticsearch-dsl~=7.0 flask-redis~=0.3