siimon/prom-client

Exemplar values in counter metrics are always 1

psimk opened this issue · 0 comments

Problem

It is annoying to use exemplars in cases where you are using a counter metric that you just call inc on.

Example

I have a project with a http_request_total metric that I call inc on every time a request comes in. Because the exemplar value is also set to 1, it makes for an awkward experience viewing these exemplars in something like Grafana:

image

You'd have to open the image and zoom to the bottom of the graph to see the yellow rhombus, which represent exemplars in Grafana.


Proposal

We should allow users to configure their metrics to allow placing the computed counter value as the exemplar value, instead of the value passed to inc.

Example

Given code such as:

const counter = new Counter({ useCounterValueAsExemplar: true })
counter.inc({ exemplarLabels: { traceId }})
counter.inc({ exemplarLabels: { traceId }})

Would generate plain text metrics such as:

counter{} 2 # { traceId="..." } 2 <timestamp>

Without the useCounterValueAsExemplar: true configuration field, it would set it to the value passed to inc (default is 1). Which is the current behavior.

counter{} 2 # { traceId="..." } 1<timestamp>

I have looked at other prometheus clients (like https://github.com/prometheus/client_golang), and they do not implement anything similar. I am a bit confused about that as this behavior makes exemplars less useful for cases where you are just incrementing the counter with a static value.

Via a configurable metric flag, we should