question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Initializing a metric with a tuple for labels leads to incorrect label count

See original GitHub issue
g = prometheus_client.Gauge(
            "my_super_special_metric",
           "This is  ametric", 
           ("label"))
g.labels({"label" : "somevalue"}).set(1)

Leads to “incorrect label names”. Changing it to:

g = prometheus_client.Gauge(
            "my_super_special_metric",
           "This is  ametric", 
           ["label"])
g.labels({"label" : "somevalue"}).set(1)

works normally.

Since both are iterable types, it would be idiomatic python to ensure that any non-string sequence type supplied for the labels be treated as a list of labels.

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Reactions:2
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

27reactions
Sispheorcommented, Dec 4, 2017

It’s ok, here is the way to go for thos who pass here

# declaration of the gauge
my_val= Gauge('val_name', 'My val description, ["product_name", "server_name"])

# usage
my_val.labels(product_name=product_name, server_name=server_name).set(val)

2reactions
brian-brazilcommented, Aug 25, 2015

(“label”)

This isn’t a tuple, it’s a string in parens. (“label”, ) is what you want.

Read more comments on GitHub >

github_iconTop Results From Across the Web

In the context o f prometheus instrumentation, should I use all ...
No, you have to give a value for each of the labels. ... in labels raise ValueError('Incorrect label count') ValueError: Incorrect label ......
Read more >
How to set multiple label values with using tuple or list to ...
File "/Library/Python/2.7/site-packages/prometheus_client/core.py", line 516, in labels raise ValueError('Incorrect label count')
Read more >
Collection of alerting rules - Awesome Prometheus alerts
1. Windows Server collector Error. Collector {{ $labels. · 2. Windows Server service Status. Windows Service state is not OK [copy] · 3....
Read more >
Usage examples - Python package - CatBoost
Get the identifier of the iteration with the best result. Return the iteration with the best value of the evaluation metric on the...
Read more >
Trainer - Hugging Face
from torch import nn from transformers import Trainer class CustomTrainer(Trainer): def compute_loss(self, model, inputs, return_outputs=False): labels ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found