stephenhillier / starlette_exporter

Prometheus exporter for Starlette and FastAPI

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Mount has no attribute endpoint

marco-neumann-by opened this issue · comments

If you are using starlette Mounts (e.g. via FastAPI StaticFiles):

app.mount("/static", StaticFiles(directory="some/local/path"), name="static")

starlette_exporter results in the following error log:

ERROR:    'Mount' object has no attribute 'endpoint'

due to this code:

try:
path = [route for route in request.scope['router'].routes if route.endpoint == request.scope['endpoint']][0].path
except Exception as e:
logger.error(e)

Hi, thanks for the report.

The Mount object from Starlette doesn't seem to have an endpoint attribute, which is what I was using to organize paths for the group_paths option. That might make it difficult to group metrics for static files under one path (is that the behavior you want?).

In the meantime I can try to improve the error handling.

I have a potential solution that still allows grouping of static file metrics, but it needs more thorough testing... I opened a pull request in case you have any comments. #7