From dbde66adceafae95294d97d851d273dbeb4903fc Mon Sep 17 00:00:00 2001 From: ssorin Date: Fri, 13 Dec 2024 15:12:04 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=8A(dashboard)=20add=20Sentry=20integr?= =?UTF-8?q?ation?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sentry integration to enable error tracking and performance monitoring - install Sentry SDK and DjangoIntegration to Sentry. - add Sentry configuration (in settings). - add `SENTRY_DSN` to .env --- env.d/dashboard | 13 +++++++++++-- src/dashboard/CHANGELOG.md | 1 + src/dashboard/Pipfile | 1 + src/dashboard/Pipfile.lock | 13 ++++++++++++- src/dashboard/dashboard/settings.py | 16 ++++++++++++++++ 5 files changed, 41 insertions(+), 3 deletions(-) diff --git a/env.d/dashboard b/env.d/dashboard index a59faedb..d502f80d 100644 --- a/env.d/dashboard +++ b/env.d/dashboard @@ -1,9 +1,18 @@ PORT=8000 + +# django +DASHBOARD_DEBUG=1 DASHBOARD_ALLOWED_HOSTS=* +DASHBOARD_SECRET_KEY=the_secret_key + +# database DASHBOARD_DB_NAME=qualicharge-dashboard DASHBOARD_DATABASE_URL=psql://qualicharge:pass@postgresql:5432/qualicharge-dashboard -DASHBOARD_DEBUG=1 -DASHBOARD_SECRET_KEY=the_secret_key + +# tools +DASHBOARD_SENTRY_DSN= + +# superuser DJANGO_SUPERUSER_PASSWORD=admin DJANGO_SUPERUSER_USERNAME=admin DJANGO_SUPERUSER_EMAIL=admin@example.com diff --git a/src/dashboard/CHANGELOG.md b/src/dashboard/CHANGELOG.md index 74cf975e..a67f69f2 100644 --- a/src/dashboard/CHANGELOG.md +++ b/src/dashboard/CHANGELOG.md @@ -19,6 +19,7 @@ and this project adheres to - add dashboard homepage - add consent form to manage consents of one or many entities - integration of custom 403, 404 and 500 pages +- sentry integration [unreleased]: https://github.com/MTES-MCT/qualicharge/compare/main...bootstrap-dashboard-project diff --git a/src/dashboard/Pipfile b/src/dashboard/Pipfile index 59af921e..34c870af 100644 --- a/src/dashboard/Pipfile +++ b/src/dashboard/Pipfile @@ -10,6 +10,7 @@ django-environ = "==0.11.2" django-extensions = "==3.2.3" gunicorn = "==23.0.0" psycopg = {extras = ["pool", "binary"], version = "==3.2.3"} +sentry-sdk = {extras = ["django"], version = "==2.19.2"} whitenoise = "==6.8.2" [dev-packages] diff --git a/src/dashboard/Pipfile.lock b/src/dashboard/Pipfile.lock index d4a9b10b..7fa0c07a 100644 --- a/src/dashboard/Pipfile.lock +++ b/src/dashboard/Pipfile.lock @@ -1,7 +1,7 @@ { "_meta": { "hash": { - "sha256": "2a8a17843f0ddae6033b9e1c39555103ff0d33ce30ef0373a8010d84750c7f50" + "sha256": "7bab31f60f4278df10774d080bdfe862b7e54443ceae7061468a47433a6be002" }, "pipfile-spec": 6, "requires": { @@ -318,6 +318,17 @@ "markers": "python_version >= '3.8'", "version": "==2.32.3" }, + "sentry-sdk": { + "extras": [ + "django" + ], + "hashes": [ + "sha256:467df6e126ba242d39952375dd816fbee0f217d119bf454a8ce74cf1e7909e8d", + "sha256:ebdc08228b4d131128e568d696c210d846e5b9d70aa0327dec6b1272d9d40b84" + ], + "markers": "python_version >= '3.6'", + "version": "==2.19.2" + }, "sqlparse": { "hashes": [ "sha256:09f67787f56a0b16ecdbde1bfc7f5d9c3371ca683cfeaa8e6ff60b4807ec9272", diff --git a/src/dashboard/dashboard/settings.py b/src/dashboard/dashboard/settings.py index dd4a0f54..280b4d57 100644 --- a/src/dashboard/dashboard/settings.py +++ b/src/dashboard/dashboard/settings.py @@ -12,7 +12,9 @@ from pathlib import Path import environ +import sentry_sdk from django.utils.translation import gettext_lazy as _ +from sentry_sdk.integrations.django import DjangoIntegration # Build paths inside the project like this: BASE_DIR / 'subdir'. BASE_DIR = Path(__file__).resolve().parent.parent @@ -21,6 +23,7 @@ env = environ.Env( DASHBOARD_DEBUG=(bool, False), DASHBOARD_ALLOWED_HOSTS=(list, ["localhost"]), + DASHBOARD_SENTRY_DSN=(str, ""), ) env.prefix = "DASHBOARD_" @@ -153,3 +156,16 @@ LOGOUT_REDIRECT_URL = "/" AUTH_USER_MODEL = "qcd_auth.DashboardUser" + +# Sentry +sentry_sdk.init( + dsn=env.str("SENTRY_DSN"), + integrations=[DjangoIntegration()], + # 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, + # If you wish to associate users to errors (assuming you are using + # django.contrib.auth) you may enable sending PII data. + send_default_pii=True, +)