Monitoring
Monitoring is critical when running app in production. It gives you visibility across your infrastructure and allows you to debug issues without touching production servers.
Sentry provides error monitoring allowing you to quickly investigate errors in production. Sentry can also provide performance monitoring, equivalent to OpenTelemetry traces.
OpenTelemetry is a set of standards meant to observe production environments across the stack, from server to application.
Both are needed for proper monitoring of your infrastructure but Sentry may be sufficient when running on managed hosting providers.
Error monitoring using Sentry
It can be easily setup using Flask-Sentry:
Install Flask-Sentry:
uv add flask-sentry
Activate the extension in config.yml:
flask_extensions:
- "flask_sentry:Sentry":
dsn: "http://DSN"
To track frontend errors, override the default layout in app/layouts/default.html:
{% extends "layouts/base.html %}
{% block head_assets %}
{{ init_sentry() }}
{% endblock %}
When using a VPS
When deploying to a VPS, it is recommend to install the OpenTelemetry Collector to gather all telemetry data before forwarding it to a remote service.
You can install the collector as a container then:
- Configure the collector to collect hostmetrics
- Collect application metrics using Flask-Observability and point to the collector
Grafana is a great service to store and visualize your monitoring data. Their cloud service has a generous free tier but it is hard to self host.
It can be used as an OLTP endpoint to collect OpenTelemetry data. Configure the collector to export to this endpoint.
Signoz is an alternative that is purpose built for OpenTelemetry and that can be easily self hosted.
Uptime monitoring
Uptime monitoring allows you to recieve alerts when your infrastructure is completely down and measures how long it has been down.
Check out UptimeRobot (commercial service, no affiliation).