From 8ac082240de8bdae96ac6d55dfa75e6dcb10b1ab Mon Sep 17 00:00:00 2001 From: Lova ANDRIARIMALALA <43842786+Xpirix@users.noreply.github.com> Date: Thu, 23 May 2024 10:30:50 +0300 Subject: [PATCH] Integrate sentry into the django project (#408) * Integrate sentry into the django project * Init sentry when the dsn is specified * Fix test in GH actions * Update the url in valid_metadata_link --- dockerize/.env.template | 3 +++ dockerize/docker-compose.yml | 2 +- dockerize/docker/REQUIREMENTS.txt | 2 ++ qgis-app/plugins/tests/test_plugin_update.py | 16 ++++++++++++---- qgis-app/plugins/tests/test_plugin_upload.py | 8 ++++++-- .../tests/testfiles/valid_metadata_link.zip | Bin 45863 -> 45877 bytes qgis-app/settings_docker.py | 14 ++++++++++++++ 7 files changed, 38 insertions(+), 7 deletions(-) diff --git a/dockerize/.env.template b/dockerize/.env.template index 8cbf8dc8..5175f3ff 100644 --- a/dockerize/.env.template +++ b/dockerize/.env.template @@ -33,5 +33,8 @@ QGISPLUGINS_ENV=debug # Ldap ENABLE_LDAP=False +# SENTRY +SENTRY_DSN='' + # Download stats URL METABASE_DOWNLOAD_STATS_URL='https://plugins.qgis.org/metabase/public/dashboard/' diff --git a/dockerize/docker-compose.yml b/dockerize/docker-compose.yml index 387fd96d..5fd84d1e 100644 --- a/dockerize/docker-compose.yml +++ b/dockerize/docker-compose.yml @@ -54,7 +54,7 @@ services: - EMAIL_HOST_USER=${EMAIL_HOST_USER:-automation} - EMAIL_HOST_PASSWORD=${EMAIL_HOST_PASSWORD} - DEFAULT_PLUGINS_SITE=${DEFAULT_PLUGINS_SITE:-https://plugins.qgis.org/} - + - SENTRY_DSN=${SENTRY_DSN} volumes: - ../qgis-app:/home/web/django_project - ./docker/uwsgi.conf:/uwsgi.conf diff --git a/dockerize/docker/REQUIREMENTS.txt b/dockerize/docker/REQUIREMENTS.txt index 3d738ad9..24146e93 100644 --- a/dockerize/docker/REQUIREMENTS.txt +++ b/dockerize/docker/REQUIREMENTS.txt @@ -60,3 +60,5 @@ geoip2==4.5.0 django-matomo==0.1.6 uwsgi~=2.0 freezegun~=1.4 + +sentry-sdk~=2.2 diff --git a/qgis-app/plugins/tests/test_plugin_update.py b/qgis-app/plugins/tests/test_plugin_update.py index d1e4c34b..118b12d8 100644 --- a/qgis-app/plugins/tests/test_plugin_update.py +++ b/qgis-app/plugins/tests/test_plugin_update.py @@ -92,9 +92,13 @@ def test_plugin_new_version(self): self.assertEqual(self.plugin.tracker, "https://github.com/") self.assertEqual(self.plugin.repository, "https://github.com/") - self.assertEqual( + self.assertIn( + 'admin@admin.it', mail.outbox[0].recipients(), - ['admin@admin.it', 'staff@staff.it'] + ) + self.assertIn( + 'staff@staff.it', + mail.outbox[0].recipients() ) # Should use the new email @@ -145,9 +149,13 @@ def test_plugin_version_update(self): self.assertEqual(self.plugin.tracker, "https://github.com/") self.assertEqual(self.plugin.repository, "https://github.com/") - self.assertEqual( + self.assertIn( + 'admin@admin.it', mail.outbox[0].recipients(), - ['admin@admin.it', 'staff@staff.it'] + ) + self.assertIn( + 'staff@staff.it', + mail.outbox[0].recipients() ) # Should use the new email diff --git a/qgis-app/plugins/tests/test_plugin_upload.py b/qgis-app/plugins/tests/test_plugin_upload.py index 9b3d2814..f2819ea9 100644 --- a/qgis-app/plugins/tests/test_plugin_upload.py +++ b/qgis-app/plugins/tests/test_plugin_upload.py @@ -69,9 +69,13 @@ def test_plugin_upload_form(self): 3) self.assertTrue(PluginVersion.objects.filter(plugin__name='Test Plugin', version='0.0.1').exists()) - self.assertEqual( + self.assertIn( + 'admin@admin.it', mail.outbox[0].recipients(), - ['admin@admin.it', 'staff@staff.it'] + ) + self.assertIn( + 'staff@staff.it', + mail.outbox[0].recipients() ) # Should use the new email diff --git a/qgis-app/plugins/tests/testfiles/valid_metadata_link.zip b/qgis-app/plugins/tests/testfiles/valid_metadata_link.zip index 94ca6c67422f50a82f6095533a745fcf30fa740e..6c53b03958e43f8cf92f6da86e17b391aa5034f8 100644 GIT binary patch delta 1493 zcmZ9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nT+%x*7IrzRmP+e#0unQzXXv)?)2IluF}-@W(ypL6fORfUOFn2{eB zC-f2ZW4$IRxY%eRpln1;LT_UNn&TdHZyo{@p}*T^Dmjl4z=$p*efM zn18LT+dT0dzbj5Zy3{MR$d4Iw$!erECHunJFMqb}bC6sabX}d1bS~?VXK%EJ?OSEf zmL&(nZjAay5+#9H> zV5L)XJXwXYsCRf->9%!Vk^OdY1{gE{M1Lrq= zhILY76fze9PLhS&L+$4n=Py$Ab5zbvN1|J$&Nc(mz{E%bl@i}Cxhd{-G(G3nc9>8JcKIg2uF;2U z)#j)OMyrF-7x3-zK+MSj9*O5es)G@99A~4a0j=R-eCHWy3JZOWp|FO7TEWd4!A#c8 z8WZSe8A4<&8}oP3zyx0Z z$s~y`*LY+EAGAt-1G!&Zu*u!RPgVufyjNPVz>0RtU{ AVE_OC diff --git a/qgis-app/settings_docker.py b/qgis-app/settings_docker.py index 9d8fcacf..4b5bd1f4 100644 --- a/qgis-app/settings_docker.py +++ b/qgis-app/settings_docker.py @@ -165,3 +165,17 @@ # Default primary key type DEFAULT_AUTO_FIELD = 'django.db.models.AutoField' + + +# Sentry +SENTRY_DSN = os.environ.get("SENTRY_DSN", "") + +if SENTRY_DSN and SENTRY_DSN != "": + import sentry_sdk + + sentry_sdk.init( + dsn=SENTRY_DSN, + # Set traces_sample_rate to 1.0 to capture 100% + # of transactions for performance monitoring. + traces_sample_rate=1.0, + )