client_python
client_python copied to clipboard
Add no-op asgi-lifespan handling
Super simple hook that checks for lifespan and immediately responds type.complete, essentially making startup/shutdown lifespan events no-ops for the prometheus ASGI app.
Fixes #855
from hypercorn.middleware import DispatcherMiddleware
from prometheus_client import make_asgi_app
import asyncio
async def main():
from hypercorn.asyncio import serve
from hypercorn.config import Config
app = DispatcherMiddleware({
"/metrics": make_asgi_app(),
})
config = Config()
config.bind = ["localhost:8080"]
await serve(app, config)
Before:
assert scope.get("type") == "http"
AssertionError
After:
[2022-11-15 16:05:20 -0800] [59048] [INFO] Running on http://127.0.0.1:8080 (CTRL + C to quit)
INFO:hypercorn.error:Running on http://127.0.0.1:8080 (CTRL + C to quit)
Signed-off-by: Sheena Artrip [email protected]
If an exception is raised when calling the application callable with a lifespan.startup message or a scope with type lifespan, the server must continue but not send any lifespan events.
this might be a better solution!