Skip to content

Metrics

provide.foundation.metrics

TODO: Add module docstring.

Classes

Functions

counter

counter(
    name: str, description: str = "", unit: str = ""
) -> SimpleCounter

Create a counter metric.

Parameters:

Name Type Description Default
name str

Name of the counter

required
description str

Description of what this counter measures

''
unit str

Unit of measurement

''

Returns:

Type Description
SimpleCounter

Counter instance

Source code in provide/foundation/metrics/__init__.py
def counter(name: str, description: str = "", unit: str = "") -> SimpleCounter:
    """Create a counter metric.

    Args:
        name: Name of the counter
        description: Description of what this counter measures
        unit: Unit of measurement

    Returns:
        Counter instance

    """
    if _HAS_OTEL_METRICS and _meter:
        try:
            otel_counter = _meter.create_counter(name=name, description=description, unit=unit)
            return SimpleCounter(name, otel_counter=otel_counter)
        except Exception:
            # Broad catch intentional: OTEL metrics are optional, gracefully fall back to simple counter
            pass

    return SimpleCounter(name)

gauge

gauge(
    name: str, description: str = "", unit: str = ""
) -> SimpleGauge

Create a gauge metric.

Parameters:

Name Type Description Default
name str

Name of the gauge

required
description str

Description of what this gauge measures

''
unit str

Unit of measurement

''

Returns:

Type Description
SimpleGauge

Gauge instance

Source code in provide/foundation/metrics/__init__.py
def gauge(name: str, description: str = "", unit: str = "") -> SimpleGauge:
    """Create a gauge metric.

    Args:
        name: Name of the gauge
        description: Description of what this gauge measures
        unit: Unit of measurement

    Returns:
        Gauge instance

    """
    if _HAS_OTEL_METRICS and _meter:
        try:
            otel_gauge = _meter.create_up_down_counter(name=name, description=description, unit=unit)
            return SimpleGauge(name, otel_gauge=otel_gauge)
        except Exception:
            # Broad catch intentional: OTEL metrics are optional, gracefully fall back to simple gauge
            pass

    return SimpleGauge(name)

histogram

histogram(
    name: str, description: str = "", unit: str = ""
) -> SimpleHistogram

Create a histogram metric.

Parameters:

Name Type Description Default
name str

Name of the histogram

required
description str

Description of what this histogram measures

''
unit str

Unit of measurement

''

Returns:

Type Description
SimpleHistogram

Histogram instance

Source code in provide/foundation/metrics/__init__.py
def histogram(name: str, description: str = "", unit: str = "") -> SimpleHistogram:
    """Create a histogram metric.

    Args:
        name: Name of the histogram
        description: Description of what this histogram measures
        unit: Unit of measurement

    Returns:
        Histogram instance

    """
    if _HAS_OTEL_METRICS and _meter:
        try:
            otel_histogram = _meter.create_histogram(name=name, description=description, unit=unit)
            return SimpleHistogram(name, otel_histogram=otel_histogram)
        except Exception:
            # Broad catch intentional: OTEL metrics are optional, gracefully fall back to simple histogram
            pass

    return SimpleHistogram(name)