Monitoring & Observability
Effective monitoring is critical for identifying and diagnosing issues in production.
1. Structured Logging
Framework M uses standard Python logging but supports structured, JSON-based outputs for better readability in log aggregators (ELK, Datadog, etc.).
- Log Correlation: Use the
request_idin every log message to trace requests through the system. - Context Injection: Include the
user_idandtenant_idautomatically using theUserContextprovider in theFastAPIdependency hierarchy.
2. Health Checks (Liveness & Readiness)
We provide standard health check endpoints (/health and /ready) that must be used for Kubernetes or other orchestrators.
- /health: A basic liveness probe. Return 200 if the API can respond.
- /ready: A readiness probe that checks for downstream dependencies (Database, Redis, etc.) by default. It can be extended with custom checks (like database migration verification) by registering plugins under the
framework_m.readinessentrypoint group.
3. Metrics (Prometheus)
Native metrics are exposed at the /metrics endpoint (if configured).
- Request Counts: Track success/error rates per endpoint.
- Latencies: Use histograms for request-response times (p50, p95, p99).
- Queue Length: For background workers, monitor the Redis queue length as a proxy for labor pressure.
4. Distributed Tracing (OpenTelemetry)
Support for distributed tracing can be enabled by providing an OTLPAdapter. This allows for visualizing the request journey across multiple services (Monolith vs. Microservices).