diff --git a/api/config/settings/common.py b/api/config/settings/common.py index 049596d6b..c25c3ed9d 100644 --- a/api/config/settings/common.py +++ b/api/config/settings/common.py @@ -17,6 +17,25 @@ APPS_DIR = ROOT_DIR.path("funkwhale_api") env = environ.Env() ENV = env LOGLEVEL = env("LOGLEVEL", default="info").upper() + + +if env("FUNKWHALE_SENTRY_DSN", default=None) is not None: + import sentry_sdk + from sentry_sdk.integrations.django import DjangoIntegration + from sentry_sdk.integrations.celery import CeleryIntegration + from funkwhale_api import __version__ as version + + sentry_sdk.init( + dsn=env("FUNKWHALE_SENTRY_DSN"), + integrations=[DjangoIntegration(), CeleryIntegration()], + traces_sample_rate=env("FUNKWHALE_SENTRY_SR", default=0.25), + send_default_pii=False, + environment="api", + debug=env.bool("DEBUG", False), + release=version, + ) + sentry_sdk.set_tag("instance", env("FUNKWHALE_HOSTNAME")) + """ Default logging level for the Funkwhale processes""" # pylint: disable=W0105 diff --git a/api/requirements/base.txt b/api/requirements/base.txt index 8e2f90739..2ebf32979 100644 --- a/api/requirements/base.txt +++ b/api/requirements/base.txt @@ -69,3 +69,4 @@ watchdog~=2.1.2 ## Pin third party dependency to avoid issue with latest version asgiref==3.3.4 #1516 +sentry-sdk==1.9.5 diff --git a/changes/changelog.d/sentry.feature b/changes/changelog.d/sentry.feature new file mode 100644 index 000000000..eda8170f5 --- /dev/null +++ b/changes/changelog.d/sentry.feature @@ -0,0 +1 @@ +Add Sentry SDK to collect errors at the backend diff --git a/deploy/env.prod.sample b/deploy/env.prod.sample index 11b21dfe2..a8f0bd624 100644 --- a/deploy/env.prod.sample +++ b/deploy/env.prod.sample @@ -197,3 +197,7 @@ AWS_STORAGE_BUCKET_NAME= # Available options can be found here: https://docs.aws.amazon.com/AmazonS3/latest/userguide/acl-overview.html#canned-acl # AWS_DEFAULT_ACL= + +# Funkwhale allows collecting errors using Sentry compatible APIs. If you want +# to help us improving Funkwhale, feel free to use our instance: +#FUNKWHALE_SENTRY_DSN=https://5840197379c64f65aad3c5c09274994d@am.funkwhale.audio/1