BackendDeployment
Monitoring
Error tracking with Sentry and task monitoring with Flower.
Sentry
Sentry captures errors and exceptions across Django, Celery, and Redis.
Configuration
import sentry_sdk
from sentry_sdk.integrations.logging import LoggingIntegration
from sentry_sdk.integrations.django import DjangoIntegration
from sentry_sdk.integrations.celery import CeleryIntegration
from sentry_sdk.integrations.redis import RedisIntegration
sentry_sdk.init(
dsn=env("SENTRY_DSN"),
integrations=[
LoggingIntegration(
level=logging.INFO, # Breadcrumbs from INFO
event_level=logging.ERROR, # Events from ERROR
),
DjangoIntegration(),
CeleryIntegration(),
RedisIntegration(),
],
environment=env("SENTRY_ENVIRONMENT", default="production"),
traces_sample_rate=env.float("SENTRY_TRACES_SAMPLE_RATE", default=0.0),
)Integrations
| Integration | What it captures |
|---|---|
DjangoIntegration | Unhandled exceptions in views, middleware errors |
CeleryIntegration | Task failures, retries, timeouts |
RedisIntegration | Redis connection errors |
LoggingIntegration | Python logging as breadcrumbs (INFO+) and events (ERROR+) |
Performance Monitoring
Set SENTRY_TRACES_SAMPLE_RATE to enable transaction tracing:
SENTRY_TRACES_SAMPLE_RATE=0.1 # Sample 10% of requestsLeave at 0.0 in production unless actively debugging performance — tracing adds overhead.
Environment Variables
| Variable | Default | Description |
|---|---|---|
SENTRY_DSN | — | Sentry project DSN |
DJANGO_SENTRY_LOG_LEVEL | INFO | Minimum log level for breadcrumbs |
SENTRY_ENVIRONMENT | production | Environment tag |
SENTRY_TRACES_SAMPLE_RATE | 0.0 | Transaction sample rate (0.0 - 1.0) |
Flower
Flower provides a real-time web dashboard for Celery monitoring.
What it shows
- Active, completed, and failed tasks
- Worker status and resource usage
- Task execution time and rate
- Task details (arguments, result, traceback)
- Broker (Redis) connection status
Access
| Environment | URL | Auth |
|---|---|---|
| Local | http://localhost:5555 | None |
| Production | https://yourdomain.com:5555 | Basic auth |
Production Auth
CELERY_FLOWER_USER=admin
CELERY_FLOWER_PASSWORD=your-secure-passwordFlower is exposed via Traefik on a separate entrypoint (port 5555).
Logging
Django's logging is configured in base.py. Key loggers:
| Logger | Level | Purpose |
|---|---|---|
django | INFO | Django framework messages |
django.request | ERROR | HTTP 4xx/5xx responses |
backend.documents.tasks | INFO | Document ingestion pipeline |
backend.chat | INFO | Chat/agent operations |
celery | INFO | Task execution lifecycle |
In production, Sentry captures all ERROR-level log entries as events and INFO-level entries as breadcrumbs for context.
Health Checks
Application
# Django system check
docker compose exec django python manage.py check
# Database connectivity
docker compose exec django python manage.py check --database default
# API responding
curl -s http://localhost:8000/api/schema/ | head -1Celery
# Ping workers
docker compose exec django celery -A config.celery_app inspect ping
# Check active tasks
docker compose exec django celery -A config.celery_app inspect active
# Check scheduled tasks
docker compose exec django celery -A config.celery_app inspect scheduledDatabase
# PostgreSQL shell
docker compose exec postgres psql -U $POSTGRES_USER -d $POSTGRES_DB
# Check pgvector extension
SELECT * FROM pg_extension WHERE extname = 'vector';
# Check table sizes
SELECT relname, pg_size_pretty(pg_total_relation_size(relid))
FROM pg_stat_user_tables ORDER BY pg_total_relation_size(relid) DESC;Redis
# Redis CLI
docker compose exec redis redis-cli
# Check memory usage
redis-cli INFO memory
# Check connected clients
redis-cli INFO clients