Open maxkomarychev opened 8 months ago
The same happens with method FastAPIInstrumentor.instrument_app(app)
:
venv/lib64/python3.9/site-packages/opentelemetry/instrumentation/fastapi/init.py:232: in instrument_app
def add_middleware(self, middleware_class: typing.Type[_MiddlewareClass[P]], *args: P.args, **kwargs: P.kwargs, ) -> None:
if self.middleware_stack is not None: # pragma: no cover
raise RuntimeError("Cannot add middleware after an application has started")
I also had this issue when I instrumented in lifespan startup event, here's my fix: https://github.com/pamelafox/staticmaps-function/pull/72
Uninstrument is breaking subsequent calls to
add_middleware
due to recent changes instarlette
https://github.com/encode/starlette/pull/2017 and latest version offastapi@>=0.91
.Call to
build_middleware_stack
makes an instance of FastAPI and starelette to think that application is already runningDescribe your environment
Python 3.9.9
Steps to reproduce Describe exactly how to reproduce the error. Include a code sample if applicable.
What is the expected behavior? What did you expect to see?
FastAPIInstrumentor.uninstrument_app
should not break ability to add more middlewaresWhat is the actual behavior? What did you see instead?
Application crashes:
Additional context Add any other context about the problem here.