From d0752c8ec7bd64fc1aacd4690d11b4aa79d2f8a8 Mon Sep 17 00:00:00 2001 From: Ayo Ayco Date: Fri, 17 May 2024 18:04:58 +0200 Subject: [PATCH] feat: use config.json for sentry stuff --- .gitignore | 2 ++ example_config.json | 8 ++++++++ web.py | 20 ++++++++++++++++++++ 3 files changed, 30 insertions(+) create mode 100644 example_config.json diff --git a/.gitignore b/.gitignore index 56741f7..c7d1b61 100755 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ +config.json + # Deployment Unix socket *.sock diff --git a/example_config.json b/example_config.json new file mode 100644 index 0000000..e96a606 --- /dev/null +++ b/example_config.json @@ -0,0 +1,8 @@ +{ + "SENTRY": { + "dsn": "https://public@sentry.example.com/1", + "traces_sample_rate": 1.0, + "profiles_sample_rate": 1.0, + "enable_tracing": true + } +} diff --git a/web.py b/web.py index 72ed928..3176ea6 100755 --- a/web.py +++ b/web.py @@ -1,3 +1,5 @@ +import sentry_sdk +import json from flask import Flask, send_from_directory from partials import partials from threads import threads @@ -5,6 +7,17 @@ from threads import threads app = Flask(__name__) app.register_blueprint(partials, url_prefix='/p') app.register_blueprint(threads, url_prefix='/threads') +app.config.from_file("config.json", load=json.load) + +# sentry.io error monitoring +sentry_config = app.config["SENTRY"] +sentry_sdk.init( + dsn=sentry_config["dsn"], + traces_sample_rate=sentry_config["traces_sample_rate"], + profiles_sample_rate=sentry_config["profiles_sample_rate"], + enable_tracing=sentry_config["enable_tracing"], +) + @app.route('/') def home(): @@ -17,9 +30,16 @@ def dist(path): else: return send_from_directory('dist', path + '/index.html') +@app.route('/error') +def errorthing(): + 1/0 + return 'hello' + @app.errorhandler(404) def not_found(e): return send_from_directory('dist', '404.html'), 404 + + if __name__ == '__main__': app.run(host='0.0.0.0')