Skip to content

Commit 837e483

Browse files
author
morenol
authored
Merge pull request #86 from eduNEXT/lmm/ignore_error_sentry
Add capability to ignore exceptions in sentry.
2 parents d7810b0 + bff2b59 commit 837e483

File tree

7 files changed

+61
-2
lines changed

7 files changed

+61
-2
lines changed

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,20 @@ The plugin offers some integrations listed below:
8080

8181
```yaml
8282
EOX_CORE_SENTRY_INTEGRATION_DSN: <your DSN value>
83+
EOX_CORE_SENTRY_IGNORED_ERRORS: [] # optional
8384
```
8485

8586
By default, **EOX_CORE_SENTRY_INTEGRATION_DSN** setting is None, which disables the sentry integration.
8687

88+
**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:
89+
90+
```yaml
91+
EOX_CORE_SENTRY_IGNORED_ERRORS: [
92+
'xmodule.exceptions.NotFoundError',
93+
'openedx.core.djangoapps.user_authn.exceptions.AuthFailedError',
94+
]
95+
```
96+
8797
## Course Management automation compilation
8898

8999
We use webpack to bundle the React js application and its dependencies,

eox_core/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
"""
22
Init for main eox-core app
33
"""
4-
__version__ = '2.8.1'
4+
__version__ = '2.9.0'

eox_core/integrations/__init__.py

Whitespace-only changes.

eox_core/integrations/sentry.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
"""
2+
This file implements utils used for sentry integration.
3+
4+
See: https://github.com/eduNEXT/eox-core#integrations-with-third-party-services
5+
"""
6+
import importlib
7+
8+
from django.conf import settings
9+
10+
11+
def load_class(full_class_string):
12+
"""
13+
dynamically load a class from a string
14+
"""
15+
16+
class_data = full_class_string.split(".")
17+
module_path = ".".join(class_data[:-1])
18+
class_str = class_data[-1]
19+
20+
module = importlib.import_module(module_path)
21+
return getattr(module, class_str)
22+
23+
24+
def before_send(event, hint):
25+
"""
26+
Workaround to prevent certain exceptions to be sent to sentry.io
27+
See: https://github.com/getsentry/sentry-python/issues/149#issuecomment-434448781
28+
"""
29+
ignored_errors = ()
30+
for error in settings.SENTRY_IGNORED_ERRORS:
31+
try:
32+
error_class = load_class(error)
33+
ignored_errors += (error_class,)
34+
except Exception: # pylint: disable=broad-except
35+
pass
36+
if 'exc_info' in hint and ignored_errors:
37+
_exc_type, exc_value, _tb = hint['exc_info']
38+
if isinstance(exc_value, ignored_errors):
39+
return None
40+
41+
return event

eox_core/settings/aws.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,15 @@ def plugin_settings(settings): # pylint: disable=function-redefined
119119
'EOX_CORE_SENTRY_INTEGRATION_DSN',
120120
settings.EOX_CORE_SENTRY_INTEGRATION_DSN
121121
)
122+
settings.EOX_CORE_SENTRY_IGNORED_ERRORS = getattr(settings, 'ENV_TOKENS', {}).get(
123+
'EOX_CORE_SENTRY_IGNORED_ERRORS',
124+
settings.EOX_CORE_SENTRY_IGNORED_ERRORS
125+
)
126+
122127
if sentry_sdk is not None and sentry_integration_dsn is not None:
128+
from eox_core.integrations.sentry import before_send
123129
sentry_sdk.init(
130+
before_send=before_send,
124131
dsn=sentry_integration_dsn,
125132
integrations=[DjangoIntegration()],
126133

eox_core/settings/common.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,4 @@ def plugin_settings(settings):
4949

5050
# Sentry Integration
5151
settings.EOX_CORE_SENTRY_INTEGRATION_DSN = None
52+
settings.EOX_CORE_SENTRY_IGNORED_ERRORS = []

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[bumpversion]
2-
current_version = 2.8.1
2+
current_version = 2.9.0
33
commit = True
44
tag = True
55

0 commit comments

Comments
 (0)