client_python icon indicating copy to clipboard operation
client_python copied to clipboard

ASGI lifespan crash

Open sheenobu opened this issue 3 years ago • 1 comments

client_python version: testing on 0.15.0 but the offending code exists in the master branch as well.

I'm trying to use the prometheus ASGI handler with Hypercorns DispatcherMiddleware. It sends lifecycle events which are not properly handled:

def make_asgi_app(registry: CollectorRegistry = REGISTRY, disable_compression: bool = False) -> Callable:
    """Create a ASGI app which serves the metrics from a registry."""

    async def prometheus_app(scope, receive, send):
        assert scope.get("type") == "http"
        # Prepare parameters

assert scope.get("type") == "http" ensures any ASGI middleware sending lifecycle events will fail to start the prometheus asgi app.

sheenobu avatar Nov 15 '22 23:11 sheenobu

middleware solution if you are eager for a fix:

https://gist.github.com/sheenobu/064b501b76415c6f6dacb6afa1ac6305

sheenobu avatar Nov 16 '22 19:11 sheenobu