You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
INFO: Will watch for changes in these directories: ['/Users/username/project/backend']
INFO: Uvicorn running on http://0.0.0.0:8000 (Press CTRL+C to quit)
INFO: Started reloader process [25843] using WatchFiles
2023-03-13 13:30:27.298 | INFO | logging:callHandlers:1706 - Started server process [25847]
2023-03-13 13:30:27.298 | INFO | logging:callHandlers:1706 - Waiting for application startup.
2023-03-13 13:30:27.302 | ERROR | logging:callHandlers:1706 - Traceback (most recent call last):
File "/Users/username/Library/Caches/pypoetry/virtualenvs/project-6TboK3_T-py3.11/lib/python3.11/site-packages/starlette/routing.py", line 675, in lifespan
async with self.lifespan_context(app) as maybe_state:
File "/Users/username/Library/Caches/pypoetry/virtualenvs/project-6TboK3_T-py3.11/lib/python3.11/site-packages/starlette/routing.py", line 566, in __aenter__
await self._router.startup()
File "/Users/username/Library/Caches/pypoetry/virtualenvs/project-6TboK3_T-py3.11/lib/python3.11/site-packages/starlette/routing.py", line 652, in startup
await handler()
File "/Users/username/project/backend/project/web/lifetime.py", line 60, in _startup
setup_cors(app)
File "/Users/username/project/backend/project/web/lifetime.py", line 35, in setup_cors
app.add_middleware(
File "/Users/username/Library/Caches/pypoetry/virtualenvs/project-6TboK3_T-py3.11/lib/python3.11/site-packages/starlette/applications.py", line 137, in add_middleware
raise RuntimeError("Cannot add middleware after an application has started")
RuntimeError: Cannot add middleware after an application has started
I guess we need to rebuild middleware stack by hand.
defstartup(app: FastAPI) ->Callable[[], Awaitable[None]]:
asyncdef_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.
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:
trallnag/prometheus-fastapi-instrumentator#214
The text was updated successfully, but these errors were encountered: