Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

incompatibility with fastapi-versioning #31

Closed
fiddletwix opened this issue Apr 17, 2021 · 5 comments · Fixed by #208
Closed

incompatibility with fastapi-versioning #31

fiddletwix opened this issue Apr 17, 2021 · 5 comments · Fixed by #208

Comments

@fiddletwix
Copy link

Whenever I use the instrumentator and I use the fastapi-versionin lib, all my handlers match just my version. I think it's because of the prefix format here:

app = VersionedFastAPI(
    app,
    version_format="{major}",
    prefix_format="/v{major}",
    default_version=(1, 0),
)

I'm not sure this is fixable but I did want to report it here

@nikitira
Copy link

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

@trallnag
Copy link
Owner

Are we talking about this project?

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

@james-aliya
Copy link

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

@JoniB
Copy link

JoniB commented Nov 3, 2021

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.

@lucacampanella
Copy link

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. :)

@trallnag trallnag linked a pull request Feb 24, 2023 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants