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

feat: Allow passing a custom registry to be used instead of using the default one #153

Merged
merged 9 commits into from Feb 22, 2023

Conversation

tiangolo
Copy link
Contributor

@tiangolo tiangolo commented Jun 17, 2022

✨ Allow passing a custom registry to be used instead of using the default one.

This would be useful in particular when testing multiple FastAPI apps (e.g. microservices) in the same tests run.

This is also related to #80

Note: I'm still having issues with this in different corner cases. The way that the underlying Prometheus Client for Python works is quite weird. It errors out if a metric is duplicated, but there's no way to check if a new metric will create that error or not. And a try block would have to be very generic catching all ValueErrors. I'm still not sure what's the best way to handle this.

@tiangolo tiangolo marked this pull request as draft June 17, 2022 14:59
@ChuckHend
Copy link

I'd love to see this go out!

@trallnag trallnag marked this pull request as ready for review February 22, 2023 16:23
@trallnag trallnag changed the title ✨ Allow passing a custom registry to be used instead of using the default one feat: Allow passing a custom registry to be used instead of using the default one Feb 22, 2023
@trallnag trallnag merged commit b6ac364 into trallnag:master Feb 22, 2023
@trallnag
Copy link
Owner

Thank you, @tiangolo. Sorry for ignoring your work for a long time

@trallnag
Copy link
Owner

trallnag commented Feb 26, 2023

Hmm I just did a poetry update and suddenly test_expose_defaults() started to fail.

info = <prometheus_fastapi_instrumentator.metrics.Info object at 0x7f232b7433d0>

    def instrumentation(info: Info) -> None:
>       TOTAL.labels(info.method, info.modified_status, info.modified_handler).inc()
E       NameError: free variable 'TOTAL' referenced before assignment in enclosing scope

src/prometheus_fastapi_instrumentator/metrics.py:628: NameError

Before that it worked fine. It tried to debug it. The Prometheus client lib is complaining about duplicate metrics as excepted.

Duplicated timeseries in CollectorRegistry: {'http_requests_total', 'http_requests_created', 'http_requests'}

Problems start when updating starlette and fastapi

  • Updating starlette (0.22.0 -> 0.25.0)
  • Updating fastapi (0.88.0 -> 0.92.0)

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 this pull request may close these issues.

None yet

3 participants