From 4b4032be6f984cea34aeb7a52cbfcc38bc389b35 Mon Sep 17 00:00:00 2001 From: Andrew Godwin Date: Sun, 20 Nov 2022 11:18:42 -0700 Subject: Add Sentry error integration option --- activities/admin.py | 6 ++++++ requirements.txt | 1 + takahe/settings/production.py | 14 ++++++++++++++ templates/500.html | 6 ++++++ users/admin.py | 6 ++++++ 5 files changed, 33 insertions(+) create mode 100644 templates/500.html diff --git a/activities/admin.py b/activities/admin.py index e24304d..ba809a8 100644 --- a/activities/admin.py +++ b/activities/admin.py @@ -32,6 +32,12 @@ class PostAdmin(admin.ModelAdmin): def object_json(self, instance): return instance.to_ap() + def has_add_permission(self, request, obj=None): + """ + Disables admin creation of posts as it will skip steps + """ + return False + @admin.register(TimelineEvent) class TimelineEventAdmin(admin.ModelAdmin): diff --git a/requirements.txt b/requirements.txt index 8eed5d8..b32f91c 100644 --- a/requirements.txt +++ b/requirements.txt @@ -14,3 +14,4 @@ django-htmx~=1.13.0 django-storages[google,boto3]~=1.13.1 whitenoise~=6.2.0 sphinx~=5.3.0 +sentry-sdk~=1.11.0 diff --git a/takahe/settings/production.py b/takahe/settings/production.py index 34116af..4120217 100644 --- a/takahe/settings/production.py +++ b/takahe/settings/production.py @@ -77,3 +77,17 @@ STATOR_TOKEN = os.environ.get("TAKAHE_STATOR_TOKEN") # Error email recipients if "TAKAHE_ERROR_EMAILS" in os.environ: ADMINS = [("Admin", e) for e in os.environ["TAKAHE_ERROR_EMAILS"].split(",")] + +# Sentry integration +if "SENTRY_DSN" in os.environ: + import sentry_sdk + from sentry_sdk.integrations.django import DjangoIntegration + + sentry_sdk.init( + dsn=os.environ["SENTRY_DSN"], + integrations=[ + DjangoIntegration(), + ], + traces_sample_rate=1.0, + send_default_pii=True, + ) diff --git a/templates/500.html b/templates/500.html new file mode 100644 index 0000000..e828f68 --- /dev/null +++ b/templates/500.html @@ -0,0 +1,6 @@ +{% extends "base.html" %} + +{% block content %} +

Internal Server Error

+

Sorry about that.

+{% endblock %} diff --git a/users/admin.py b/users/admin.py index 0901307..7a54c52 100644 --- a/users/admin.py +++ b/users/admin.py @@ -44,6 +44,12 @@ class IdentityAdmin(admin.ModelAdmin): def actor_json(self, instance): return instance.to_ap() + def has_add_permission(self, request, obj=None): + """ + Disables admin creation of identities as it will skip steps + """ + return False + @admin.register(Follow) class FollowAdmin(admin.ModelAdmin): -- cgit v1.2.3