Skip to content

Commit 844d9a1

Browse files
committed
Added sentry to the backend
1 parent 139ba22 commit 844d9a1

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

backend/PyMatcha/__init__.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import os
2222

2323
import pymysql
24+
import sentry_sdk
2425
from celery import Celery
2526
from dotenv import load_dotenv
2627
from flask import Flask
@@ -32,6 +33,9 @@
3233
from PyMatcha.utils.tables import create_tables
3334
from pymysql.cursors import DictCursor
3435
from redis import StrictRedis
36+
from sentry_sdk import configure_scope
37+
from sentry_sdk.integrations.flask import FlaskIntegration
38+
3539

3640
PYMATCHA_ROOT = os.path.join(os.path.dirname(__file__), "../..") # refers to application_top
3741
dotenv_path = os.path.join(PYMATCHA_ROOT, ".env")
@@ -79,6 +83,13 @@
7983
if ENABLE_LOGGING == "True":
8084
setup_logging()
8185

86+
sentry_sdk.init(
87+
dsn="https://bb17c14c99d448e2804bf2f105d4ec52@o450203.ingest.sentry.io/5434438",
88+
integrations=[FlaskIntegration()],
89+
traces_sample_rate=1.0,
90+
)
91+
92+
8293
application = Flask(__name__)
8394

8495
if os.getenv("FLASK_DEBUG", "false") == "true" or os.getenv("FLASK_DEBUG", "false") == "1":
@@ -183,6 +194,9 @@ def jwt_user_callback(identity):
183194
except NotFoundError:
184195
# The user who the server issues the token for was deleted in the db.
185196
return None
197+
198+
with configure_scope() as scope:
199+
scope.user = {"email": u.email, "id": u.id, "username": u.username}
186200
redis.set("online_user:" + str(identity["id"]), datetime.datetime.utcnow().timestamp())
187201
return u
188202

backend/requirements.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,6 @@ argon2-cffi==20.1.0
3333

3434
geopy==2.0.0
3535
fuzzywuzzy==0.18.0
36-
python-Levenshtein==0.12.0
36+
python-Levenshtein==0.12.0
37+
38+
sentry-sdk==0.17.6

0 commit comments

Comments
 (0)