Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exemplar values in counter metrics are always 1 #621

Open
psimk opened this issue Mar 26, 2024 · 0 comments
Open

Exemplar values in counter metrics are always 1 #621

psimk opened this issue Mar 26, 2024 · 0 comments

Comments

@psimk
Copy link
Contributor

psimk commented Mar 26, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant