You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello, I was thinking it would be great to add explicit support for Django. Besides updating the documentation, it would be useful to provide a view so it can be added easily in the urlconf of a django app.
django-prometheus does it like this using generate_latest, but from looking at the already provided exposition endpoints, I was thinking of using the _bake_output utility instead.
I'm volunteering to make a PR for it.
What do you think?
There could be opportunity for this similar to what is done for twisted. Specifically, only optional dependency on django code and in a separate directory.
That said, is there a problem you are encountering with django-prometheus? Perhaps we just link out to other projects to make it easier to discover how to use Prometheus with various frameworks? Starlette also comes to mind.
Yes I was thinking of following the same code architecture as the twisted support, to avoid any conflict.
To give you my context:
I am not using django-prometheus currently (so I have no problem with it ^^): django-prometheus gives you lots of already configured metrics out of the box and that's its main use, whereas I was only trying to add one specific custom metrics to my existing django-app so prometheus-client seemed more than enough
I found it hard to understand how to add a prometheus endpoint to my existing django app with no specific guidance in the prometheus-client documentation
Hence I ended up looking at how django-prometheus was doing it, and also how it was done for other web-frameworks here (like twisted)
django-prometheus is kinda huge and does a lot of things, so linking it as an example on how to integrate with prometheus-client is a bit involved I think. A simple view calling _bake_output and some dedicated documentation would be very appreciated of those coming from django I think :)
Maybe in time the provided view might even be used by django-prometheus directly instead of having to provide their own.
I am still a bit hesitant to add full code for django as that could be confusing with when to use django-prometheus. That said, I do agree that having at least some documentation would be helpful. What if you added an example like https://prometheus.github.io/client_python/exporting/http/flask/, but for django? Especially if it is just going to do something like call generate_latest()
@Agent-Hellboy I'm not sure what you mean exactly, could you elaborate?
PS: this issue is still in my todo list, I don't have much time at the moment but I'm planning to get back to it eventually
I mean writing an ASGI middleware, as you would be serving Django over Uvicorn (maybe something else) if you're running an asynchronous app. I’ve written something that could be helpful for you. Please take a look. https://github.com/Agent-Hellboy/asgi-prometheus-exporter
If it’s really helpful I will try to test and enhancer it with other frameworks and web servers as this is an independent bridge which assume framework and webserver following a spec.
Activity
csmarchbanks commentedon Jan 28, 2025
There could be opportunity for this similar to what is done for twisted. Specifically, only optional dependency on django code and in a separate directory.
That said, is there a problem you are encountering with django-prometheus? Perhaps we just link out to other projects to make it easier to discover how to use Prometheus with various frameworks? Starlette also comes to mind.
Chadys commentedon Jan 28, 2025
Yes I was thinking of following the same code architecture as the twisted support, to avoid any conflict.
To give you my context:
django-prometheus is kinda huge and does a lot of things, so linking it as an example on how to integrate with prometheus-client is a bit involved I think. A simple view calling
_bake_outputand some dedicated documentation would be very appreciated of those coming from django I think :)Maybe in time the provided view might even be used by django-prometheus directly instead of having to provide their own.
Chadys commentedon Feb 27, 2025
So, should I make a PR for this? :)
csmarchbanks commentedon Feb 28, 2025
I am still a bit hesitant to add full code for django as that could be confusing with when to use django-prometheus. That said, I do agree that having at least some documentation would be helpful. What if you added an example like https://prometheus.github.io/client_python/exporting/http/flask/, but for django? Especially if it is just going to do something like call
generate_latest()Agent-Hellboy commentedon May 18, 2025
Hi @Chadys what do you think of exporting metric at
gunicornor whateverwebserverlayer ?Chadys commentedon May 18, 2025
@Agent-Hellboy I'm not sure what you mean exactly, could you elaborate?
PS: this issue is still in my todo list, I don't have much time at the moment but I'm planning to get back to it eventually
Agent-Hellboy commentedon May 20, 2025
Hi @Chadys ,
I mean writing an ASGI middleware, as you would be serving Django over Uvicorn (maybe something else) if you're running an asynchronous app. I’ve written something that could be helpful for you. Please take a look. https://github.com/Agent-Hellboy/asgi-prometheus-exporter
If it’s really helpful I will try to test and enhancer it with other frameworks and web servers as this is an independent bridge which assume framework and webserver following a spec.
Chadys commentedon May 21, 2025
Ok I understand better what you mean. But I think it's out of scope from the current issue.
Add Django exporter (prometheus#1088)
Add Django exporter (prometheus#1088)
Chadys commentedon Nov 11, 2025
@csmarchbanks I made a PR about this :)
csmarchbanks commentedon Nov 20, 2025
Thanks! It's on my list to review soon!
Add Django exporter (prometheus#1088)
Add Django exporter (prometheus#1088)
Add Django exporter (#1088) (#1143)