fix(metrics): support FastAPI >=0.137 (bump prometheus instrumentator to >=8.0.2)#440
fix(metrics): support FastAPI >=0.137 (bump prometheus instrumentator to >=8.0.2)#440ibbybuilds wants to merge 1 commit into
Conversation
…astAPI >=0.137 FastAPI 0.137 changed app.routes to hold _IncludedRouter nodes that have no .path. The instrumentator 7.x walks app.routes and reads route.path on a match, raising AttributeError on every request when metrics are enabled. Aegra mounts all routers via include_router, so this 500'd every request under metrics on FastAPI >=0.137. 8.0.2 handles the new route tree and stays compatible with the older FastAPI we already resolve. Adds an integration regression covering an include_router route under metrics (the prior test used a direct @app.get, which never produced an _IncludedRouter and so could not catch this). Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
📝 WalkthroughWalkthroughThe ChangesPrometheus instrumentator bump and regression test
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~4 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Problem
With
ENABLE_PROMETHEUS_METRICS=trueand FastAPI>=0.137, every request returns HTTP 500.FastAPI 0.137 (fastapi/fastapi#15745) changed
app.routesto hold_IncludedRoutertree nodes that have no.path.prometheus-fastapi-instrumentator7.x walksapp.routesand readsroute.pathon a match:Aegra mounts all its routers via
include_router, so an_IncludedRouteris always present, and the instrumentator middleware raises on every request. The same FastAPI change brokeopentelemetry-instrumentation-fastapi(open-telemetry/opentelemetry-python-contrib#4699).Reported against
aegra-api==0.9.21+ FastAPI 0.137.0.Fix
Bump the floor:
prometheus-fastapi-instrumentator>=7.1.0→>=8.0.2. 8.0.2 handles the new route tree.Verification
Reproduced the exact
AttributeError500 with 7.1.0 + FastAPI 0.137 on aninclude_routerapp, confirmed 8.0.2 returns 200 on both FastAPI 0.138.1 (the broken range) and the older FastAPI we previously resolved. Added an integration regression that drives a templatedinclude_routerroute under metrics (the prior test used a direct@app.get, which never produces an_IncludedRouterand so could not catch this). Full unit + integration suite green on the bumped resolve (FastAPI 0.138.1 / starlette 1.3.1).Scope
Confirmed metrics is the only thing affected. The other two places Aegra touches
app.routesare safe on 0.137: the custom-route auth walker type-checks (isinstance APIRoute/ recurses on.routes) and the root-route check already guards withhasattr(route, "path").🤖 Generated with Claude Code
Summary by CodeRabbit
Bug Fixes
Tests
Greptile Summary
This PR updates the Prometheus metrics dependency for newer FastAPI route trees. The main changes are:
prometheus-fastapi-instrumentatorto>=8.0.2.include_routerroute.Confidence Score: 5/5
This looks safe to merge.
Important Files Changed
include_router.Reviews (1): Last reviewed commit: "fix(metrics): bump prometheus-fastapi-in..." | Re-trigger Greptile
Context used: