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

Set default labels on a single metric #598

Open
bienzaaron opened this issue Nov 9, 2023 · 1 comment · May be fixed by #600
Open

Set default labels on a single metric #598

bienzaaron opened this issue Nov 9, 2023 · 1 comment · May be fixed by #600

Comments

@bienzaaron
Copy link

I would like to propose an option to be added to each metric type, which would allow specifying default label values for that metric only. Those labels would then be applied to each metric value (unless the value is overridden when recorded, similar to how default labels already work at the client level in prom-client).

It would look something like this:

const counter = new client.Counter({
  name: 'metric_name',
  help: 'metric_help',
  labelNames: ['my_label'],
  defaultLabels: {
    my_label: 'my_value'
  }
});

counter.inc(); // recorded with my_label: my_value
counter.inc({ my_label: 'my_other_value' }); // recorded with my_label: my_other_value

If this is a valid use case / not already possible, I would love to contribute.

More use case details:
My team uses prom-client to expose metrics which are scraped by prometheus and ultimately pushed to newrelic via a prometheus remote write integration.

We have an issue occasionally where if a metric is created that does not follow the naming convention expected by newrelic, newrelic interprets the metric as an inappropriate type (most often, counters are interpreted as gauges). I'd like to use this API to add the newrelic_metric_type label in a universal way to prevent this.

@zbjornson
Copy link
Collaborator

It looks like 9e49ee6 started to pave the way for this:

class Counter extends Metric {
constructor(config) {
super(config);
this.type = 'counter';
this.defaultLabels = {};

Happy to review a PR if you want to wire up incWithoutExemplar() to use defaultLabels.

@bienzaaron bienzaaron linked a pull request Nov 26, 2023 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants