diff --git a/README.md b/README.md index b09077f8b..994391c05 100644 --- a/README.md +++ b/README.md @@ -80,10 +80,20 @@ The plugin offers some integrations listed below: ```yaml EOX_CORE_SENTRY_INTEGRATION_DSN: + EOX_CORE_SENTRY_IGNORED_ERRORS: [] # optional ``` By default, **EOX_CORE_SENTRY_INTEGRATION_DSN** setting is None, which disables the sentry integration. + **EOX_CORE_SENTRY_IGNORED_ERRORS** is optional. It is a list of exceptions that wants to be ignored by sentry. For instance, it can be defined as: + + ```yaml + EOX_CORE_SENTRY_IGNORED_ERRORS: [ + 'xmodule.exceptions.NotFoundError', + 'openedx.core.djangoapps.user_authn.exceptions.AuthFailedError', + ] + ``` + ## Course Management automation compilation We use webpack to bundle the React js application and its dependencies, diff --git a/eox_core/__init__.py b/eox_core/__init__.py index 47d720dfc..4c2122585 100644 --- a/eox_core/__init__.py +++ b/eox_core/__init__.py @@ -1,4 +1,4 @@ """ Init for main eox-core app """ -__version__ = '2.8.1' +__version__ = '2.9.0' diff --git a/eox_core/integrations/__init__.py b/eox_core/integrations/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/eox_core/integrations/sentry.py b/eox_core/integrations/sentry.py new file mode 100644 index 000000000..2e7f3b27b --- /dev/null +++ b/eox_core/integrations/sentry.py @@ -0,0 +1,41 @@ +""" +This file implements utils used for sentry integration. + +See: https://github.com/eduNEXT/eox-core#integrations-with-third-party-services +""" +import importlib + +from django.conf import settings + + +def load_class(full_class_string): + """ + dynamically load a class from a string + """ + + class_data = full_class_string.split(".") + module_path = ".".join(class_data[:-1]) + class_str = class_data[-1] + + module = importlib.import_module(module_path) + return getattr(module, class_str) + + +def before_send(event, hint): + """ + Workaround to prevent certain exceptions to be sent to sentry.io + See: https://github.com/getsentry/sentry-python/issues/149#issuecomment-434448781 + """ + ignored_errors = () + for error in settings.SENTRY_IGNORED_ERRORS: + try: + error_class = load_class(error) + ignored_errors += (error_class,) + except Exception: # pylint: disable=broad-except + pass + if 'exc_info' in hint and ignored_errors: + _exc_type, exc_value, _tb = hint['exc_info'] + if isinstance(exc_value, ignored_errors): + return None + + return event diff --git a/eox_core/settings/aws.py b/eox_core/settings/aws.py index 9ec83a60f..15a56acb1 100644 --- a/eox_core/settings/aws.py +++ b/eox_core/settings/aws.py @@ -119,8 +119,15 @@ def plugin_settings(settings): # pylint: disable=function-redefined 'EOX_CORE_SENTRY_INTEGRATION_DSN', settings.EOX_CORE_SENTRY_INTEGRATION_DSN ) + settings.EOX_CORE_SENTRY_IGNORED_ERRORS = getattr(settings, 'ENV_TOKENS', {}).get( + 'EOX_CORE_SENTRY_IGNORED_ERRORS', + settings.EOX_CORE_SENTRY_IGNORED_ERRORS + ) + if sentry_sdk is not None and sentry_integration_dsn is not None: + from eox_core.integrations.sentry import before_send sentry_sdk.init( + before_send=before_send, dsn=sentry_integration_dsn, integrations=[DjangoIntegration()], diff --git a/eox_core/settings/common.py b/eox_core/settings/common.py index 9c952031e..2648756d7 100644 --- a/eox_core/settings/common.py +++ b/eox_core/settings/common.py @@ -49,3 +49,4 @@ def plugin_settings(settings): # Sentry Integration settings.EOX_CORE_SENTRY_INTEGRATION_DSN = None + settings.EOX_CORE_SENTRY_IGNORED_ERRORS = [] diff --git a/setup.cfg b/setup.cfg index 351320223..9e4ca35ad 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,5 +1,5 @@ [bumpversion] -current_version = 2.8.1 +current_version = 2.9.0 commit = True tag = True