prometheus / prometheus/client_python

ASGI mounted to FastAPI mounts metrics to `/metrics/` instead of `/metrics`

Open
#1,016 8 comments 10 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
4.4k
Forks
876
Avg merge
8d 4h
Merged PRs (30d)
1

Description

The documentation gives an example application which mounts the ASGI app to /metrics in a FastAPI app

from fastapi import FastAPI
from prometheus_client import make_asgi_app

# Create app
app = FastAPI(debug=False)

# Add prometheus asgi middleware to route /metrics requests
metrics_app = make_asgi_app()
app.mount("/metrics", metrics_app)

and says that you should be able to see the metrics at http://localhost:8000/metrics, however if you try to access this endpoint

$ uvicorn app:app
INFO:     Started server process [1620866]
INFO:     Waiting for application startup.
INFO:     Application startup complete.
INFO:     Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)
INFO:     127.0.0.1:34428 - "GET / HTTP/1.1" 404 Not Found
INFO:     127.0.0.1:34428 - "GET /favicon.ico HTTP/1.1" 404 Not Found
INFO:     127.0.0.1:34444 - "GET /metrics HTTP/1.1" 307 Temporary Redirect
INFO:     127.0.0.1:34444 - "GET /metrics/ HTTP/1.1" 200 OK

you get redirected to /metrics/.

It would be better if this redirect could be avoided.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the FastAPI example in the linked documentation and reproduce the mounted /metrics request using uvicorn. Check whether the redirect is controlled by the documented client_python example or the FastAPI mount behavior; done means either avoiding the redirect or documenting the actual endpoint behavior clearly.

Written by the indexing model from the issue text.

Assessment

Tech stack
fastapi, python
Domain
api, backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.