From d8cc7d558f638633eac03409655885e9c4e6a4cd Mon Sep 17 00:00:00 2001 From: komipika <44190957+komipika@users.noreply.github.com> Date: Wed, 2 Feb 2022 12:20:00 +0200 Subject: [PATCH 1/2] Initialize sentry logging --- dogmap/__init__.py | 21 +++++++++++++++++++++ requirements.txt | 3 ++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/dogmap/__init__.py b/dogmap/__init__.py index a8b9676a..941c7127 100644 --- a/dogmap/__init__.py +++ b/dogmap/__init__.py @@ -3,6 +3,7 @@ from typing import Any, TypedDict, Dict from dotenv import load_dotenv import logging import requests +import sentry_sdk from flask import ( Flask, @@ -12,6 +13,8 @@ from flask import ( url_for ) +from sentry_sdk.integrations.flask import FlaskIntegration + from flask.templating import render_template from flask_mongoengine import MongoEngine from werkzeug.exceptions import BadRequestKeyError @@ -26,7 +29,21 @@ logger = logging.getLogger(__name__) # Define basic config, which sets the handler to print into console by default logger.setLevel(logging.DEBUG) +sentry_sdk.init( + dsn='SENTRY_DSN', + integrations=[FlaskIntegration()], + + # Set traces_sample_rate to 1.0 to capture 100% + # of transactions for performance monitoring. + # We recommend adjusting this value in production. + traces_sample_rate=1.0, + # By default the SDK will try to use the SENTRY_RELEASE + # environment variable, or infer a git commit + # SHA as release, however you may want to set + # something more human-readable. + # release="myapp@1.0.0", +) def create_app() -> Flask: """ @@ -289,6 +306,10 @@ def create(): message = f"Something went wrong with creating new marker" return render_template("crud_pagenotfound.html", message = message) +@app.route('/debug-sentry') +def trigger_error(): + division_by_zero = 1 / 0 + @app.route("/build") def image_build(): diff --git a/requirements.txt b/requirements.txt index 08a89f5c..f169973b 100644 --- a/requirements.txt +++ b/requirements.txt @@ -5,4 +5,5 @@ python-dotenv flask-mongoengine mongomock Flask-Babel -requests \ No newline at end of file +requests +sentry-sdk[flask] \ No newline at end of file -- GitLab From 492e87ab722fd42089ce55757282715805efb55a Mon Sep 17 00:00:00 2001 From: komipika <44190957+komipika@users.noreply.github.com> Date: Wed, 2 Feb 2022 12:40:06 +0200 Subject: [PATCH 2/2] added environ get --- dogmap/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dogmap/__init__.py b/dogmap/__init__.py index 941c7127..17ffdeab 100644 --- a/dogmap/__init__.py +++ b/dogmap/__init__.py @@ -30,7 +30,7 @@ logger = logging.getLogger(__name__) logger.setLevel(logging.DEBUG) sentry_sdk.init( - dsn='SENTRY_DSN', + dsn=environ.get('SENTRY_DSN'), integrations=[FlaskIntegration()], # Set traces_sample_rate to 1.0 to capture 100% -- GitLab