mirror of
				https://github.com/TitanEmbeds/Titan.git
				synced 2025-11-03 23:37:09 +01:00 
			
		
		
		
	Utilize sentry to track execution errors
This commit is contained in:
		@@ -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):
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user