Skip to content

Async CustomCollector #1069

Open
Open

Description

@takeda

So I need to obtain some metrics from a database and I'm planning to create a custom collector as described here: http://prometheus.github.io/client_python/collector/custom/

I use asyncpg to connect to PostgreSQL. My problem though is that asyncpg query needs to be called from an async function and collect() is synchronous.

Is there an async equivalent? It looks like the client supports being used from ASGI.

Activity

  1. csmarchbanks commented on Nov 19, 2024

    @csmarchbanks
    Member

    Not today, but adding async support for custom collectors would be a reasonable feature to add. I doubt I will have time to add it soon but would be happy to take a contribution.

  2. chamini2 commented on May 17, 2025

    @chamini2

    How can we help get asyncio features out? Are you open to accept PRs that maybe don't affect existing codebase but give options to users to use an async solution? Or do you prefer this happens in a separate module entirely?

  3. takeda commented on Aug 20, 2025

    @takeda
    ContributorAuthor

    @chamini2 I think you can make PR. Probably there would be another method like collect that calls async code. I'm not exactly sure how it could be done, as normally all the calls that leading to the collect() would have to be converted to async as well...

    I also found this thread in async add-on to this library: hynek/prometheus-async#13

    But I guess it might be implemented here.

    I managed to run async code in the regular collect() but it feels extremely hacky and I hate that code. I wish the library would natively support it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions