A metric taking In updates and holding a State. Make one
with metric.counter, gauge, frequency, histogram,
summary or timer.
Attributes#
| Attribute | Type | Description |
|---|---|---|
type | Final[MetricType] = kind | |
id | Final = id | |
description | Final = description | |
attributes | Final = attributes |
Functions#
__init__#
__init__(kind, id, description, attributes) -> None| Parameter | Type | Description |
|---|---|---|
kind | MetricType | |
id | str | |
description | str | None | |
attributes | Mapping[str, str] | None |
def __init__(
self,
kind: MetricType,
id: str,
description: str | None,
attributes: Mapping[str, str] | None,
) -> None:
self.type: Final[MetricType] = kind
self.id: Final = id
self.description: Final = description
self.attributes: Final = attributesunsafe_value#
unsafe_value(context) -> State_coThe state of the series context selects.
| Parameter | Type | Description |
|---|---|---|
context | Context |
Returns State_co
@abstractmethod
def unsafe_value(self, context: Context) -> State_co:
"""The state of the series ``context`` selects."""unsafe_update#
unsafe_update(input, context) -> NoneUpdate the series context selects.
| Parameter | Type | Description |
|---|---|---|
input | In_contra | |
context | Context |
@abstractmethod
def unsafe_update(self, input: In_contra, context: Context) -> None:
"""Update the series ``context`` selects."""unsafe_modify#
unsafe_modify(input, context) -> NoneModify the series context selects (a gauge adds input;
the other kinds update).
| Parameter | Type | Description |
|---|---|---|
input | In_contra | |
context | Context |
@abstractmethod
def unsafe_modify(self, input: In_contra, context: Context) -> None:
"""Modify the series ``context`` selects (a gauge adds ``input``;
the other kinds update)."""unsafe_remove#
unsafe_remove(context) -> NoneDrop the series context selects from its registry.
| Parameter | Type | Description |
|---|---|---|
context | Context |
@abstractmethod
def unsafe_remove(self, context: Context) -> None:
"""Drop the series ``context`` selects from its registry."""value#
value() -> Effect[State_co]The state of this metric's series in the current registry.
Returns Effect[State_co]
def value(self) -> Effect[State_co]:
"""The state of this metric's series in the current registry."""
return WithContext(self.unsafe_value)update#
update(input) -> Effect[None]Update the series: a counter adds, a gauge sets, a frequency counts the word, a histogram or summary records the value.
| Parameter | Type | Description |
|---|---|---|
input | In_contra |
Returns Effect[None]
def update(self, input: In_contra) -> Effect[None]:
"""Update the series: a counter adds, a gauge sets, a frequency
counts the word, a histogram or summary records the value."""
return WithContext(lambda context: self.unsafe_update(input, context))modify#
modify(input) -> Effect[None]Modify the series: a gauge adds input to its value; the
other kinds update.
| Parameter | Type | Description |
|---|---|---|
input | In_contra |
Returns Effect[None]
def modify(self, input: In_contra) -> Effect[None]:
"""Modify the series: a gauge adds ``input`` to its value; the
other kinds update."""
return WithContext(lambda context: self.unsafe_modify(input, context))remove#
remove() -> Effect[None]Drop the series for the current attributes; the next update starts it afresh.
Returns Effect[None]
def remove(self) -> Effect[None]:
"""Drop the series for the current attributes; the next update
starts it afresh."""
return WithContext(self.unsafe_remove)map_input#
map_input(f) -> Metric[In2, State_co]The same series, updated with f(input).
| Parameter | Type | Description |
|---|---|---|
f | Callable[[In2], In_contra] |
Returns Metric[In2, State_co]
def map_input[In2](self, f: Callable[[In2], In_contra]) -> Metric[In2, State_co]:
"""The same series, updated with ``f(input)``."""
return _Transform(self, lambda input, _: f(input), _same)with_constant_input#
with_constant_input(input) -> Metric[object, State_co]The same series, updated with input whatever it is given.
| Parameter | Type | Description |
|---|---|---|
input | In_contra |
Returns Metric[object, State_co]
def with_constant_input(self, input: In_contra) -> Metric[object, State_co]:
"""The same series, updated with ``input`` whatever it is given."""
return _Transform(self, lambda _, __: input, _same)with_attributes#
with_attributes(attributes) -> Metric[In_contra, State_co]The series with attributes added; they win over the
contextual attributes and the metric's own.
| Parameter | Type | Description |
|---|---|---|
attributes | Attributes |
Returns Metric[In_contra, State_co]
def with_attributes(self, attributes: Attributes) -> Metric[In_contra, State_co]:
"""The series with ``attributes`` added; they win over the
contextual attributes and the metric's own."""
return _Transform(self, _pass_input, _adding(attributes))pipe#
pipe(f) -> B| Parameter | Type | Description |
|---|---|---|
f | Callable[[Self], B] |
Returns B
def pipe[B](self, f: Callable[[Self], B], /) -> B:
return f(self)