Skip to content

ASGI mounted to FastAPI mounts metrics to /metrics/ instead of /metrics #1016

@hmellor

Description

@hmellor

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions