You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a similar setup to what is described here. The only difference is that I have nginx in front talking to gunicorn over sockets, but I don't think that matters as far as I can tell.
I wasn't able to use this code:
# Using multiprocess collector for registrydefmake_metrics_app():
registry=CollectorRegistry()
multiprocess.MultiProcessCollector(registry)
returnmake_asgi_app(registry=registry)
metrics_app=make_metrics_app()
app.mount("/metrics", metrics_app)
It results in a page that gets a 307, so I implemented this:
My in progress counter always remains at zero, but I'm hoping that's because requests finish faster than I can see them. The histogram, however, never shows up - I see no record of it in my PROMETHEUS_MULTIPROC_DIR and it's never rendered in the output. Any ideas for what I could troubleshoot?
Some extra context: most all of these get called in async middleware. Here's a rather benign one:
asyncdefadd_request_id(
request: Request, call_next: Callable[[Request], Awaitable[Response]]
) ->Response:
ifnotis_prometheus_endpoint(request):
REQUESTS_IN_PROGRESS_TOTAL.inc()
request.state.request_id=correlation_id.get()
start_time=time.time()
response=awaitcall_next(request)
ifnotis_prometheus_endpoint(request):
time_taken=time.time() -start_time# we replace UUIDs with <uuid> so that we flatten the curve of cardinality with unique URLs across all urlsREQUEST_TIME_SECONDS.labels(
method=request.method,
url_rule=replace_uuids(request.url.path),
status_code=response.status_code,
).observe(time_taken)
REQUESTS_IN_PROGRESS_TOTAL.dec()
returnresponse
I have similar issues, with some histogram metrics specifically not showing up, only in certain contexts ( threaded celery workers e.g. ). Working on having reproducible code.
You are probably not setting PROMETHEUS_MULTIPROC_DIR before importing prometheus_client. Note that even a transitive import of prometheus_client from some downstream dependency can trigger this issue.
Activity
matt0x6F commentedon Feb 12, 2025
Some extra context: most all of these get called in async middleware. Here's a rather benign one:
csmarchbanks commentedon Feb 28, 2025
Hmm, I am not seeing anything obvious, does REQUESTS_IN_PROGRESS show up in the multiproc dir?
gg-mmill commentedon Jun 4, 2025
I have similar issues, with some histogram metrics specifically not showing up, only in certain contexts ( threaded celery workers e.g. ). Working on having reproducible code.
danobi commentedon Jun 23, 2025
You are probably not setting
PROMETHEUS_MULTIPROC_DIRbefore importingprometheus_client. Note that even a transitive import ofprometheus_clientfrom some downstream dependency can trigger this issue.gg-mmill commentedon Aug 28, 2025
Does adding a
labelnamesargument (with a dummy label name) in REQUESTS_IN_PROGRESS_TOTAL solves the issue ?I had similar troubles, and this solved it for me (see #1123)