Skip to content

Commit ed8fdcd

Browse files
Merge pull request #2973 from onmete/chore/deps-update
chore: bump dependencies to latest
2 parents 3442d5e + 9b711e0 commit ed8fdcd

4 files changed

Lines changed: 967 additions & 1048 deletions

File tree

ols/app/main.py

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from fastapi import FastAPI, Request, Response
77
from starlette.datastructures import Headers
88
from starlette.responses import StreamingResponse
9-
from starlette.routing import Mount, Route, WebSocketRoute
9+
from starlette.routing import BaseRoute, Mount, Route, WebSocketRoute
1010

1111
from ols import config, constants, version
1212
from ols.app import metrics, routers
@@ -191,11 +191,24 @@ async def stream_response_body(
191191

192192
routers.include_routers(app)
193193

194-
app_routes_paths = [
195-
route.path
196-
for route in app.routes
197-
if isinstance(route, (Mount, Route, WebSocketRoute))
198-
]
194+
195+
def _collect_app_route_paths(routes: list[BaseRoute]) -> list[str]:
196+
"""Collect route paths for metrics middleware, including included routers."""
197+
paths: list[str] = []
198+
for route in routes:
199+
if hasattr(route, "effective_candidates"):
200+
for candidate in route.effective_candidates():
201+
if hasattr(candidate, "effective_candidates"):
202+
paths.extend(_collect_app_route_paths([candidate]))
203+
elif path := getattr(candidate, "path", None):
204+
paths.append(path)
205+
continue
206+
if isinstance(route, (Mount, Route, WebSocketRoute)) and route.path is not None:
207+
paths.append(route.path)
208+
return paths
209+
210+
211+
app_routes_paths = _collect_app_route_paths(app.routes)
199212

200213
cleanup_offload_storage(config.ols_config.offload_storage_path)
201214

0 commit comments

Comments
 (0)