Open reuben opened 1 year ago
Actually, more changes are needed. The grouping function also needs to be called differently depending on sync vs async context. (Plus PayloadBuilder
is also using request.environ
).
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.
pip install git+https://github.com/djmango/metrics-sdks.git@master#subdirectory=packages/python
or
poetry add git+https://github.com/djmango/metrics-sdks.git@master#subdirectory=packages/python --extras=Django
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.