feat(ops): failure counters + alerting hooks for background jobs (#86) #171
Loading…
Reference in a new issue
No description provided.
Delete branch "feat/86-failure-counters"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
Background-job failures only surfaced as
logger.errorto stdout — a backup/transcription failure at 2am was a log line nobody read, with no counter to alert on. Adds Prometheus counters, example alert rules, and an optional Sentry hook.Changes
metrics.py:backup_failed_total,celery_task_failed_total{task_name},bot_event_delivery_failed_total.celery_app.py: a@task_failure.connecthandler incrementscelery_task_failed_total{task_name}for every task automatically (no per-task edits).reminder_tasks.py:backup_failed_totalin therun_scheduled_backupexcept path;bot_event_delivery_failed_totalin the delivery-failure except paths. Only.inc()added — no delivery behaviour changed. For the two-tier HTTP→stream paths it counts only the terminal failure (both mechanisms exhausted), not an inner HTTP failure that then succeeds via fallback.sentry_dsnconfig (default empty);main.pyinitssentry-sdk(FastAPI + Celery integrations) only when set — theimportitself is skipped when unset, so it's a complete no-op.sentry-sdkpinned in requirements.OPERATIONS.md: new "Alerting" subsection with 3 example Prometheus rules (backup staleness >25h;rate(celery_task_failed_total[15m]) > 0for 15m; bot-delivery failures increasing).Verification
Backend full suite 394 passed (+ new tests: signal handler increments the labelled counter incl. a real
task_failure.send(); backup except-path increments;/metricsexposes all three). Confirmed the suite passes withsentry-sdknot importable (unset-DSN path fully guarded). ruff 0.4.4 clean.Closes #86
🤖 Generated with Claude Code