GithubHelp home page GithubHelp logo

Comments (7)

eneiva avatar eneiva commented on May 23, 2024 2

Are you using async? if so, have you tried this? link

from prometheus-fastapi-instrumentator.

zoola969 avatar zoola969 commented on May 23, 2024 1

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.

Eytan-S avatar Eytan-S commented on May 23, 2024

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.

bralbral avatar bralbral commented on May 23, 2024

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.

bralbral avatar bralbral commented on May 23, 2024

Are you using async? if so, have you tried this? link

Yes, this solve my issue. Thanks!

from prometheus-fastapi-instrumentator.

zoola969 avatar zoola969 commented on May 23, 2024

Are you using async? if so, have you tried this? link

Doesn't work for starlette>=0.24.0

from prometheus-fastapi-instrumentator.

trallnag avatar trallnag commented on May 23, 2024

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)

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.