Mounting to Starlette app adds trailing '/' #2548
-
I am running a FastAPI server, and mounted a asgi middleware to be able to serve prometheus metrics on the same server at the Now the scrape endpoint can be changed to have a trailing slash, but it involves custom changes to the scrape targets, and via most defaults, I would prefer this to be on the '/metrics' endpoint. I think I found the code section that causes this issue for me routing.py. What do you think? Am I doing something wrong? Or is is a fair use case for this to be configurable? My violating code block: ...
# Add prometheus asgi middleware to route /metrics requests
metrics_app = make_asgi_app()
app.mount(path="/metrics", app=metrics_app)
... |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
As far as I know, that's the default behavior, not a problem but feature. |
Beta Was this translation helpful? Give feedback.
-
This is annoying because it pollutes the logs with constants As a turnaround I've defined the @app.get("/metrics")
async def metrics_endpoint():
# Generate the Prometheus metrics and return them as a plain text response
metrics_data = prometheus_client.generate_latest()
return Response(content=metrics_data, media_type="text/plain") |
Beta Was this translation helpful? Give feedback.
As far as I know, that's the default behavior, not a problem but feature.