Summary
NotesYou now have a complete observability stack: application and host metrics in Prometheus, alerts sent by Alertmanager, logs collected by Alloy into Loki, and everything visible in Grafana.
Every part of it was tested together while writing this guide: Prometheus scraping the application through host.containers.internal, the HomePageBusy rule firing and reaching Alertmanager, Alloy shipping the log file to Loki, and Grafana’s provisioned data sources connecting to both.
The example code includes test_metrics.py, which checks the /metrics page includes the request metrics and the custom counter.
Code
The example code at this point is tagged ch12-observability in the example repository. To get it:
git clone https://github.com/codewalkr/fastapi-example-for-you.git
cd fastapi-example-for-you
git checkout ch12-observability