yr.UInt64Counter.add_labels

yr.UInt64Counter.add_labels#

UInt64Counter.add_labels(labels: dict) None[source]#

add lable for metrics data.

Parameters:

labels (dict) – A dictionary of labels where both keys and values must be strings.

Raises:

ValueError – If the label is empty or does not meet the data type requirements.

Example

>>> import yr
>>>
>>> config = yr.Config(enable_metrics=True)
>>> yr.init(config)
>>>
>>> @yr.instance
>>> class Actor:
...     def __init__(self):
...         labels = {"key1": "value1", "key2": "value2"}
...         self.data = yr.UInt64Counter(
...             name="test",
...             description="",
...             unit="ms",
...             labels=labels
...         )
...         self.data.add_labels({"key3": "value3"})
...         print("Actor init done")
...
...     def run(self):
...         self.data.set(5)
...         self.data.add_labels({"phase": "run"})
...         msg = (
...             f"Actor run: {self.data._UInt64Counter__uint_counter_labels},
...             f"value: {self.data.get_value()}"
...         )
...         print(msg)
...         return msg
>>>
>>> actor1 = Actor.options(name="actor").invoke()
>>> print(yr.get(actor1.run.invoke()))