GitHub

API reference for Metric.

A metric taking In updates and holding a State. Make one with metric.counter, gauge, frequency, histogram, summary or timer.

Attributes

AttributeTypeDescription
typeFinal[MetricType] = kind
idFinal = id
descriptionFinal = description
attributesFinal = attributes

Functions

__init__

__init__(kind, id, description, attributes) -> None
ParameterTypeDescription
kindMetricType
idstr
descriptionstr | None
attributesMapping[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 = attributes

unsafe_value

unsafe_value(context) -> State_co

The state of the series context selects.

ParameterTypeDescription
contextContext

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) -> None

Update the series context selects.

ParameterTypeDescription
inputIn_contra
contextContext
@abstractmethod
def unsafe_update(self, input: In_contra, context: Context) -> None:
    """Update the series ``context`` selects."""

unsafe_modify

unsafe_modify(input, context) -> None

Modify the series context selects (a gauge adds input; the other kinds update).

ParameterTypeDescription
inputIn_contra
contextContext
@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) -> None

Drop the series context selects from its registry.

ParameterTypeDescription
contextContext
@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.

ParameterTypeDescription
inputIn_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.

ParameterTypeDescription
inputIn_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).

ParameterTypeDescription
fCallable[[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.

ParameterTypeDescription
inputIn_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.

ParameterTypeDescription
attributesAttributes

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
ParameterTypeDescription
fCallable[[Self], B]

Returns B

def pipe[B](self, f: Callable[[Self], B], /) -> B:
    return f(self)