Health, logs and observability
Observability helps you tell whether your Mojara application is running and what failed when requests do not work.
1. Add a health endpoint
def health(req: Request) -> Response:
return Response.json('{"status":"ok"}')
app.get("/api/health", health)
A load balancer can request /api/health and confirm a successful response.
2. Check it yourself
curl -i http://127.0.0.1:8000/api/health
Expected: HTTP 200 OK and {"status":"ok"}.
3. Distinguish liveness from readiness
A process can be alive but unable to accept more traffic. The reference application uses:
GET /api/live -> 200 while the process is alive
GET /api/ready -> 200 when accepting traffic; 503 while draining
Register these endpoints only when needed by your deployment, and make readiness reflect real dependencies.
4. Log useful events
def create_note(req: Request) -> Response:
print("POST /api/notes")
return Response.json('{"created":true}', status=201)
This simple example logs the action. A production logger should also record timestamp, HTTP method, route, status and duration. Never log passwords, session tokens or entire private request bodies.
5. Diagnose an HTTP failure
curl -i https://app.example.com/api/health
sudo journalctl -u your-mojara-service -n 50 --no-pager
sudo tail -f /var/log/nginx/error.log
The first command checks the response, the second inspects service output, and the third checks the reverse proxy.
6. Metrics
Monitor request count, error rate, active requests, CPU, memory and latency. Treat 5xx spikes as signals to inspect logs and dependencies rather than simply restarting repeatedly.