mirror of
https://github.com/TitanEmbeds/Titan.git
synced 2024-11-12 17:11:20 +01:00
Utilize sentry to track execution errors
This commit is contained in:
parent
0efa1882a4
commit
a7d80c39d2
@ -10,4 +10,6 @@ config = {
|
||||
'bots-discord-pw-token': "bots.discord.pw Post Stats Token",
|
||||
|
||||
'logging-location': "/home/titan/Titan/discordbot/titanbot.log",
|
||||
|
||||
"sentry-dsn": "Copy the dns string when creating a project on sentry",
|
||||
}
|
||||
|
@ -5,6 +5,8 @@ from titanembeds.commands import Commands
|
||||
from titanembeds.socketio import SocketIOInterface
|
||||
from titanembeds.poststats import DiscordBotsOrg, BotsDiscordPw
|
||||
from collections import deque
|
||||
from raven import Client as RavenClient
|
||||
import raven
|
||||
import discord
|
||||
import aiohttp
|
||||
import asyncio
|
||||
@ -15,6 +17,10 @@ logging.basicConfig(filename='titanbot.log',level=logging.INFO,format='%(asctime
|
||||
handler = logging.FileHandler(config.get("logging-location", "titanbot.log"))
|
||||
logging.getLogger('TitanBot')
|
||||
logging.getLogger('sqlalchemy')
|
||||
try:
|
||||
raven_client = RavenClient(config["sentry-dsn"])
|
||||
except raven.exceptions.InvalidDsn:
|
||||
pass
|
||||
|
||||
class Titan(discord.AutoShardedClient):
|
||||
def __init__(self):
|
||||
|
@ -15,4 +15,6 @@ patreon
|
||||
flask-redis
|
||||
gino
|
||||
sqlalchemy==1.2.8
|
||||
asyncio_redis
|
||||
asyncio_redis
|
||||
raven
|
||||
raven[flask]
|
@ -27,4 +27,7 @@ config = {
|
||||
|
||||
# https://titanembeds.com/api/webhook/discordbotsorg/vote
|
||||
'discordbotsorg-webhook-secret': "Secret code used in the authorization header for DBL webhook",
|
||||
|
||||
# Sentry.io is used to track and upload errors
|
||||
"sentry-dsn": "Copy the dns string when creating a project on sentry",
|
||||
}
|
||||
|
@ -40,6 +40,10 @@ def init_debug():
|
||||
subprocess.Popen("git pull", shell=True).wait()
|
||||
except OSError:
|
||||
return "ERROR"
|
||||
|
||||
@app.route("/error")
|
||||
def make_error():
|
||||
1 / 0
|
||||
|
||||
return "OK"
|
||||
if __name__ == "__main__":
|
||||
|
@ -12,9 +12,9 @@ except:
|
||||
monkey.patch_all()
|
||||
|
||||
from .database import db
|
||||
from flask import Flask, render_template, request, session, url_for, redirect, jsonify
|
||||
from flask import Flask, render_template, request, session, url_for, redirect, jsonify, g
|
||||
from flask_sslify import SSLify
|
||||
from titanembeds.utils import rate_limiter, discord_api, socketio, babel, redis_store, language_code_list
|
||||
from titanembeds.utils import rate_limiter, discord_api, socketio, babel, redis_store, language_code_list, sentry
|
||||
from .blueprints import api, user, admin, embed, gateway
|
||||
import os
|
||||
from titanembeds.database import get_administrators_list
|
||||
@ -34,6 +34,7 @@ app.config['PERMANENT_SESSION_LIFETIME'] = timedelta(days=3)
|
||||
app.config['REDIS_URL'] = config["redis-uri"]
|
||||
app.secret_key = config['app-secret']
|
||||
|
||||
sentry.init_app(app)
|
||||
db.init_app(app)
|
||||
rate_limiter.init_app(app)
|
||||
if config.get("enable-ssl", False):
|
||||
@ -91,3 +92,10 @@ def context_processor():
|
||||
"af_mode_enabled": datetime.datetime.now().date() == datetime.date(datetime.datetime.now().year, 4, 1),
|
||||
"dbl_voted": session.get("unauthenticated", True) == False and bool(redis_store.get("DiscordBotsOrgVoted/" + str(session.get("user_id", -1))))
|
||||
}
|
||||
|
||||
@app.errorhandler(500)
|
||||
def internal_server_error(error):
|
||||
return render_template('500.html.j2',
|
||||
event_id=g.sentry_event_id,
|
||||
public_dsn=sentry.client.get_public_dsn('https')
|
||||
)
|
11
webapp/titanembeds/templates/500.html.j2
Normal file
11
webapp/titanembeds/templates/500.html.j2
Normal file
@ -0,0 +1,11 @@
|
||||
<!-- Sentry JS SDK 2.1.+ required -->
|
||||
<script src="https://cdn.ravenjs.com/2.3.0/raven.min.js"></script>
|
||||
|
||||
{% if event_id %}
|
||||
<script>
|
||||
Raven.showReportDialog({
|
||||
eventId: '{{ event_id }}',
|
||||
dsn: '{{ public_dsn }}'
|
||||
});
|
||||
</script>
|
||||
{% endif %}
|
@ -7,6 +7,7 @@ from flask_babel import Babel
|
||||
from flask_redis import FlaskRedis
|
||||
from config import config
|
||||
from sqlalchemy import and_
|
||||
from raven.contrib.flask import Sentry
|
||||
import random
|
||||
import string
|
||||
import hashlib
|
||||
@ -352,6 +353,7 @@ def is_int(specimen):
|
||||
rate_limiter = Limiter(key_func=get_client_ipaddr) # Default limit by ip address
|
||||
socketio = SocketIO(engineio_logger=config.get("engineio-logging", False))
|
||||
babel = Babel()
|
||||
sentry = Sentry(dsn=config.get("sentry-dsn", None))
|
||||
|
||||
@socketio.on_error_default # disconnect on all errors
|
||||
def default_socketio_error_handler(e):
|
||||
|
Loading…
Reference in New Issue
Block a user