starlette_exporter icon indicating copy to clipboard operation
starlette_exporter copied to clipboard

Cannot use `await request.body()` in label

Open TheCodeWrangler opened this issue 5 months ago • 2 comments

I would like to have labels applied which will be populated from the content of the request body.

tried something like:

async def get_label_value(request:Request):
    return request.json().get("label", None)
    
app.add_middleware(
        PrometheusMiddleware,
        labels={"custom_label": get_label_value}
    )
app.add_route("/metrics", handle_metrics)

But upon a request the call hangs.

I know this is a known issue with starlette_exporter https://github.com/encode/starlette/issues/847

BUT if there is a way for me to include labels based on some values in the request body I would love to know!

TheCodeWrangler avatar Sep 12 '24 13:09 TheCodeWrangler