-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from eduNEXT/cag/sentry
feat: add sentry support on openedx
- Loading branch information
Showing
8 changed files
with
140 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# Celery plugin for [Tutor](https://docs.tutor.edly.io) | ||
|
||
A tutor plugin to integration Open edX with Sentry. | ||
|
||
## Installation | ||
|
||
```shell | ||
pip install git+https://github.com/eduNEXT/tutor-contrib-sentry | ||
``` | ||
|
||
## Usage | ||
|
||
```shell | ||
tutor plugins enable sentry | ||
``` | ||
|
||
## Configuration | ||
|
||
This plugin supports the following settings: | ||
|
||
- `SENTRY_DSN`: The sentry DSN used for ingestion. | ||
- `SENTRY_IGNORED_ERRORS`: A list of rules with exceptions types to ignore, optionally | ||
you can ignore only specific exceptions that matches a list of regex. | ||
|
||
```yaml | ||
SENTRY_IGNORED_ERRORS: | ||
# Ignore all AuthFailedError exceptions | ||
- exc_class: AuthFailedError | ||
# Ignore all exceptions that match a regex | ||
- exc_text: | ||
- .*Email or password is incorrect | ||
# Ignore all exceptions of type AuthFailedError that matches: .*Email or password is incorrect | ||
- exc_class: AuthFailedError | ||
exc_text: | ||
- .*Email or password is incorrect | ||
``` | ||
- `SENTRY_ENVIRONMENT`: The sentry environment. Defaults to `production`. | ||
- `SENTRY_EXTRA_ARGS`: A dictionary with extra arguments for the sentry SDK. e.g: | ||
|
||
```yaml | ||
SENTRY_EXTRA_ARGS: | ||
traces_sample_rate: 1.0 | ||
profiles_sample_rate: 0.0 | ||
``` | ||
|
||
### Recommendations | ||
|
||
On production we recommend adjusting both `traces_sample_rate` and `profiles_sample_rate` as those | ||
can impact performance. See the [sentry configuration options](https://docs.sentry.io/platforms/python/configuration/options/) for more information. | ||
|
||
|
||
### License | ||
|
||
This software is licensed under the terms of the AGPLv3. |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import re | ||
import logging | ||
|
||
logger = logging.getLogger(__file__) | ||
|
||
SENTRY_IGNORED_ERRORS = {{SENTRY_IGNORED_ERRORS}} | ||
|
||
def validate_exc(method, value, exc_value, exc_class_name): | ||
if method == 'exc_class': | ||
# exc_class_name = value | ||
return exc_class_name == value | ||
|
||
elif method == 'exc_text': | ||
exc_text_expr = value | ||
for expr in exc_text_expr: | ||
if re.search(expr, exc_value): | ||
return True | ||
|
||
return False | ||
|
||
|
||
def should_ignore_by_rule(rule, exc_value, exc_class_name): | ||
""" | ||
Validates if a given ignored exception rule matches the current exception | ||
""" | ||
for method, value in rule.items(): | ||
result = validate_exc(method, value, exc_value, exc_class_name) | ||
if not result: | ||
return False | ||
return True | ||
|
||
def exception_filter_hook(event, hint): | ||
""" | ||
Calls the proper method to verify which exceptions are ignored | ||
for sentry | ||
""" | ||
exc_text = '' | ||
exc_value = None | ||
|
||
if 'log_record' in hint: | ||
exc_text = hint['log_record'].message | ||
if 'exc_info' in hint: | ||
_exc_type, exc_value, _tb = hint['exc_info'] | ||
exc_class_name = _exc_type.__name__ | ||
exc_text += str(exc_value) | ||
|
||
for rule in SENTRY_IGNORED_ERRORS: | ||
ignore_event = should_ignore_by_rule(rule, exc_text, exc_class_name) | ||
if ignore_event: | ||
return None | ||
|
||
return event | ||
|
||
try: | ||
import sentry_sdk | ||
from sentry_sdk.integrations.django import DjangoIntegration | ||
|
||
sentry_sdk.init( | ||
dsn="{{SENTRY_DSN}}", | ||
integrations=[ | ||
DjangoIntegration(), | ||
], | ||
before_send=exception_filter_hook, | ||
send_default_pii=True, | ||
**{{SENTRY_EXTRA_ARGS}}, | ||
) | ||
except ImportError: | ||
logger.error("Sentry SDK is not installed.") |
2 changes: 2 additions & 0 deletions
2
tutorsentry/patches/openedx-dockerfile-post-python-requirements
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
RUN --mount=type=cache,target=/openedx/.cache/pip,sharing=shared \ | ||
pip install "sentry-sdk==2.8.0" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
ignore-sigpipe | ||
ignore-write-errors | ||
disable-write-exception |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters