Monitor — django_monitor
django_monitor captures server-side errors and browser events, then pushes them to Cloudflare D1 via django_cf. No separate database, no PostgreSQL tables — events live at the edge alongside your user data.
django_monitor requires django_cf to be configured (CloudflareConfig(enabled=True, ...)). If Cloudflare is not configured, all capture paths silently no-op.
How It Fits Together
What Gets Captured
| Source | Event type | Dedup |
|---|---|---|
got_request_exception signal | UNHANDLED_EXCEPTION | by fingerprint |
logging.Handler with exception | UNHANDLED_EXCEPTION | by fingerprint |
logging.Handler without exception | LOG_ERROR | by fingerprint |
execute_wrapper (slow DB query) | SLOW_QUERY | by fingerprint |
RQ exception_handler | RQ_FAILURE | by fingerprint |
capture_exception() | SERVER_ERROR | by fingerprint |
capture_message() | LOG_ERROR | by message hash |
Browser SDK (@djangocfg/monitor) | various | append-only |
Server events are deduplicated — same fingerprint = occurrence_count++ on the existing row.
Frontend events are append-only — duplicate (session_id, event_id) pairs are silently ignored.
Quick Start
1. Configure django_cf
# djangoconfig.py
from django_cfg import CloudflareConfig
class MyConfig(DjangoConfig):
cloudflare: CloudflareConfig = CloudflareConfig(
enabled=True,
account_id="${CF_ACCOUNT_ID}",
api_token="${CF_API_TOKEN}",
d1_database_id="${CF_D1_DATABASE_ID}",
telegram_alerts_enabled=True,
)DjangoMonitorConfig AppConfig is registered automatically. On first event, the schema (server_events + frontend_events tables) is created in D1.
2. Manual capture (optional)
from django_cfg.modules.django_monitor import capture_exception, capture_message
try:
process_payment(order)
except Exception as e:
capture_exception(e, url="/api/orders/", http_method="POST")
capture_message("payment gateway slow", level="warning", extra={"latency_ms": 3200})Both calls are fire-and-forget — they never raise.
3. Check status
python manage.py monitor_statusStreamlit Admin Dashboard
Events are visible in the Streamlit admin under the Monitor section:
- Server Events — deduplicated list with
occurrence_count,first_seen,last_seen - Frontend Events — browser event stream, filterable by type, project, session
What’s Next
capture_exception / capture_message APIConfigurationSlow query threshold, Telegram alerts, retentionFrontend SDKBrowser @djangocfg/monitor package, withMonitor, window.monitor@djangocfg/layoutsZero-config monitor + debug panel via AppLayoutManagement Commandsmonitor_status, monitor_cleanupCloudflare D1 ModuleThe underlying storage layerTAGS: django_monitor, error-tracking, cloudflare-d1, server-events, frontend-events DEPENDS_ON: [django-cf/overview]