diff --git a/InvenTree/InvenTree/settings.py b/InvenTree/InvenTree/settings.py index 2d9090b05e..797924fd36 100644 --- a/InvenTree/InvenTree/settings.py +++ b/InvenTree/InvenTree/settings.py @@ -72,6 +72,27 @@ if DEBUG: format='%(asctime)s %(levelname)s %(message)s', ) +# Does the user wish to use the sentry.io integration? +sentry_opts = CONFIG.get('sentry', {}) + +if sentry_opts.get('enabled', False): + dsn = sentry_opts.get('dsn', None) + + if dsn is not None: + # Try to import required modules (exit if not installed) + try: + import sentry_sdk + from sentry_sdk.integrations.django import DjangoIntegration + + sentry_sdk.init(dsn=dsn, integrations=[DjangoIntegration()], send_default_pii=True) + + except ModuleNotFoundError: + print("sentry_sdk module not found. Install using 'pip install sentry-sdk'") + sys.exit(-1) + + else: + print("Warning: Sentry.io DSN not specified") + # Application definition INSTALLED_APPS = [ diff --git a/InvenTree/config_template.yaml b/InvenTree/config_template.yaml index 0865827d56..64c5db0a06 100644 --- a/InvenTree/config_template.yaml +++ b/InvenTree/config_template.yaml @@ -65,4 +65,11 @@ log_queries: False # Backup options # Set the backup_dir parameter to store backup files in a specific location # If unspecified, the local user's temp directory will be used -#backup_dir: '/home/inventree/backup/' \ No newline at end of file +#backup_dir: '/home/inventree/backup/' + +# Sentry.io integration +# If you have a sentry.io account, it can be used to log server errors +# Ensure sentry_sdk is installed by running 'pip install sentry-sdk' +sentry: + enabled: False + # dsn: add-your-sentry-dsn-here