Merge pull request #456 from ae-utbm/455-sentry-modal

Updated sentry modal SDK
This commit is contained in:
Théo DURR 2022-08-27 21:47:59 +02:00 committed by GitHub
commit 5e6d60bb3a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 39 additions and 3 deletions

View File

@ -1,7 +1,11 @@
{% extends "core/base.jinja" %} {% extends "core/base.jinja" %}
{% block head %} {% block head %}
{{ super() }} {{ super() }}
<script src="{{ static('core/js/sentry/bundle.min.js') }}" crossorigin="anonymous"></script> <script
src="https://browser.sentry-cdn.com/7.11.1/bundle.min.js"
integrity="sha384-qcYSo5+/E8hEkPmHFa79GRDsGT84SRhBJHRw3+dbQyh0UwueiFP1jCsRBClEREcs"
crossorigin="anonymous"
></script>
{% endblock head %} {% endblock head %}
{% block content %} {% block content %}
@ -9,7 +13,15 @@
{% if settings.SENTRY_DSN %} {% if settings.SENTRY_DSN %}
<script> <script>
Sentry.init({ dsn: '{{ settings.SENTRY_DSN }}' }); Sentry.init({ dsn: '{{ settings.SENTRY_DSN }}' });
Sentry.showReportDialog({ eventId: '{{ request.sentry_last_event_id() }}' }) Sentry.showReportDialog({
eventId: '{{ request.sentry_last_event_id() }}',
{% if user.is_authenticated %}
user: {
'name': '{{user.first_name}} {{user.last_name}}',
'email': '{{user.email}}'
}
{% endif %}
})
</script> </script>
{% endif %} {% endif %}
{% endblock content %} {% endblock content %}

View File

@ -643,6 +643,7 @@ SITH_MAILING_FETCH_KEY = "IloveMails"
SITH_GIFT_LIST = [("AE Tee-shirt", _("AE tee-shirt"))] SITH_GIFT_LIST = [("AE Tee-shirt", _("AE tee-shirt"))]
SENTRY_DSN = "" SENTRY_DSN = ""
SENTRY_ENV = "production"
try: try:
from .settings_custom import * from .settings_custom import *
@ -669,13 +670,18 @@ if DEBUG:
"debug_toolbar.panels.redirects.RedirectsPanel", "debug_toolbar.panels.redirects.RedirectsPanel",
] ]
SASS_INCLUDE_FOLDERS = ["core/static/"] SASS_INCLUDE_FOLDERS = ["core/static/"]
SENTRY_ENV = "development"
if "test" in sys.argv: if "test" in sys.argv:
CAPTCHA_TEST_MODE = True CAPTCHA_TEST_MODE = True
if SENTRY_DSN: if SENTRY_DSN:
# Connection to sentry # Connection to sentry
sentry_sdk.init(dsn=SENTRY_DSN, integrations=[DjangoIntegration()]) sentry_sdk.init(
dsn=SENTRY_DSN,
integrations=[DjangoIntegration()],
environment=SENTRY_ENV,
)
SITH_FRONT_DEP_VERSIONS = { SITH_FRONT_DEP_VERSIONS = {

View File

@ -86,9 +86,27 @@ urlpatterns = [
path("captcha/", include("captcha.urls")), path("captcha/", include("captcha.urls")),
] ]
if settings.DEBUG: if settings.DEBUG:
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT) urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
import debug_toolbar import debug_toolbar
urlpatterns += [path("__debug__/", include(debug_toolbar.urls))] urlpatterns += [path("__debug__/", include(debug_toolbar.urls))]
"""Sentry debug endpoint
This function always crash and allows us to test
the sentry configuration and the modal popup
displayed to users on production
The error will be displayed on Sentry
inside the "development" environment
NOTE : you need to specify the SENTRY_DSN setting in settings_custom.py
"""
def raise_exception(request):
division_by_zero = 1 / 0
urlpatterns += [path("sentry-debug/", raise_exception)]