[Python] Add custom label based on endpoint with prometheus_fastapi_instrumentator

Discussão em 'Python' iniciado por Stack, Junho 11, 2025.

  1. Stack

    Stack Membro Participativo

    I am using prometheus_fastapi_instrumentator for my service. Now I am using Instrumentator().instrument(app).expose(app, include_in_schema=False) to get the basic metircs. But I want to add some custom labels in the metrics based on the endpoints. For example, I have some metrics like below:

    http_requests_total{handler="/orders/{order_id}",method="GET",status="2xx"} 99.0
    http_requests_total{handler="/orders/electronic/{order_id}/items/",method="GET",status="4xx"} 5.0


    Is it possible to add custom label based on the endpoint, so I could get something like below?

    http_requests_total{handler="/orders/{order_id}",label="order",method="GET",status="2xx"}
    http_requests_total{handler="/orders/electronic/{order_id}/items/",label="electronic",method="GET",status="4xx"}

    Continue reading...

Compartilhe esta Página