api.py 563 B

123456789101112131415161718
  1. from django_prometheus import exports
  2. from ninja import Router
  3. from ninja.errors import HttpError
  4. from apps.users.models import User
  5. from glitchtip.api.authentication import AuthHttpRequest
  6. from .metrics import compile_metrics
  7. router = Router()
  8. @router.get("observability/django/")
  9. async def django_prometheus_metrics(request: AuthHttpRequest):
  10. if not await User.objects.filter(id=request.auth.user_id, is_staff=True).aexists():
  11. raise HttpError(403, "is_staff required")
  12. await compile_metrics()
  13. return exports.ExportToDjangoView(request)