Hi,
I've been using github.com/prometheus/client_golang/prometheus/promhttp
<https://pkg.go.dev/github.com/prometheus/client_golang/prometheus/promhttp> to
export API metrics and now I'd like to extend these with per-request
dynamic label values.
For example, let's imagine that for each incoming HTTP request, I want to
add and fill a `user_group` label with value `admin` or `guest` depending
on a few validations that happen at run time while processing the request.
Now let's imagine the API has received 2 requests so far, one from an admin
and another from a guest.
Instead of something like this:
myapp_http_requests_total{code="200",method="get"} 2
I want this:
myapp_http_requests_total{code="200",method="get",user_group="admin"} 1
myapp_http_requests_total{code="200",method="get",user_group="guest"} 1
Right now I don't see any way of achieving this. I know we can add const
labels, but I don't see a way to inject and fill labels depending on the
HTTP request context. The only option I see is cloning the promhttp package
code and modify it to add these new labels and fill them at run time by
reading their value from the HTTP request context (such as here
<https://github.com/prometheus/client_golang/blob/8184d76b3b0bd3b01ed903690431ccb6826bf3e0/prometheus/promhttp/instrument_server.go#L102>
).
I wonder if anyone is aware of a better solution?
--
You received this message because you are subscribed to the Google Groups
"Prometheus Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/prometheus-users/5906bb11-bc17-4c0c-a60a-83121fb8c05fn%40googlegroups.com.