fix(fastapi): Fix FastAPI Instrumentation Compatibility with Middleware-Wrapped Apps#4041
Open
punitmahes wants to merge 3 commits intoopen-telemetry:mainfrom
Open
fix(fastapi): Fix FastAPI Instrumentation Compatibility with Middleware-Wrapped Apps#4041punitmahes wants to merge 3 commits intoopen-telemetry:mainfrom
punitmahes wants to merge 3 commits intoopen-telemetry:mainfrom
Conversation
|
|
3e478e3 to
9e3b02a
Compare
23d5e85 to
9aa86ce
Compare
9aa86ce to
a85bee6
Compare
Contributor
Author
|
@xrmx Following up if you got chance to have a look. |
xrmx
reviewed
Jan 19, 2026
| @@ -409,6 +417,9 @@ async def __call__( | |||
|
|
|||
| @staticmethod | |||
| def uninstrument_app(app: fastapi.FastAPI): | |||
Contributor
There was a problem hiding this comment.
Here and in instrument_app you are also taking a generic object I guess, CorsMiddleware does not inherit from anything
| Returns: | ||
| The unwrapped FastAPI or Starlette application. | ||
| """ | ||
| while hasattr(app, "app"): |
Contributor
There was a problem hiding this comment.
Should we break once app is fastapi.FastAPI?
xrmx
reviewed
Jan 19, 2026
| > Use [this search for a list of all CHANGELOG.md files in this repo](https://github.com/search?q=repo%3Aopen-telemetry%2Fopentelemetry-python-contrib+path%3A**%2FCHANGELOG.md&type=code). | ||
|
|
||
| ## Unreleased | ||
| - `opentelemetry-instrumentation-fastapi` Support for Middleware Wrapped FastAPI Application [#4041](https://github.com/open-telemetry/opentelemetry-python-contrib/issues/4031) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This pull request resolves issue #4031, which reported that FastAPI instrumentation did not work with middleware-wrapped applications such as
CORSMiddleware. The changes here ensure that theFastAPIInstrumentorcan properly identify and instrumentFastAPIorStarletteinstances, even if wrapped by middleware.Fixes #4031
Type of change
Please delete options that are not relevant.
How Has This Been Tested?
Does This PR Require a Core Repo Change?
Checklist:
See contributing.md for styleguide, changelog guidelines, and more.