From 1121c7014c3c2e96e06eeee96bdd61d179ee9bd8 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Valenta?= <git@imaniti.org>
Date: Tue, 23 May 2023 17:50:30 +0200
Subject: [PATCH] add Sentry integration

---
 registry/settings/base.py   | 14 ++++++++++++++
 requirements/production.txt |  1 +
 shared/models.py            |  2 +-
 3 files changed, 16 insertions(+), 1 deletion(-)

diff --git a/registry/settings/base.py b/registry/settings/base.py
index c2f29bd..d1b9ceb 100644
--- a/registry/settings/base.py
+++ b/registry/settings/base.py
@@ -15,6 +15,9 @@ import pathlib
 
 import dj_database_url
 import environ
+import sentry_sdk
+
+from sentry_sdk.integrations.django import DjangoIntegration
 
 # Build paths inside the project like this: BASE_DIR / 'subdir'.
 BASE_DIR = pathlib.Path(__file__).parents[2]
@@ -229,6 +232,17 @@ CLAMD_TCP_SOCKET = env.int("CLAMD_TCP_SOCKET")
 CLAMD_TCP_ADDR = env.str("CLAMD_TCP_ADDR")
 
 
+# Sentry
+
+SENTRY_DSN = env.str("SENTRY_DSN")
+
+if SENTRY_DSN is not None:
+    sentry_sdk.init(
+        dsn=SENTRY_DSN,
+        integrations=[DjangoIntegration()],
+        send_default_pii=True,
+    )
+
 ## App-specific
 
 DEFAULT_CONTRACTEE_NAME = env.str("DEFAULT_CONTRACTEE_NAME")
diff --git a/requirements/production.txt b/requirements/production.txt
index ce5169e..efb3ddd 100644
--- a/requirements/production.txt
+++ b/requirements/production.txt
@@ -1,2 +1,3 @@
 gunicorn==20.1.0
 whitenoise==6.3.0
+sentry-sdk==1.24.0
diff --git a/shared/models.py b/shared/models.py
index 5d05557..b9f1d20 100644
--- a/shared/models.py
+++ b/shared/models.py
@@ -4,4 +4,4 @@ class NameStrMixin:
         raise NotImplementedError
 
     def __str__(self) -> str:
-        return self.name
+        return str(self.name)
-- 
GitLab