Closed refl3ct1on closed 2 months ago
I guess we need to rebuild middleware stack by hand.
def startup(app: FastAPI) -> Callable[[], Awaitable[None]]:
async def _startup() -> None:
"""Startup."""
app.middleware_stack = None
# Do all startup stuff
...
app.middleware_stack = app.build_middleware_stack()
return _startup
But this solution is a bit hacky. Let's leave this issue open for some time. I guess @tiangolo will fix it in new releases if we create an issue in fastapi repo.
Can you elaborate on how to do this? I'm getting the middleware error, and I set it up like this
@app.on_event("startup")
async def startup_event():
instrumentator = Instrumentator()
instrumentator.instrument(app).expose(app)
Nevermind, I find this https://github.com/trallnag/prometheus-fastapi-instrumentator/issues/214#issuecomment-1441706795
The fastapi was upgraded along with other dependencies.
Currently I am trying to use fastapi 0.94.0 and prometheus-fastapi-instrumentator 5.11.1 but I think the way instrumentator is initialised is not supported any more:
https://github.com/trallnag/prometheus-fastapi-instrumentator/issues/214