Orange County Lettings - Sentry¶
This page explains how Sentry is integrated in the project and how exceptions are captured both from explicit errors and error pages.
Overview¶
Sentry is optional and enabled when the environment variable
SENTRY_DSNis set.Initialization occurs in
oc_lettings_site/settings.pywithsentry_sdk.initusingDjangoIntegrationandLoggingIntegration.In production (
ENV_MODE=prod), error handlers may send events to Sentry.
Initialization¶
Environment variable:
SENTRY_DSNmust be set (e.g., in Render or your environment).Configuration highlights:
send_default_pii=Trueto include request contexttraces_sample_rate=1.0for full transaction traces (tune in production)LoggingIntegrationcaptures logs (event_level=ERROR)DjangoIntegrationcaptures exceptions during requests and signals
Triggering an exception for testing¶
Route
/sentry-debug/deliberately raises an exception to validate Sentry capture.
404 and 500 pages¶
custom_404: logs a warning and, whenENV_MODE=prod, sends a message (capture_message) with levelwarningcustom_500: returns the 500 template; uncaught exceptions have already been captured by Sentry/Django
Views and try/except¶
Views in
lettingsandprofilesusetry/exceptto:Log database errors with
exc_info=TrueRaise
Http404for not found casesLog template errors (
TemplateDoesNotExist,TemplateSyntaxError)
These exceptions are either handled (404) or re-raised so that Sentry can capture them when applicable.
Local tips¶
Set
ENV_MODE=prodand a validSENTRY_DSNto mimic production behavior.Use
/sentry-debug/to verify that Sentry receives events from the environment.
Orange County Lettings