Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure StaticFiles doesn't break instrument_fastapi #294

Merged
merged 1 commit into from
Jul 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions logfire/_internal/integrations/fastapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@ def find_mounted_apps(app: FastAPI) -> list[FastAPI]:
for route in app.routes:
if isinstance(route, Mount):
_app: Any = route.app
mounted_apps.append(_app)
mounted_apps += find_mounted_apps(_app)
if isinstance(_app, FastAPI):
mounted_apps.append(_app)
mounted_apps += find_mounted_apps(_app)
return mounted_apps


Expand Down
2 changes: 2 additions & 0 deletions tests/otel_integrations/test_fastapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from fastapi.exceptions import RequestValidationError
from fastapi.params import Header
from fastapi.security import SecurityScopes
from fastapi.staticfiles import StaticFiles
from inline_snapshot import snapshot
from opentelemetry.propagate import inject
from starlette.requests import Request
Expand Down Expand Up @@ -75,6 +76,7 @@ def app():
app = FastAPI()
first_lvl_app = FastAPI()
second_lvl_app = FastAPI()
app.mount('/static', StaticFiles(), name='static') # https://github.com/pydantic/logfire/issues/288
app.mount('/first_lvl', first_lvl_app)
first_lvl_app.mount('/second_lvl', second_lvl_app)

Expand Down