Install sentry-sdk
into your Django project:
$ pip install --upgrade sentry-sdk
To configure the SDK, initialize it with the Django integration in your settings.py
file:
import sentry_sdk
from sentry_sdk.integrations.django import DjangoIntegration
sentry_sdk.init(
dsn="YOUR-GLITCHTIP-DSN-HERE",
integrations=[DjangoIntegration()],
auto_session_tracking=False,
traces_sample_rate=0
)
You can verify your SDK installation by creating a route that triggers an error:
from django.urls import path
def trigger_error(request):
division_by_zero = 1 / 0
urlpatterns = [
path('glitchtip-debug/', trigger_error),
# ...
]
Visiting this route will trigger an error that will be captured by GlitchTip.
Here is a more robust configuration example:
sentry_sdk.init(
dsn="YOUR-GLITCHTIP-DSN-HERE",
integrations=[DjangoIntegration()],
auto_session_tracking=False,
traces_sample_rate=0.01,
release="1.0.0",
environment="production",
)
SENTRY_RELEASE
.SENTRY_ENVIRONMENT
.Using Content Security Policy (CSP)? Send reports to GlitchTip. Set your website's CSP report-uri
directive to the GlitchTip Security Endpoint.
If using Django-CSP, in settings.py set:
CSP_REPORT_URI = ["your Security Endpoint here"]