Aufgabe 36: Structured Logging & Fehlerbehandlung #11

Open
opened 2026-06-24 11:10:18 +02:00 by danielkrause · 0 comments
Owner

Ziel

Einheitliches Structured Logging (structlog) für alle Komponenten und robuste Fehlerbehandlung.

Ist-Stand

  • app.py verwendet print()-Statements und traceback.print_exc()
  • Keine strukturierten Logs (JSON-Format fehlt)
  • Keine Log-Level (alles stdout)
  • Fehler werden nicht zentral behandelt

Akzeptanzkriterien

Logging

  • structlog in app.py integrieren (JSON-Format)
  • Log-Level: DEBUG (Entwicklung), INFO (Produktion)
  • Request-Logging: Method, Path, Status, Duration
  • Webhook-Logs: Platform, Message-ID, Status
  • Worker-Logs: Submission-ID, Dauer, Ergebnis
  • Keine print()-Aufrufe mehr im Produktionscode

Fehlerbehandlung

  • Zentraler Error-Handler für Flask (400, 404, 500)
  • WhatsApp: 200 OK immer (sonst Retry-Loop), Fehler loggen
  • Telegram: Fehler an User melden (nicht silent)
  • Worker: Fehler in submission.status = "error" + submission.error_msg
  • Queue: Poison-Message-Handling (nach 3 Retries → Dead-Letter)

Dateien

  • logging_config.py — NEU (structlog-Setup)
  • error_handler.py — NEU (Flask-Error-Handler)
  • app.py — Logging-Integration
  • worker.py — Worker-Logging
  • tests/test_logging.py — NEU
  • tests/test_error_handler.py — NEU

Qualität

ruff check . --fix && ruff format . && pytest -v
## Ziel Einheitliches Structured Logging (structlog) für alle Komponenten und robuste Fehlerbehandlung. ## Ist-Stand - `app.py` verwendet `print()`-Statements und `traceback.print_exc()` - Keine strukturierten Logs (JSON-Format fehlt) - Keine Log-Level (alles stdout) - Fehler werden nicht zentral behandelt ## Akzeptanzkriterien ### Logging - [ ] structlog in `app.py` integrieren (JSON-Format) - [ ] Log-Level: DEBUG (Entwicklung), INFO (Produktion) - [ ] Request-Logging: Method, Path, Status, Duration - [ ] Webhook-Logs: Platform, Message-ID, Status - [ ] Worker-Logs: Submission-ID, Dauer, Ergebnis - [ ] Keine `print()`-Aufrufe mehr im Produktionscode ### Fehlerbehandlung - [ ] Zentraler Error-Handler für Flask (400, 404, 500) - [ ] WhatsApp: 200 OK immer (sonst Retry-Loop), Fehler loggen - [ ] Telegram: Fehler an User melden (nicht silent) - [ ] Worker: Fehler in `submission.status = "error"` + `submission.error_msg` - [ ] Queue: Poison-Message-Handling (nach 3 Retries → Dead-Letter) ### Dateien - `logging_config.py` — NEU (structlog-Setup) - `error_handler.py` — NEU (Flask-Error-Handler) - `app.py` — Logging-Integration - `worker.py` — Worker-Logging - `tests/test_logging.py` — NEU - `tests/test_error_handler.py` — NEU ### Qualität ```bash ruff check . --fix && ruff format . && pytest -v ```
Sign in to join this conversation.
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: danielkrause/BSN-Chatsystem#11