Observability
KeyNetra includes first-party metrics and structured logging for operational visibility.
Observability components:
- Metrics definitions:
keynetra/observability/metrics.py - Metrics endpoint:
keynetra/api/routes/metrics.py - Logging config:
keynetra/infrastructure/logging.py - Request logging middleware:
keynetra/api/middleware/logging.py
Metrics Endpoint
GET /metrics returns Prometheus text format (text/plain; version=0.0.4).
Metric Families
From implementation, key metrics include:
keynetra_access_checks_totalkeynetra_acl_matches_totalkeynetra_policy_evaluations_totalkeynetra_relationship_traversals_totalkeynetra_policy_compilations_totalkeynetra_revision_updates_totalkeynetra_access_check_latency_secondskeynetra_decision_latency_secondskeynetra_cache_hits_totalkeynetra_cache_misses_totalkeynetra_cache_events_totalkeynetra_api_errors_total
These metrics cover authorization decisions, cache behavior, policy/model lifecycle, and API error rates.
Logging Modes
- JSON logs by default
- Rich colored logs when
KEYNETRA_LOG_FORMAT=rich
Docker startup script sets rich mode by default.
Use JSON mode for log aggregation pipelines and rich mode for local operator readability.
Prometheus and Grafana
Compose stack includes monitoring:
- Prometheus config:
infra/docker/monitoring/prometheus/prometheus.yml - Grafana provisioning:
infra/docker/monitoring/grafana/provisioning/ - Dashboards:
infra/docker/monitoring/grafana/dashboards/
Quick Validation
curl -s http://localhost:8000/metrics | head