prometheus-fastapi-instrumentator icon indicating copy to clipboard operation
prometheus-fastapi-instrumentator copied to clipboard

BaseHTTPMiddleware vs BackgroundTasks

Open Kludex opened this issue 4 years ago • 7 comments

@trallnag I've just noticed that we use @app.middleware('http') here, I should have been able to catch this earlier... Anyway, that decorator is implemented on top of BaseHTTPMiddleware, which has a problem: https://github.com/encode/starlette/issues/919

Solution: change the implementation to a pure ASGI app/middleware.

PS.: I can open a PR with it, jfyk.

Kludex avatar Dec 04 '20 13:12 Kludex

Async Python is a complete black box for me I have zero experience with so far (except the little bit I interact with it in FastAPI). So if you know a way to refactor the code, please go on. Would be awesome

trallnag avatar Dec 04 '20 13:12 trallnag

I've found a very insightful article yesterday: https://florimond.dev/blog/articles/2019/08/introduction-to-asgi-async-python-web/

But anyway, thank you. I'll be working on it then (it should not be many changes, only focused on the middleware interface).

Kludex avatar Dec 04 '20 14:12 Kludex

Took me a few hours today to get to this issue 😄 Glad to see it has already been worked on, thanks @Kludex and @trallnag 🙂 Any way I can help moving this forward?

pawamoy avatar Apr 06 '22 15:04 pawamoy

Oh, I see @Kludex is also working on resolving the original issue in Starlette.

pawamoy avatar Apr 06 '22 15:04 pawamoy

Any way I can help moving this forward?

Yes, you can take my PR: https://github.com/trallnag/prometheus-fastapi-instrumentator/pull/23 .

Oh, I see @Kludex is also working on resolving the original issue in Starlette.

🏃 💨

Kludex avatar Apr 06 '22 15:04 Kludex

Should I understand the Starlette PR is doomed 😅 ? I'll see if I can continue your work once @trallnag has given us updates (on this PR or on the CI one) 🙂

pawamoy avatar Apr 06 '22 16:04 pawamoy

Should I understand the Starlette PR is doomed 😅 ?

I'm bothering ppl to review it... 😅

Kludex avatar Apr 06 '22 16:04 Kludex

Hi all, would it be possible to get a status update here? Does the close on this PR means this will never be implemented? https://github.com/encode/starlette/issues/919 or it's fixed via: https://github.com/encode/starlette/pull/1715?

Does anybody have/tested a workaround, like: https://github.com/encode/starlette/issues/919#issuecomment-644596659 ?

thanks

tonkolviktor avatar Oct 10 '22 14:10 tonkolviktor

This was already fixed here.

Kludex avatar Oct 10 '22 14:10 Kludex