Hello,
I've had an issue with django 5.2 and the django.contrib.auth.middleware.LoginRequiredMiddleware middleware on to enable site-wide login requirement.
I wanted to allow /metrics to be unauthenticated because it would be way too complicated to configure prometheus scraping with django auth system, and I don't think it's worth it from a security perspective.
Therefore, I did this bit of workaround:
from django_prometheus.exports import ExportToDjangoView
from django.contrib.auth.decorators import login_not_required
# Hack to allow unauthenticated access to the prometheus metrics view
# with django.contrib.auth.middleware.LoginRequiredMiddleware on
@login_not_required
def UnauthenticatedDjangoMetricsView(request):
return ExportToDjangoView(request)
urlpatterns = [
...
path('metrics', UnauthenticatedDjangoMetricsView, name="prometheus-django-metrics"),
]
However, it would be quite nice if there was some kind of switch parameter for django-prometheus to enable this decorator. I kinda hope my hack won't break at the next library update.
Thanks.