add sentry support

This commit is contained in:
codl 2017-08-07 13:29:31 +02:00
parent fdf7148cf1
commit a1b9cb4311
No known key found for this signature in database
GPG Key ID: 6CD7C8891ED1233A
4 changed files with 17 additions and 2 deletions

5
app.py
View File

@ -27,3 +27,8 @@ metadata = MetaData(naming_convention = {
db = SQLAlchemy(app, metadata=metadata)
migrate = Migrate(app, db)
sentry = None
if 'SENTRY_DSN' in app.config:
from raven.contrib.flask import Sentry
sentry = Sentry(app, dsn=app.config['SENTRY_DSN'])

View File

@ -31,6 +31,8 @@ CELERY_BROKER='amqp://'
HTTPS=True
# SENTRY_DSN='https://foo:bar@sentry.io/69420'
"""
you can also use any config variable that flask expects here, such as
"""

View File

@ -1,8 +1,10 @@
alembic==0.9.3
amqp==2.2.1
billiard==3.5.0.3
blinker==1.4
celery==4.1.0
click==6.7
contextlib2==0.5.5
Flask==0.12.2
Flask-Migrate==2.0.4
Flask-Script==2.0.5
@ -18,6 +20,7 @@ psycopg2==2.7.1
python-dateutil==2.6.0
python-editor==1.0.3
pytz==2017.2
raven==6.1.0
six==1.10.0
SQLAlchemy==1.1.11
twitter==1.17.1

View File

@ -1,11 +1,10 @@
from app import app
from flask import render_template, url_for, redirect, request, g, Response
from datetime import datetime, timedelta
import lib.twitter
import lib
from lib import require_auth
from model import Account, Session, Post, TwitterArchive
from app import db
from app import app, db, sentry
import tasks
@app.before_request
@ -14,6 +13,12 @@ def load_viewer():
sid = request.cookies.get('forget_sid', None)
if sid:
g.viewer = Session.query.get(sid)
if g.viewer and sentry:
sentry.user_context({
'id': g.viewer.account.id,
'username': g.viewer.account.screen_name,
'service': g.viewer.account.service
})
@app.after_request
def touch_viewer(resp):