mirror of
https://github.com/inventree/InvenTree.git
synced 2025-04-28 11:36:44 +00:00
Sentry (#3174)
* Add sentry for optional error reporting Closes https://github.com/inventreedb/org/issues/3 Heavily inspired by https://github.com/netbox-community/netbox/issues/9340 * do not consider optional stuff in coverage * Add DSN for inventree org Co-authored-by: Oliver Walters <oliver.henry.walters@gmail.com>
This commit is contained in:
parent
5ecba6b13c
commit
90aa7b8444
@ -23,7 +23,9 @@ from django.core.files.storage import default_storage
|
|||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
|
|
||||||
import moneyed
|
import moneyed
|
||||||
|
import sentry_sdk
|
||||||
import yaml
|
import yaml
|
||||||
|
from sentry_sdk.integrations.django import DjangoIntegration
|
||||||
|
|
||||||
from .config import get_base_dir, get_config_file, get_plugin_file, get_setting
|
from .config import get_base_dir, get_config_file, get_plugin_file, get_setting
|
||||||
|
|
||||||
@ -33,6 +35,9 @@ def _is_true(x):
|
|||||||
return str(x).strip().lower() in ['1', 'y', 'yes', 't', 'true']
|
return str(x).strip().lower() in ['1', 'y', 'yes', 't', 'true']
|
||||||
|
|
||||||
|
|
||||||
|
# Default Sentry DSN (can be overriden if user wants custom sentry integration)
|
||||||
|
INVENTREE_DSN = 'https://3928ccdba1d34895abde28031fd00100@o378676.ingest.sentry.io/6494600'
|
||||||
|
|
||||||
# Determine if we are running in "test" mode e.g. "manage.py test"
|
# Determine if we are running in "test" mode e.g. "manage.py test"
|
||||||
TESTING = 'test' in sys.argv
|
TESTING = 'test' in sys.argv
|
||||||
# Are enviroment variables manipulated by tests? Needs to be set by testing code
|
# Are enviroment variables manipulated by tests? Needs to be set by testing code
|
||||||
@ -546,7 +551,7 @@ db_config['TEST'] = {
|
|||||||
|
|
||||||
# Set collation option for mysql test database
|
# Set collation option for mysql test database
|
||||||
if 'mysql' in db_engine:
|
if 'mysql' in db_engine:
|
||||||
db_config['TEST']['COLLATION'] = 'utf8_general_ci'
|
db_config['TEST']['COLLATION'] = 'utf8_general_ci' # pragma: no cover
|
||||||
|
|
||||||
DATABASES = {
|
DATABASES = {
|
||||||
'default': db_config
|
'default': db_config
|
||||||
@ -882,6 +887,26 @@ MARKDOWNIFY_WHITELIST_ATTRS = [
|
|||||||
|
|
||||||
MARKDOWNIFY_BLEACH = False
|
MARKDOWNIFY_BLEACH = False
|
||||||
|
|
||||||
|
# Error reporting
|
||||||
|
SENTRY_ENABLED = get_setting('INVENTREE_SENTRY_ENABLED', CONFIG.get('sentry_enabled', False))
|
||||||
|
SENTRY_DSN = get_setting('INVENTREE_SENTRY_DSN', CONFIG.get('sentry_dsn', INVENTREE_DSN))
|
||||||
|
|
||||||
|
if SENTRY_ENABLED and SENTRY_DSN: # pragma: no cover
|
||||||
|
sentry_sdk.init(
|
||||||
|
dsn=SENTRY_DSN,
|
||||||
|
integrations=[DjangoIntegration(), ],
|
||||||
|
traces_sample_rate=1.0 if DEBUG else 0.15,
|
||||||
|
send_default_pii=True
|
||||||
|
)
|
||||||
|
inventree_tags = {
|
||||||
|
'testing': TESTING,
|
||||||
|
'docker': DOCKER,
|
||||||
|
'debug': DEBUG,
|
||||||
|
'remote': REMOTE_LOGIN,
|
||||||
|
}
|
||||||
|
for key, val in inventree_tags.items():
|
||||||
|
sentry_sdk.set_tag(f'inventree_{key}', val)
|
||||||
|
|
||||||
# Maintenance mode
|
# Maintenance mode
|
||||||
MAINTENANCE_MODE_RETRY_AFTER = 60
|
MAINTENANCE_MODE_RETRY_AFTER = 60
|
||||||
MAINTENANCE_MODE_STATE_BACKEND = 'maintenance_mode.backends.DefaultStorageBackend'
|
MAINTENANCE_MODE_STATE_BACKEND = 'maintenance_mode.backends.DefaultStorageBackend'
|
||||||
@ -925,6 +950,6 @@ CUSTOM_LOGO = get_setting(
|
|||||||
)
|
)
|
||||||
|
|
||||||
# check that the logo-file exsists in media
|
# check that the logo-file exsists in media
|
||||||
if CUSTOM_LOGO and not default_storage.exists(CUSTOM_LOGO):
|
if CUSTOM_LOGO and not default_storage.exists(CUSTOM_LOGO): # pragma: no cover
|
||||||
CUSTOM_LOGO = False
|
CUSTOM_LOGO = False
|
||||||
logger.warning("The custom logo file could not be found in the default media storage")
|
logger.warning("The custom logo file could not be found in the default media storage")
|
||||||
|
@ -102,6 +102,14 @@ debug: True
|
|||||||
# and only if InvenTree is accessed from a local IP (127.0.0.1)
|
# and only if InvenTree is accessed from a local IP (127.0.0.1)
|
||||||
debug_toolbar: False
|
debug_toolbar: False
|
||||||
|
|
||||||
|
# Set sentry_enabled to True to report errors back to the maintainers
|
||||||
|
# Use the environment variable INVENTREE_SENTRY_ENABLED
|
||||||
|
# sentry_enabled: True
|
||||||
|
|
||||||
|
# Set sentry_dsn to your custom DSN if you want to use your own instance for error reporting
|
||||||
|
# Use the environment variable INVENTREE_SENTRY_DSN
|
||||||
|
# sentry_dsn: https://custom@custom.ingest.sentry.io/custom
|
||||||
|
|
||||||
# Set this variable to True to enable InvenTree Plugins
|
# Set this variable to True to enable InvenTree Plugins
|
||||||
# Alternatively, use the environment variable INVENTREE_PLUGINS_ENABLED
|
# Alternatively, use the environment variable INVENTREE_PLUGINS_ENABLED
|
||||||
plugins_enabled: False
|
plugins_enabled: False
|
||||||
|
@ -47,5 +47,6 @@ pygments==2.7.4 # Syntax highlighting
|
|||||||
python-barcode[images]==0.13.1 # Barcode generator
|
python-barcode[images]==0.13.1 # Barcode generator
|
||||||
qrcode[pil]==6.1 # QR code generator
|
qrcode[pil]==6.1 # QR code generator
|
||||||
rapidfuzz==0.7.6 # Fuzzy string matching
|
rapidfuzz==0.7.6 # Fuzzy string matching
|
||||||
|
sentry-sdk==1.5.12 # Error reporting (optional)
|
||||||
tablib[xls,xlsx,yaml] # Support for XLS and XLSX formats
|
tablib[xls,xlsx,yaml] # Support for XLS and XLSX formats
|
||||||
weasyprint==55.0 # PDF generation library
|
weasyprint==55.0 # PDF generation library
|
||||||
|
Loading…
x
Reference in New Issue
Block a user