prometheus-fastapi-instrumentator icon indicating copy to clipboard operation
prometheus-fastapi-instrumentator copied to clipboard

Unexpected print in Middleware

Open DenysMoskalenko opened this issue 2 years ago • 1 comments

Hello) I found the print in library code: https://github.com/trallnag/prometheus-fastapi-instrumentator/blob/673b922e97a4e943a0e4d23db7767015e4c751dd/prometheus_fastapi_instrumentator/middleware.py#L80 Can you pls remove it or allow some customization of this behavior?)

DenysMoskalenko avatar Jun 13 '22 13:06 DenysMoskalenko

I noticed this as well, and would like to second its removal. 😅

In the meantime for anyone else whose logs are being cluttered up by this, you can silence it by applying this patch somewhere before the instrumentor is actually called:

    import prometheus_fastapi_instrumentator as pfi
    import prometheus_fastapi_instrumentator.middleware
    

    # Patch the Prometheus instrumentor to stop
    # it from `print()`ing to stdout
    pfi.middleware.print = lambda *_, **__: None

It's hacky, but it works and is safe.

the-wondersmith avatar Jun 15 '22 13:06 the-wondersmith

Fixed in #157. Will be released soon(tm)

trallnag avatar Aug 22 '22 16:08 trallnag