Skip to content

Commit

Permalink
Merge pull request #86 from eduNEXT/lmm/ignore_error_sentry
Browse files Browse the repository at this point in the history
Add capability to ignore exceptions in sentry.
  • Loading branch information
morenol committed Apr 6, 2020
2 parents d7810b0 + bff2b59 commit 837e483
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 2 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,20 @@ The plugin offers some integrations listed below:

```yaml
EOX_CORE_SENTRY_INTEGRATION_DSN: <your DSN value>
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,
Expand Down
2 changes: 1 addition & 1 deletion eox_core/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""
Init for main eox-core app
"""
__version__ = '2.8.1'
__version__ = '2.9.0'
Empty file.
41 changes: 41 additions & 0 deletions eox_core/integrations/sentry.py
Original file line number Diff line number Diff line change
@@ -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
7 changes: 7 additions & 0 deletions eox_core/settings/aws.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()],

Expand Down
1 change: 1 addition & 0 deletions eox_core/settings/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,4 @@ def plugin_settings(settings):

# Sentry Integration
settings.EOX_CORE_SENTRY_INTEGRATION_DSN = None
settings.EOX_CORE_SENTRY_IGNORED_ERRORS = []
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 2.8.1
current_version = 2.9.0
commit = True
tag = True

Expand Down

0 comments on commit 837e483

Please sign in to comment.