Code Monkey home page Code Monkey logo

Comments (5)

trallnag avatar trallnag commented on August 12, 2024 2

Are we talking about this project?

https://github.com/DeanWay/fastapi-versioning

from prometheus-fastapi-instrumentator.

lucacampanella avatar lucacampanella commented on August 12, 2024 2

Hi,

I found a quick workaround, since fastpi-versioning mounts an api for each version, you can attach the metrics to each mounted api seperatly:

app = VersionedFastAPI(...)

# add Prometheus Metrics
for route in app.routes:
    if isinstance(route, starlette.routing.Mount):
        Instrumentator().instrument(route.app).expose(route.app)

This of course generates one metrics endpoint per versioned-api (localhost:XXXX/v1/metrics), but its better than nothing.

This was very helpful, I was still getting an error because some of the default metrics shared names between different versions, so I changed the default metrics names before instrumenting, like so:

for route in app.routes:
    if isinstance(route, starlette.routing.Mount):
        instr = Instrumentator()
        default_metrics = metrics.default(
            metric_namespace=route.path.strip("/"),
        )
        instr.add(default_metrics)
        instr.instrument(route.app).expose(route.app)

Just putting it here for reference. :)

from prometheus-fastapi-instrumentator.

nikitira avatar nikitira commented on August 12, 2024

I'm having the same problem - any solution yet? @trallnag

from prometheus-fastapi-instrumentator.

james-aliya avatar james-aliya commented on August 12, 2024

Not to answer for the op, but yes I think that is the github for the fastapi-version project

from prometheus-fastapi-instrumentator.

JoniB avatar JoniB commented on August 12, 2024

Hi,

I found a quick workaround, since fastpi-versioning mounts an api for each version, you can attach the metrics to each mounted api seperatly:

app = VersionedFastAPI(...)

# add Prometheus Metrics
for route in app.routes:
    if isinstance(route, starlette.routing.Mount):
        Instrumentator().instrument(route.app).expose(route.app)

This of course generates one metrics endpoint per versioned-api (localhost:XXXX/v1/metrics), but its better than nothing.

from prometheus-fastapi-instrumentator.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.