Sentry
Sentry is a service that keeps track of error and warning logs in the system to help identify bugs and execution errors in our application.
To activate it, we just need the DSN (identification URL) credentials and assign them to the SENTRY_DSN
environment variable.
Here’s an example:
SENTRY_DSN="https://b5f1faba900346543d7f220da92510e6@o1193796.ingest.sentry.io/45048052344325775"
Note
To obtain the credentials, you need to sign up at Sentry https://sentry.io/, create a new project, and select Django as the platform.
After configuring the SENTRY_DSN
environment variable correctly, Django Easystart will record any runtime error that occurs in the system.
In some cases, to prevent the thread of execution from stopping due to an error, we can use the try-except strategy and take appropriate action accordingly.
Additionally, we can send a personalized notification if the execution goes through the exception. Here’s an example of the code:
from sentry_sdk import capture_message
@permission_required("core.new_permission_test", raise_exception=True)
def new_feature(request):
# Anything
try:
division = 1 / 0
except Exception as e:
capture_message(f"Exception: {e}", level="error")