-
Notifications
You must be signed in to change notification settings - Fork 26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Django integration doesn't work for async projects #796
Comments
Actually, more changes are needed. The grouping function also needs to be called differently depending on sync vs async context. (Plus |
I've integrated your patches as well as a few others to make it a drop-in solution, see my fork https://github.com/djmango/metrics-sdks One thing is that for my use case I don't need sync requests at all, and to simplify things and avoid major rewrite of this package I made the Django integration of my fork async/ASGI only. This can and should certainly expand to work with both ASGI and WSGI, but I don't have the bandwidth today. Open to contribs. Because of that a PR to master isn't necessarily the most appropriate step today, feel free to just install from my branch if your needs are similar.
|
Any plans on supporting this new async world? @erunion @domharrington I'm looking to incorporate this django middleware into our project but we run Uvicorn and are facing this same incompatibility |
Hi all! Dropping in to say that we're planning on support ASGI in the coming months. Will add a more detailed description in the near future. |
I don't have time to make a proper PR soonish but here's a version of the middleware which works for both sync and async contexts:
Relevant documentation: https://docs.djangoproject.com/en/4.2/topics/http/middleware/#async-middleware
In addition,
readme_metrics.Metrics.Metrics
tries to accessrequest.environ
which is WSGI specific. For my use case, I just replaced it with a patched version which usesrequest.META
instead. For your package I imagine you'll want to handle both WSGI and ASGI gracefully.The text was updated successfully, but these errors were encountered: