File tree Expand file tree Collapse file tree 1 file changed +9
-5
lines changed Expand file tree Collapse file tree 1 file changed +9
-5
lines changed Original file line number Diff line number Diff line change 75
75
76
76
router = APIRouter ()
77
77
78
- # Add prometheus asgi middleware to route /metrics requests
79
- route = Mount ("/metrics" , make_asgi_app ())
80
- # Workaround for 307 Redirect for /metrics
81
- route .path_regex = re .compile ("^/metrics(?P<path>.*)$" )
82
- router .routes .append (route )
78
+
79
+ def mount_metrics (app : fastapi .FastAPI ) -> None :
80
+ # Add prometheus asgi middleware to route /metrics requests
81
+ metrics_route = Mount ("/metrics" , make_asgi_app ())
82
+ # Workaround for 307 Redirect for /metrics
83
+ metrics_route .path_regex = re .compile ("^/metrics(?P<path>.*)$" )
84
+ app .routes .append (metrics_route )
83
85
84
86
85
87
@router .get ("/health" )
@@ -188,6 +190,8 @@ async def _force_log(): # noqa: ANN202
188
190
app .include_router (router )
189
191
app .root_path = args .root_path
190
192
193
+ mount_metrics (app )
194
+
191
195
app .add_middleware (
192
196
CORSMiddleware ,
193
197
allow_origins = args .allowed_origins ,
You can’t perform that action at this time.
0 commit comments