Comments (7)
Are you using async? if so, have you tried this? link
from prometheus-fastapi-instrumentator.
but works when the instrumentator is initialized outside from lifespan event handler.
instrumentator = Instrumentator().instrument(app)
@app.on_event("startup")
async def startup_event() -> None:
instrumentator.add(custom_metric()).expose(app)
from prometheus-fastapi-instrumentator.
Hi, I'm seeing the exact same issue, while using async like suggested in the link.
Getting this issue while using version 5.8.2. Rolling back to 5.7.1 fixes this.
from prometheus-fastapi-instrumentator.
Same:
Traceback (most recent call last):
File "/home/bral/PycharmProjects/elasticsearch_dbapi/main.py", line 13, in <module>
uvicorn.run(
File "/home/bral/PycharmProjects/elasticsearch_dbapi/venv/lib/python3.9/site-packages/uvicorn/main.py", line 575, in run
server.run()
File "/home/bral/PycharmProjects/elasticsearch_dbapi/venv/lib/python3.9/site-packages/uvicorn/server.py", line 60, in run
return asyncio.run(self.serve(sockets=sockets))
File "/usr/lib/python3.9/asyncio/runners.py", line 44, in run
return loop.run_until_complete(main)
File "uvloop/loop.pyx", line 1501, in uvloop.loop.Loop.run_until_complete
File "/home/bral/PycharmProjects/elasticsearch_dbapi/venv/lib/python3.9/site-packages/uvicorn/server.py", line 67, in serve
config.load()
File "/home/bral/PycharmProjects/elasticsearch_dbapi/venv/lib/python3.9/site-packages/uvicorn/config.py", line 479, in load
self.loaded_app = import_from_string(self.app)
File "/home/bral/PycharmProjects/elasticsearch_dbapi/venv/lib/python3.9/site-packages/uvicorn/importer.py", line 21, in import_from_string
module = importlib.import_module(module_str)
File "/usr/lib/python3.9/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 790, in exec_module
File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
File "/home/bral/PycharmProjects/elasticsearch_dbapi/main.py", line 7, in <module>
app = get_application()
File "/home/bral/PycharmProjects/elasticsearch_dbapi/app/__init__.py", line 98, in get_application
Instrumentator().instrument(_app).expose(_app)
File "/home/bral/PycharmProjects/elasticsearch_dbapi/venv/lib/python3.9/site-packages/prometheus_fastapi_instrumentator/instrumentation.py", line 122, in instrument
app.add_middleware(
File "/home/bral/PycharmProjects/elasticsearch_dbapi/venv/lib/python3.9/site-packages/starlette/applications.py", line 169, in add_middleware
self.middleware_stack = self.build_middleware_stack()
File "/home/bral/PycharmProjects/elasticsearch_dbapi/venv/lib/python3.9/site-packages/fastapi/applications.py", line 194, in build_middleware_stack
app = cls(app=app, **options)
File "/home/bral/PycharmProjects/elasticsearch_dbapi/venv/lib/python3.9/site-packages/prometheus_fastapi_instrumentator/middleware.py", line 52, in __init__
self.instrumentations = instrumentations or [metrics.default()]
File "/home/bral/PycharmProjects/elasticsearch_dbapi/venv/lib/python3.9/site-packages/prometheus_fastapi_instrumentator/metrics.py", line 544, in default
TOTAL = Counter(
File "/home/bral/PycharmProjects/elasticsearch_dbapi/venv/lib/python3.9/site-packages/prometheus_client/metrics.py", line 143, in __init__
registry.register(self)
File "/home/bral/PycharmProjects/elasticsearch_dbapi/venv/lib/python3.9/site-packages/prometheus_client/registry.py", line 43, in register
raise ValueError(
ValueError: Duplicated timeseries in CollectorRegistry: {'http_requests', 'http_requests_created', 'http_requests_total'}
Process finished with exit code 1
from prometheus-fastapi-instrumentator.
Are you using async? if so, have you tried this? link
Yes, this solve my issue. Thanks!
from prometheus-fastapi-instrumentator.
Are you using async? if so, have you tried this? link
Doesn't work for starlette>=0.24.0
from prometheus-fastapi-instrumentator.
Closing at fixed in newer versions released this year and documentation mentions different ways to startup.
If someone reading this still has issues please, feel free to comment and consider opening a new issue.
from prometheus-fastapi-instrumentator.
Related Issues (20)
- the middleware can't be installed for the actual FastAPI version HOT 23
- anyone know of any promql examples built off default metrics?
- broken link to documentation
- Test `test_expose_defaults` fails due to `NameError` after updating HOT 3
- Cannot See Multiprocess metric under /metric page while suing multiple workers HOT 1
- Multi process mode does not work as expected
- _created metrics are not created in multi-process mode HOT 2
- Large content in info response impacts performance a lot HOT 1
- Response body `info.response.body` is still empty
- Multiple metrics endpoints when using `expose` + multliple workers HOT 5
- Adding metrics from routers HOT 2
- Running custom metrics in background HOT 4
- Inprogress requests causes duplicated prometheus timeseries error
- labels on highr bucket default metrics
- Having metrics values even with no endpoints activity HOT 1
- Not full metrics list HOT 1
- FastAPI app with many routers HOT 3
- Instrumentator middleware includes BackgroundTask duration in http request latency metrics
- How to properly initialize modified_status when throwing exception
- Default metrics are gone when adding a custom instrumentation HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from prometheus-fastapi-instrumentator.