Module glean.metrics

This module contains all of the metric types.

Sub-modules

glean.metrics.datetime
glean.metrics.event
glean.metrics.labeled
glean.metrics.object
glean.metrics.ping
glean.metrics.string
glean.metrics.timespan
glean.metrics.timing_distribution
glean.metrics.url
glean.metrics.uuid

Classes

class AttributionMetrics (*,
source: typing.Optional[str] = <object object>,
medium: typing.Optional[str] = <object object>,
campaign: typing.Optional[str] = <object object>,
term: typing.Optional[str] = <object object>,
content: typing.Optional[str] = <object object>)
Expand source code
@dataclass
class AttributionMetrics:
    def __init__(self, *, source:typing.Optional[str] = _DEFAULT, medium:typing.Optional[str] = _DEFAULT, campaign:typing.Optional[str] = _DEFAULT, term:typing.Optional[str] = _DEFAULT, content:typing.Optional[str] = _DEFAULT):
        if source is _DEFAULT:
            self.source = None
        else:
            self.source = source
        if medium is _DEFAULT:
            self.medium = None
        else:
            self.medium = medium
        if campaign is _DEFAULT:
            self.campaign = None
        else:
            self.campaign = campaign
        if term is _DEFAULT:
            self.term = None
        else:
            self.term = term
        if content is _DEFAULT:
            self.content = None
        else:
            self.content = content
        
        

    
    def __str__(self):
        return "AttributionMetrics(source={}, medium={}, campaign={}, term={}, content={})".format(self.source, self.medium, self.campaign, self.term, self.content)
    def __eq__(self, other):
        if self.source != other.source:
            return False
        if self.medium != other.medium:
            return False
        if self.campaign != other.campaign:
            return False
        if self.term != other.term:
            return False
        if self.content != other.content:
            return False
        return True

AttributionMetrics(*, source: 'typing.Optional[str]' = , medium: 'typing.Optional[str]' = , campaign: 'typing.Optional[str]' = , term: 'typing.Optional[str]' = , content: 'typing.Optional[str]' = )

class BooleanMetricType (meta: CommonMetricData)
Expand source code
class BooleanMetric(BooleanMetricProtocol):
    
    _handle: ctypes.c_uint64
    def __init__(self, meta: CommonMetricData):
        
        _UniffiFfiConverterTypeCommonMetricData.check_lower(meta)
        _uniffi_lowered_args = (
            _UniffiFfiConverterTypeCommonMetricData.lower(meta),
        )
        _uniffi_lift_return = _UniffiFfiConverterTypeBooleanMetric.lift
        _uniffi_error_converter = None
        _uniffi_ffi_result = _uniffi_rust_call_with_error(
            _uniffi_error_converter,
            _UniffiLib.uniffi_glean_core_fn_constructor_booleanmetric_new,
            *_uniffi_lowered_args,
        )
        self._handle = _uniffi_ffi_result

    def __del__(self):
        # In case of partial initialization of instances.
        handle = getattr(self, "_handle", None)
        if handle is not None:
            _uniffi_rust_call(_UniffiLib.uniffi_glean_core_fn_free_booleanmetric, handle)

    def _uniffi_clone_handle(self):
        return _uniffi_rust_call(_UniffiLib.uniffi_glean_core_fn_clone_booleanmetric, self._handle)

    # Used by alternative constructors or any methods which return this type.
    @classmethod
    def _uniffi_make_instance(cls, handle):
        # Lightly yucky way to bypass the usual __init__ logic
        # and just create a new instance with the required handle.
        inst = cls.__new__(cls)
        inst._handle = handle
        return inst
    def set(self, value: bool) -> None:
        
        _UniffiFfiConverterBoolean.check_lower(value)
        _uniffi_lowered_args = (
            self._uniffi_clone_handle(),
            _UniffiFfiConverterBoolean.lower(value),
        )
        _uniffi_lift_return = lambda val: None
        _uniffi_error_converter = None
        _uniffi_ffi_result = _uniffi_rust_call_with_error(
            _uniffi_error_converter,
            _UniffiLib.uniffi_glean_core_fn_method_booleanmetric_set,
            *_uniffi_lowered_args,
        )
        return _uniffi_lift_return(_uniffi_ffi_result)
    def test_get_num_recorded_errors(self, error: ErrorType) -> int:
        
        _UniffiFfiConverterTypeErrorType.check_lower(error)
        _uniffi_lowered_args = (
            self._uniffi_clone_handle(),
            _UniffiFfiConverterTypeErrorType.lower(error),
        )
        _uniffi_lift_return = _UniffiFfiConverterInt32.lift
        _uniffi_error_converter = None
        _uniffi_ffi_result = _uniffi_rust_call_with_error(
            _uniffi_error_converter,
            _UniffiLib.uniffi_glean_core_fn_method_booleanmetric_test_get_num_recorded_errors,
            *_uniffi_lowered_args,
        )
        return _uniffi_lift_return(_uniffi_ffi_result)
    def test_get_value(self, ping_name: typing.Union[object, typing.Optional[str]] = _DEFAULT) -> typing.Optional[bool]:
        
        if ping_name is _DEFAULT:
            ping_name = None
        _UniffiFfiConverterOptionalString.check_lower(ping_name)
        _uniffi_lowered_args = (
            self._uniffi_clone_handle(),
            _UniffiFfiConverterOptionalString.lower(ping_name),
        )
        _uniffi_lift_return = _UniffiFfiConverterOptionalBoolean.lift
        _uniffi_error_converter = None
        _uniffi_ffi_result = _uniffi_rust_call_with_error(
            _uniffi_error_converter,
            _UniffiLib.uniffi_glean_core_fn_method_booleanmetric_test_get_value,
            *_uniffi_lowered_args,
        )
        return _uniffi_lift_return(_uniffi_ffi_result)

Base class for protocol classes.

Protocol classes are defined as::

class Proto(Protocol):
    def meth(self) -> int:
        ...

Such classes are primarily used with static type checkers that recognize structural subtyping (static duck-typing).

For example::

class C:
    def meth(self) -> int:
        return 0

def func(x: Proto) -> int:
    return x.meth()

func(C())  # Passes static type check

See PEP 544 for details. Protocol classes decorated with @typing.runtime_checkable act as simple-minded runtime protocols that check only the presence of given attributes, ignoring their type signatures. Protocol classes can be generic, they are defined as::

class GenProto[T](Protocol):
    def meth(self) -> T:
        ...

Ancestors

  • glean._uniffi.glean.BooleanMetricProtocol
  • typing.Protocol
  • typing.Generic

Methods

def set(self, value: bool) ‑> None
Expand source code
def set(self, value: bool) -> None:
    
    _UniffiFfiConverterBoolean.check_lower(value)
    _uniffi_lowered_args = (
        self._uniffi_clone_handle(),
        _UniffiFfiConverterBoolean.lower(value),
    )
    _uniffi_lift_return = lambda val: None
    _uniffi_error_converter = None
    _uniffi_ffi_result = _uniffi_rust_call_with_error(
        _uniffi_error_converter,
        _UniffiLib.uniffi_glean_core_fn_method_booleanmetric_set,
        *_uniffi_lowered_args,
    )
    return _uniffi_lift_return(_uniffi_ffi_result)
def test_get_num_recorded_errors(self, error: ErrorType) ‑> int
Expand source code
def test_get_num_recorded_errors(self, error: ErrorType) -> int:
    
    _UniffiFfiConverterTypeErrorType.check_lower(error)
    _uniffi_lowered_args = (
        self._uniffi_clone_handle(),
        _UniffiFfiConverterTypeErrorType.lower(error),
    )
    _uniffi_lift_return = _UniffiFfiConverterInt32.lift
    _uniffi_error_converter = None
    _uniffi_ffi_result = _uniffi_rust_call_with_error(
        _uniffi_error_converter,
        _UniffiLib.uniffi_glean_core_fn_method_booleanmetric_test_get_num_recorded_errors,
        *_uniffi_lowered_args,
    )
    return _uniffi_lift_return(_uniffi_ffi_result)
def test_get_value(self,
ping_name: typing.Union[glean.metrics.object, typing.Optional[str]] = <object object>) ‑> bool | None
Expand source code
def test_get_value(self, ping_name: typing.Union[object, typing.Optional[str]] = _DEFAULT) -> typing.Optional[bool]:
    
    if ping_name is _DEFAULT:
        ping_name = None
    _UniffiFfiConverterOptionalString.check_lower(ping_name)
    _uniffi_lowered_args = (
        self._uniffi_clone_handle(),
        _UniffiFfiConverterOptionalString.lower(ping_name),
    )
    _uniffi_lift_return = _UniffiFfiConverterOptionalBoolean.lift
    _uniffi_error_converter = None
    _uniffi_ffi_result = _uniffi_rust_call_with_error(
        _uniffi_error_converter,
        _UniffiLib.uniffi_glean_core_fn_method_booleanmetric_test_get_value,
        *_uniffi_lowered_args,
    )
    return _uniffi_lift_return(_uniffi_ffi_result)
class CommonMetricData (*,
category: str,
name: str,
send_in_pings: typing.List[str],
lifetime: Lifetime,
disabled: bool,
dynamic_label: typing.Optional[DynamicLabelType] = <object object>)
Expand source code
@dataclass
class CommonMetricData:
    def __init__(self, *, category:str, name:str, send_in_pings:typing.List[str], lifetime:Lifetime, disabled:bool, dynamic_label:typing.Optional[DynamicLabelType] = _DEFAULT):
        self.category = category
        self.name = name
        self.send_in_pings = send_in_pings
        self.lifetime = lifetime
        self.disabled = disabled
        if dynamic_label is _DEFAULT:
            self.dynamic_label = None
        else:
            self.dynamic_label = dynamic_label
        
        

    
    def __str__(self):
        return "CommonMetricData(category={}, name={}, send_in_pings={}, lifetime={}, disabled={}, dynamic_label={})".format(self.category, self.name, self.send_in_pings, self.lifetime, self.disabled, self.dynamic_label)
    def __eq__(self, other):
        if self.category != other.category:
            return False
        if self.name != other.name:
            return False
        if self.send_in_pings != other.send_in_pings:
            return False
        if self.lifetime != other.lifetime:
            return False
        if self.disabled != other.disabled:
            return False
        if self.dynamic_label != other.dynamic_label:
            return False
        return True

CommonMetricData(*, category: 'str', name: 'str', send_in_pings: 'typing.List[str]', lifetime: 'Lifetime', disabled: 'bool', dynamic_label: 'typing.Optional[DynamicLabelType]' = )

class CounterMetricType (meta: CommonMetricData)
Expand source code
class CounterMetric(CounterMetricProtocol):
    
    _handle: ctypes.c_uint64
    def __init__(self, meta: CommonMetricData):
        
        _UniffiFfiConverterTypeCommonMetricData.check_lower(meta)
        _uniffi_lowered_args = (
            _UniffiFfiConverterTypeCommonMetricData.lower(meta),
        )
        _uniffi_lift_return = _UniffiFfiConverterTypeCounterMetric.lift
        _uniffi_error_converter = None
        _uniffi_ffi_result = _uniffi_rust_call_with_error(
            _uniffi_error_converter,
            _UniffiLib.uniffi_glean_core_fn_constructor_countermetric_new,
            *_uniffi_lowered_args,
        )
        self._handle = _uniffi_ffi_result

    def __del__(self):
        # In case of partial initialization of instances.
        handle = getattr(self, "_handle", None)
        if handle is not None:
            _uniffi_rust_call(_UniffiLib.uniffi_glean_core_fn_free_countermetric, handle)

    def _uniffi_clone_handle(self):
        return _uniffi_rust_call(_UniffiLib.uniffi_glean_core_fn_clone_countermetric, self._handle)

    # Used by alternative constructors or any methods which return this type.
    @classmethod
    def _uniffi_make_instance(cls, handle):
        # Lightly yucky way to bypass the usual __init__ logic
        # and just create a new instance with the required handle.
        inst = cls.__new__(cls)
        inst._handle = handle
        return inst
    def add(self, amount: int = 1) -> None:
        
        _UniffiFfiConverterInt32.check_lower(amount)
        _uniffi_lowered_args = (
            self._uniffi_clone_handle(),
            _UniffiFfiConverterInt32.lower(amount),
        )
        _uniffi_lift_return = lambda val: None
        _uniffi_error_converter = None
        _uniffi_ffi_result = _uniffi_rust_call_with_error(
            _uniffi_error_converter,
            _UniffiLib.uniffi_glean_core_fn_method_countermetric_add,
            *_uniffi_lowered_args,
        )
        return _uniffi_lift_return(_uniffi_ffi_result)
    def test_get_num_recorded_errors(self, error: ErrorType) -> int:
        
        _UniffiFfiConverterTypeErrorType.check_lower(error)
        _uniffi_lowered_args = (
            self._uniffi_clone_handle(),
            _UniffiFfiConverterTypeErrorType.lower(error),
        )
        _uniffi_lift_return = _UniffiFfiConverterInt32.lift
        _uniffi_error_converter = None
        _uniffi_ffi_result = _uniffi_rust_call_with_error(
            _uniffi_error_converter,
            _UniffiLib.uniffi_glean_core_fn_method_countermetric_test_get_num_recorded_errors,
            *_uniffi_lowered_args,
        )
        return _uniffi_lift_return(_uniffi_ffi_result)
    def test_get_value(self, ping_name: typing.Union[object, typing.Optional[str]] = _DEFAULT) -> typing.Optional[int]:
        
        if ping_name is _DEFAULT:
            ping_name = None
        _UniffiFfiConverterOptionalString.check_lower(ping_name)
        _uniffi_lowered_args = (
            self._uniffi_clone_handle(),
            _UniffiFfiConverterOptionalString.lower(ping_name),
        )
        _uniffi_lift_return = _UniffiFfiConverterOptionalInt32.lift
        _uniffi_error_converter = None
        _uniffi_ffi_result = _uniffi_rust_call_with_error(
            _uniffi_error_converter,
            _UniffiLib.uniffi_glean_core_fn_method_countermetric_test_get_value,
            *_uniffi_lowered_args,
        )
        return _uniffi_lift_return(_uniffi_ffi_result)

Base class for protocol classes.

Protocol classes are defined as::

class Proto(Protocol):
    def meth(self) -> int:
        ...

Such classes are primarily used with static type checkers that recognize structural subtyping (static duck-typing).

For example::

class C:
    def meth(self) -> int:
        return 0

def func(x: Proto) -> int:
    return x.meth()

func(C())  # Passes static type check

See PEP 544 for details. Protocol classes decorated with @typing.runtime_checkable act as simple-minded runtime protocols that check only the presence of given attributes, ignoring their type signatures. Protocol classes can be generic, they are defined as::

class GenProto[T](Protocol):
    def meth(self) -> T:
        ...

Ancestors

  • glean._uniffi.glean.CounterMetricProtocol
  • typing.Protocol
  • typing.Generic

Methods

def add(self, amount: int = 1) ‑> None
Expand source code
def add(self, amount: int = 1) -> None:
    
    _UniffiFfiConverterInt32.check_lower(amount)
    _uniffi_lowered_args = (
        self._uniffi_clone_handle(),
        _UniffiFfiConverterInt32.lower(amount),
    )
    _uniffi_lift_return = lambda val: None
    _uniffi_error_converter = None
    _uniffi_ffi_result = _uniffi_rust_call_with_error(
        _uniffi_error_converter,
        _UniffiLib.uniffi_glean_core_fn_method_countermetric_add,
        *_uniffi_lowered_args,
    )
    return _uniffi_lift_return(_uniffi_ffi_result)
def test_get_num_recorded_errors(self, error: ErrorType) ‑> int
Expand source code
def test_get_num_recorded_errors(self, error: ErrorType) -> int:
    
    _UniffiFfiConverterTypeErrorType.check_lower(error)
    _uniffi_lowered_args = (
        self._uniffi_clone_handle(),
        _UniffiFfiConverterTypeErrorType.lower(error),
    )
    _uniffi_lift_return = _UniffiFfiConverterInt32.lift
    _uniffi_error_converter = None
    _uniffi_ffi_result = _uniffi_rust_call_with_error(
        _uniffi_error_converter,
        _UniffiLib.uniffi_glean_core_fn_method_countermetric_test_get_num_recorded_errors,
        *_uniffi_lowered_args,
    )
    return _uniffi_lift_return(_uniffi_ffi_result)
def test_get_value(self,
ping_name: typing.Union[glean.metrics.object, typing.Optional[str]] = <object object>) ‑> int | None
Expand source code
def test_get_value(self, ping_name: typing.Union[object, typing.Optional[str]] = _DEFAULT) -> typing.Optional[int]:
    
    if ping_name is _DEFAULT:
        ping_name = None
    _UniffiFfiConverterOptionalString.check_lower(ping_name)
    _uniffi_lowered_args = (
        self._uniffi_clone_handle(),
        _UniffiFfiConverterOptionalString.lower(ping_name),
    )
    _uniffi_lift_return = _UniffiFfiConverterOptionalInt32.lift
    _uniffi_error_converter = None
    _uniffi_ffi_result = _uniffi_rust_call_with_error(
        _uniffi_error_converter,
        _UniffiLib.uniffi_glean_core_fn_method_countermetric_test_get_value,
        *_uniffi_lowered_args,
    )
    return _uniffi_lift_return(_uniffi_ffi_result)
class DatetimeMetricType (common_metric_data: glean._uniffi.glean.CommonMetricData,
time_unit: glean._uniffi.glean.TimeUnit)
Expand source code
class DatetimeMetricType:
    """
    This implements the developer facing API for recording datetime metrics.

    Instances of this class type are automatically generated by
    `glean.load_metrics`, allowing developers to record values that were
    previously registered in the metrics.yaml file.

    The datetime API only exposes the `DatetimeMetricType.set` method.
    """

    def __init__(self, common_metric_data: CommonMetricData, time_unit: TimeUnit):
        self._inner = DatetimeMetric(common_metric_data, time_unit)

    def set(self, value: Optional[datetime.datetime] = None) -> None:
        """
        Set a datetime value, truncating it to the metric's resolution.

        Args:
            value (datetime.datetime): (default: now) The `datetime.datetime`
                value to set. If not provided, will record the current time.
        """
        if value is None:
            # now at UTC -> astimezone gives us a time with the local timezone.
            value = datetime.datetime.now(datetime.timezone.utc).astimezone()

        tzinfo = value.tzinfo
        if tzinfo is not None:
            utcoff = tzinfo.utcoffset(value)
            if utcoff is not None:
                offset = utcoff.seconds
            else:
                offset = 0
        else:
            offset = 0

        dt = Datetime(
            year=value.year,
            month=value.month,
            day=value.day,
            hour=value.hour,
            minute=value.minute,
            second=value.second,
            nanosecond=value.microsecond * 1000,
            offset_seconds=offset,
        )

        self._inner.set(dt)

    def test_get_value_as_str(self, ping_name: Optional[str] = None) -> Optional[str]:
        """
        Returns the stored value for testing purposes only, as an ISO8601 string.

        Args:
            ping_name (str): (default: first value in send_in_pings) The name
                of the ping to retrieve the metric for.

        Returns:
            value (str): value of the stored metric.
        """
        dt = self.test_get_value(ping_name)
        if not dt:
            return None

        return dt.isoformat()

    def test_get_value(self, ping_name: Optional[str] = None) -> Optional[datetime.datetime]:
        """
        Returns the stored value for testing purposes only.

        Args:
            ping_name (str): (default: first value in send_in_pings) The name
                of the ping to retrieve the metric for.

        Returns:
            value (datetime.datetime): value of the stored metric.
        """
        value = self._inner.test_get_value(ping_name)
        if not value:
            return None

        tz = tzoffset(value.offset_seconds)
        dt = datetime.datetime(
            year=value.year,
            month=value.month,
            day=value.day,
            hour=value.hour,
            minute=value.minute,
            second=value.second,
            microsecond=round(value.nanosecond / 1000),
            tzinfo=tz,
        )
        return dt

    def test_get_num_recorded_errors(self, error_type: ErrorType) -> int:
        return self._inner.test_get_num_recorded_errors(error_type)

This implements the developer facing API for recording datetime metrics.

Instances of this class type are automatically generated by load_metrics(), allowing developers to record values that were previously registered in the metrics.yaml file.

The datetime API only exposes the DatetimeMetricType.set() method.

Methods

def set(self, value: datetime.datetime | None = None) ‑> None
Expand source code
def set(self, value: Optional[datetime.datetime] = None) -> None:
    """
    Set a datetime value, truncating it to the metric's resolution.

    Args:
        value (datetime.datetime): (default: now) The `datetime.datetime`
            value to set. If not provided, will record the current time.
    """
    if value is None:
        # now at UTC -> astimezone gives us a time with the local timezone.
        value = datetime.datetime.now(datetime.timezone.utc).astimezone()

    tzinfo = value.tzinfo
    if tzinfo is not None:
        utcoff = tzinfo.utcoffset(value)
        if utcoff is not None:
            offset = utcoff.seconds
        else:
            offset = 0
    else:
        offset = 0

    dt = Datetime(
        year=value.year,
        month=value.month,
        day=value.day,
        hour=value.hour,
        minute=value.minute,
        second=value.second,
        nanosecond=value.microsecond * 1000,
        offset_seconds=offset,
    )

    self._inner.set(dt)

Set a datetime value, truncating it to the metric's resolution.

Args

value : datetime.datetime
(default: now) The datetime.datetime value to set. If not provided, will record the current time.
def test_get_num_recorded_errors(self, error_type: glean._uniffi.glean.ErrorType) ‑> int
Expand source code
def test_get_num_recorded_errors(self, error_type: ErrorType) -> int:
    return self._inner.test_get_num_recorded_errors(error_type)
def test_get_value(self, ping_name: str | None = None) ‑> datetime.datetime | None
Expand source code
def test_get_value(self, ping_name: Optional[str] = None) -> Optional[datetime.datetime]:
    """
    Returns the stored value for testing purposes only.

    Args:
        ping_name (str): (default: first value in send_in_pings) The name
            of the ping to retrieve the metric for.

    Returns:
        value (datetime.datetime): value of the stored metric.
    """
    value = self._inner.test_get_value(ping_name)
    if not value:
        return None

    tz = tzoffset(value.offset_seconds)
    dt = datetime.datetime(
        year=value.year,
        month=value.month,
        day=value.day,
        hour=value.hour,
        minute=value.minute,
        second=value.second,
        microsecond=round(value.nanosecond / 1000),
        tzinfo=tz,
    )
    return dt

Returns the stored value for testing purposes only.

Args

ping_name : str
(default: first value in send_in_pings) The name of the ping to retrieve the metric for.

Returns

value (datetime.datetime): value of the stored metric.

def test_get_value_as_str(self, ping_name: str | None = None) ‑> str | None
Expand source code
def test_get_value_as_str(self, ping_name: Optional[str] = None) -> Optional[str]:
    """
    Returns the stored value for testing purposes only, as an ISO8601 string.

    Args:
        ping_name (str): (default: first value in send_in_pings) The name
            of the ping to retrieve the metric for.

    Returns:
        value (str): value of the stored metric.
    """
    dt = self.test_get_value(ping_name)
    if not dt:
        return None

    return dt.isoformat()

Returns the stored value for testing purposes only, as an ISO8601 string.

Args

ping_name : str
(default: first value in send_in_pings) The name of the ping to retrieve the metric for.

Returns

value (str): value of the stored metric.

class DenominatorMetricType (meta: CommonMetricData,
numerators: typing.List[CommonMetricData])
Expand source code
class DenominatorMetric(DenominatorMetricProtocol):
    
    _handle: ctypes.c_uint64
    def __init__(self, meta: CommonMetricData,numerators: typing.List[CommonMetricData]):
        
        _UniffiFfiConverterTypeCommonMetricData.check_lower(meta)

        _UniffiFfiConverterSequenceTypeCommonMetricData.check_lower(numerators)
        _uniffi_lowered_args = (
            _UniffiFfiConverterTypeCommonMetricData.lower(meta),
            _UniffiFfiConverterSequenceTypeCommonMetricData.lower(numerators),
        )
        _uniffi_lift_return = _UniffiFfiConverterTypeDenominatorMetric.lift
        _uniffi_error_converter = None
        _uniffi_ffi_result = _uniffi_rust_call_with_error(
            _uniffi_error_converter,
            _UniffiLib.uniffi_glean_core_fn_constructor_denominatormetric_new,
            *_uniffi_lowered_args,
        )
        self._handle = _uniffi_ffi_result

    def __del__(self):
        # In case of partial initialization of instances.
        handle = getattr(self, "_handle", None)
        if handle is not None:
            _uniffi_rust_call(_UniffiLib.uniffi_glean_core_fn_free_denominatormetric, handle)

    def _uniffi_clone_handle(self):
        return _uniffi_rust_call(_UniffiLib.uniffi_glean_core_fn_clone_denominatormetric, self._handle)

    # Used by alternative constructors or any methods which return this type.
    @classmethod
    def _uniffi_make_instance(cls, handle):
        # Lightly yucky way to bypass the usual __init__ logic
        # and just create a new instance with the required handle.
        inst = cls.__new__(cls)
        inst._handle = handle
        return inst
    def add(self, amount: int) -> None:
        
        _UniffiFfiConverterInt32.check_lower(amount)
        _uniffi_lowered_args = (
            self._uniffi_clone_handle(),
            _UniffiFfiConverterInt32.lower(amount),
        )
        _uniffi_lift_return = lambda val: None
        _uniffi_error_converter = None
        _uniffi_ffi_result = _uniffi_rust_call_with_error(
            _uniffi_error_converter,
            _UniffiLib.uniffi_glean_core_fn_method_denominatormetric_add,
            *_uniffi_lowered_args,
        )
        return _uniffi_lift_return(_uniffi_ffi_result)
    def test_get_num_recorded_errors(self, error: ErrorType) -> int:
        
        _UniffiFfiConverterTypeErrorType.check_lower(error)
        _uniffi_lowered_args = (
            self._uniffi_clone_handle(),
            _UniffiFfiConverterTypeErrorType.lower(error),
        )
        _uniffi_lift_return = _UniffiFfiConverterInt32.lift
        _uniffi_error_converter = None
        _uniffi_ffi_result = _uniffi_rust_call_with_error(
            _uniffi_error_converter,
            _UniffiLib.uniffi_glean_core_fn_method_denominatormetric_test_get_num_recorded_errors,
            *_uniffi_lowered_args,
        )
        return _uniffi_lift_return(_uniffi_ffi_result)
    def test_get_value(self, ping_name: typing.Union[object, typing.Optional[str]] = _DEFAULT) -> typing.Optional[int]:
        
        if ping_name is _DEFAULT:
            ping_name = None
        _UniffiFfiConverterOptionalString.check_lower(ping_name)
        _uniffi_lowered_args = (
            self._uniffi_clone_handle(),
            _UniffiFfiConverterOptionalString.lower(ping_name),
        )
        _uniffi_lift_return = _UniffiFfiConverterOptionalInt32.lift
        _uniffi_error_converter = None
        _uniffi_ffi_result = _uniffi_rust_call_with_error(
            _uniffi_error_converter,
            _UniffiLib.uniffi_glean_core_fn_method_denominatormetric_test_get_value,
            *_uniffi_lowered_args,
        )
        return _uniffi_lift_return(_uniffi_ffi_result)

Base class for protocol classes.

Protocol classes are defined as::

class Proto(Protocol):
    def meth(self) -> int:
        ...

Such classes are primarily used with static type checkers that recognize structural subtyping (static duck-typing).

For example::

class C:
    def meth(self) -> int:
        return 0

def func(x: Proto) -> int:
    return x.meth()

func(C())  # Passes static type check

See PEP 544 for details. Protocol classes decorated with @typing.runtime_checkable act as simple-minded runtime protocols that check only the presence of given attributes, ignoring their type signatures. Protocol classes can be generic, they are defined as::

class GenProto[T](Protocol):
    def meth(self) -> T:
        ...

Ancestors

  • glean._uniffi.glean.DenominatorMetricProtocol
  • typing.Protocol
  • typing.Generic

Methods

def add(self, amount: int) ‑> None
Expand source code
def add(self, amount: int) -> None:
    
    _UniffiFfiConverterInt32.check_lower(amount)
    _uniffi_lowered_args = (
        self._uniffi_clone_handle(),
        _UniffiFfiConverterInt32.lower(amount),
    )
    _uniffi_lift_return = lambda val: None
    _uniffi_error_converter = None
    _uniffi_ffi_result = _uniffi_rust_call_with_error(
        _uniffi_error_converter,
        _UniffiLib.uniffi_glean_core_fn_method_denominatormetric_add,
        *_uniffi_lowered_args,
    )
    return _uniffi_lift_return(_uniffi_ffi_result)
def test_get_num_recorded_errors(self, error: ErrorType) ‑> int
Expand source code
def test_get_num_recorded_errors(self, error: ErrorType) -> int:
    
    _UniffiFfiConverterTypeErrorType.check_lower(error)
    _uniffi_lowered_args = (
        self._uniffi_clone_handle(),
        _UniffiFfiConverterTypeErrorType.lower(error),
    )
    _uniffi_lift_return = _UniffiFfiConverterInt32.lift
    _uniffi_error_converter = None
    _uniffi_ffi_result = _uniffi_rust_call_with_error(
        _uniffi_error_converter,
        _UniffiLib.uniffi_glean_core_fn_method_denominatormetric_test_get_num_recorded_errors,
        *_uniffi_lowered_args,
    )
    return _uniffi_lift_return(_uniffi_ffi_result)
def test_get_value(self,
ping_name: typing.Union[glean.metrics.object, typing.Optional[str]] = <object object>) ‑> int | None
Expand source code
def test_get_value(self, ping_name: typing.Union[object, typing.Optional[str]] = _DEFAULT) -> typing.Optional[int]:
    
    if ping_name is _DEFAULT:
        ping_name = None
    _UniffiFfiConverterOptionalString.check_lower(ping_name)
    _uniffi_lowered_args = (
        self._uniffi_clone_handle(),
        _UniffiFfiConverterOptionalString.lower(ping_name),
    )
    _uniffi_lift_return = _UniffiFfiConverterOptionalInt32.lift
    _uniffi_error_converter = None
    _uniffi_ffi_result = _uniffi_rust_call_with_error(
        _uniffi_error_converter,
        _UniffiLib.uniffi_glean_core_fn_method_denominatormetric_test_get_value,
        *_uniffi_lowered_args,
    )
    return _uniffi_lift_return(_uniffi_ffi_result)
class DistributionMetrics (*, name: typing.Optional[str] = <object object>)
Expand source code
@dataclass
class DistributionMetrics:
    def __init__(self, *, name:typing.Optional[str] = _DEFAULT):
        if name is _DEFAULT:
            self.name = None
        else:
            self.name = name
        
        

    
    def __str__(self):
        return "DistributionMetrics(name={})".format(self.name)
    def __eq__(self, other):
        if self.name != other.name:
            return False
        return True

DistributionMetrics(*, name: 'typing.Optional[str]' = )

class EventExtras
Expand source code
class EventExtras:
    """
    A class that can be converted into key-value pairs of event extras.
    This will be automatically implemented for event properties of an [EventMetricType].
    """

    def to_ffi_extra(self) -> Dict[str, str]:
        """
        Convert the event extras into a key-value dict:
        """
        return {}

A class that can be converted into key-value pairs of event extras. This will be automatically implemented for event properties of an [EventMetricType].

Methods

def to_ffi_extra(self) ‑> Dict[str, str]
Expand source code
def to_ffi_extra(self) -> Dict[str, str]:
    """
    Convert the event extras into a key-value dict:
    """
    return {}

Convert the event extras into a key-value dict:

class EventMetricType (common_metric_data: glean._uniffi.glean.CommonMetricData,
allowed_extra_keys: List[str])
Expand source code
class EventMetricType:
    """
    This implements the developer facing API for recording events.

    Instances of this class type are automatically generated by
    `glean.load_metrics`, allowing developers to record values that were
    previously registered in the metrics.yaml file.

    The event API only exposes the `EventMetricType.record` method, which
    takes care of validating the input data and making sure that limits are
    enforced.
    """

    def __init__(
        self,
        common_metric_data: CommonMetricData,
        allowed_extra_keys: List[str],
    ):
        self._inner = EventMetric(common_metric_data, allowed_extra_keys)

    def record(self, extra: Optional[EventExtras] = None) -> None:
        """
        Record an event by using the information provided by the instance of
        this class.

        Args:
            extra: optional. The extra keys and values for this event.
                   The maximum length for values is 100.
        """

        if isinstance(extra, EventExtras):
            inner_extra = extra.to_ffi_extra()
        else:
            inner_extra = {}

        self._inner.record(inner_extra)

    def test_get_value(self, ping_name: Optional[str] = None) -> Optional[List[RecordedEvent]]:
        """
        Returns the stored value for testing purposes only.

        Args:
            ping_name (str): (default: first value in send_in_pings) The name
                of the ping to retrieve the metric for.

        Returns:
            value (list of RecordedEventData): value of the stored events.
        """
        # Translate NO extras into an empty dictionary,
        # to simplify handling.
        recordings = self._inner.test_get_value(ping_name)
        if recordings:
            for recording in recordings:
                if recording.extra is None:
                    recording.extra = {}

        return recordings

    def test_get_num_recorded_errors(self, error_type: ErrorType) -> int:
        """
        Returns the number of errors recorded for the given metric.

        Args:
            error_type (ErrorType): The type of error recorded.
            ping_name (str): (default: first value in send_in_pings) The name
                of the ping to retrieve the metric for.

        Returns:
            num_errors (int): The number of errors recorded for the metric for
                the given error type.
        """
        return self._inner.test_get_num_recorded_errors(error_type)

This implements the developer facing API for recording events.

Instances of this class type are automatically generated by load_metrics(), allowing developers to record values that were previously registered in the metrics.yaml file.

The event API only exposes the EventMetricType.record() method, which takes care of validating the input data and making sure that limits are enforced.

Methods

def record(self,
extra: EventExtras | None = None) ‑> None
Expand source code
def record(self, extra: Optional[EventExtras] = None) -> None:
    """
    Record an event by using the information provided by the instance of
    this class.

    Args:
        extra: optional. The extra keys and values for this event.
               The maximum length for values is 100.
    """

    if isinstance(extra, EventExtras):
        inner_extra = extra.to_ffi_extra()
    else:
        inner_extra = {}

    self._inner.record(inner_extra)

Record an event by using the information provided by the instance of this class.

Args

extra
optional. The extra keys and values for this event. The maximum length for values is 100.
def test_get_num_recorded_errors(self, error_type: glean._uniffi.glean.ErrorType) ‑> int
Expand source code
def test_get_num_recorded_errors(self, error_type: ErrorType) -> int:
    """
    Returns the number of errors recorded for the given metric.

    Args:
        error_type (ErrorType): The type of error recorded.
        ping_name (str): (default: first value in send_in_pings) The name
            of the ping to retrieve the metric for.

    Returns:
        num_errors (int): The number of errors recorded for the metric for
            the given error type.
    """
    return self._inner.test_get_num_recorded_errors(error_type)

Returns the number of errors recorded for the given metric.

Args

error_type : ErrorType
The type of error recorded.
ping_name : str
(default: first value in send_in_pings) The name of the ping to retrieve the metric for.

Returns

num_errors (int): The number of errors recorded for the metric for the given error type.

def test_get_value(self, ping_name: str | None = None) ‑> List[glean._uniffi.glean.RecordedEvent] | None
Expand source code
def test_get_value(self, ping_name: Optional[str] = None) -> Optional[List[RecordedEvent]]:
    """
    Returns the stored value for testing purposes only.

    Args:
        ping_name (str): (default: first value in send_in_pings) The name
            of the ping to retrieve the metric for.

    Returns:
        value (list of RecordedEventData): value of the stored events.
    """
    # Translate NO extras into an empty dictionary,
    # to simplify handling.
    recordings = self._inner.test_get_value(ping_name)
    if recordings:
        for recording in recordings:
            if recording.extra is None:
                recording.extra = {}

    return recordings

Returns the stored value for testing purposes only.

Args

ping_name : str
(default: first value in send_in_pings) The name of the ping to retrieve the metric for.

Returns

value (list of RecordedEventData): value of the stored events.

class LabeledBooleanMetricType (labeled_metric_data: glean._uniffi.glean.LabeledMetricData,
labels: Set[str] | None = None)
Expand source code
class LabeledBooleanMetricType(LabeledMetricBase):
    _ctor = LabeledBoolean

This implements the developer-facing API for labeled metrics.

Instances of this class type are automatically generated by load_metrics(), allowing developers to record values that were previously registered in the metrics.yaml file.

Unlike most metric types, LabeledMetricType does not have its own corresponding storage, but records metrics for the underlying metric type T in the storage for that type. The only difference is that labeled metrics are stored with the special key $category.$name/$label. The collect method knows how to pull these special values back out of the individual metric storage and rearrange them correctly in the ping.

Ancestors

  • glean.metrics.labeled.LabeledMetricBase
class LabeledCounterMetricType (labeled_metric_data: glean._uniffi.glean.LabeledMetricData,
labels: Set[str] | None = None)
Expand source code
class LabeledCounterMetricType(LabeledMetricBase):
    _ctor = LabeledCounter

This implements the developer-facing API for labeled metrics.

Instances of this class type are automatically generated by load_metrics(), allowing developers to record values that were previously registered in the metrics.yaml file.

Unlike most metric types, LabeledMetricType does not have its own corresponding storage, but records metrics for the underlying metric type T in the storage for that type. The only difference is that labeled metrics are stored with the special key $category.$name/$label. The collect method knows how to pull these special values back out of the individual metric storage and rearrange them correctly in the ping.

Ancestors

  • glean.metrics.labeled.LabeledMetricBase
class LabeledMetricData
Expand source code
class LabeledMetricData:
    def __init__(self):
        raise RuntimeError("LabeledMetricData cannot be instantiated directly")

    # Each enum variant is a nested class of the enum itself.
    @dataclass
    class COMMON:
        
        def __init__(self, cmd:CommonMetricData):
            self.cmd = cmd
            
            
            pass

    
            
            
    
        def __str__(self):
            return "LabeledMetricData.COMMON(cmd={})".format(self.cmd)
        def __eq__(self, other):
            if not isinstance(other, LabeledMetricData):
                return NotImplemented
            if not other.is_COMMON():
                return False
            if self.cmd != other.cmd:
                return False
            return True

    @dataclass
    class CUSTOM_DISTRIBUTION:
        
        def __init__(self, cmd:CommonMetricData, range_min:int, range_max:int, bucket_count:int, histogram_type:HistogramType):
            self.cmd = cmd
            
            
            self.range_min = range_min
            
            
            self.range_max = range_max
            
            
            self.bucket_count = bucket_count
            
            
            self.histogram_type = histogram_type
            
            
            pass

    
            
            
    
        def __str__(self):
            return "LabeledMetricData.CUSTOM_DISTRIBUTION(cmd={}, range_min={}, range_max={}, bucket_count={}, histogram_type={})".format(self.cmd, self.range_min, self.range_max, self.bucket_count, self.histogram_type)
        def __eq__(self, other):
            if not isinstance(other, LabeledMetricData):
                return NotImplemented
            if not other.is_CUSTOM_DISTRIBUTION():
                return False
            if self.cmd != other.cmd:
                return False
            if self.range_min != other.range_min:
                return False
            if self.range_max != other.range_max:
                return False
            if self.bucket_count != other.bucket_count:
                return False
            if self.histogram_type != other.histogram_type:
                return False
            return True

    @dataclass
    class MEMORY_DISTRIBUTION:
        
        def __init__(self, cmd:CommonMetricData, unit:MemoryUnit):
            self.cmd = cmd
            
            
            self.unit = unit
            
            
            pass

    
            
            
    
        def __str__(self):
            return "LabeledMetricData.MEMORY_DISTRIBUTION(cmd={}, unit={})".format(self.cmd, self.unit)
        def __eq__(self, other):
            if not isinstance(other, LabeledMetricData):
                return NotImplemented
            if not other.is_MEMORY_DISTRIBUTION():
                return False
            if self.cmd != other.cmd:
                return False
            if self.unit != other.unit:
                return False
            return True

    @dataclass
    class TIMING_DISTRIBUTION:
        
        def __init__(self, cmd:CommonMetricData, unit:TimeUnit):
            self.cmd = cmd
            
            
            self.unit = unit
            
            
            pass

    
            
            
    
        def __str__(self):
            return "LabeledMetricData.TIMING_DISTRIBUTION(cmd={}, unit={})".format(self.cmd, self.unit)
        def __eq__(self, other):
            if not isinstance(other, LabeledMetricData):
                return NotImplemented
            if not other.is_TIMING_DISTRIBUTION():
                return False
            if self.cmd != other.cmd:
                return False
            if self.unit != other.unit:
                return False
            return True

    

    # For each variant, we have `is_NAME` and `is_name` methods for easily checking
    # whether an instance is that variant.
    def is_COMMON(self) -> bool:
        return isinstance(self, LabeledMetricData.COMMON)
    def is_common(self) -> bool:
        return isinstance(self, LabeledMetricData.COMMON)
    def is_CUSTOM_DISTRIBUTION(self) -> bool:
        return isinstance(self, LabeledMetricData.CUSTOM_DISTRIBUTION)
    def is_custom_distribution(self) -> bool:
        return isinstance(self, LabeledMetricData.CUSTOM_DISTRIBUTION)
    def is_MEMORY_DISTRIBUTION(self) -> bool:
        return isinstance(self, LabeledMetricData.MEMORY_DISTRIBUTION)
    def is_memory_distribution(self) -> bool:
        return isinstance(self, LabeledMetricData.MEMORY_DISTRIBUTION)
    def is_TIMING_DISTRIBUTION(self) -> bool:
        return isinstance(self, LabeledMetricData.TIMING_DISTRIBUTION)
    def is_timing_distribution(self) -> bool:
        return isinstance(self, LabeledMetricData.TIMING_DISTRIBUTION)

Subclasses

  • glean._uniffi.glean.LabeledMetricData.COMMON
  • glean._uniffi.glean.LabeledMetricData.CUSTOM_DISTRIBUTION
  • glean._uniffi.glean.LabeledMetricData.MEMORY_DISTRIBUTION
  • glean._uniffi.glean.LabeledMetricData.TIMING_DISTRIBUTION

Class variables

var COMMON
var CUSTOM_DISTRIBUTION
var MEMORY_DISTRIBUTION
var TIMING_DISTRIBUTION

Methods

def is_COMMON(self) ‑> bool
Expand source code
def is_COMMON(self) -> bool:
    return isinstance(self, LabeledMetricData.COMMON)
def is_CUSTOM_DISTRIBUTION(self) ‑> bool
Expand source code
def is_CUSTOM_DISTRIBUTION(self) -> bool:
    return isinstance(self, LabeledMetricData.CUSTOM_DISTRIBUTION)
def is_MEMORY_DISTRIBUTION(self) ‑> bool
Expand source code
def is_MEMORY_DISTRIBUTION(self) -> bool:
    return isinstance(self, LabeledMetricData.MEMORY_DISTRIBUTION)
def is_TIMING_DISTRIBUTION(self) ‑> bool
Expand source code
def is_TIMING_DISTRIBUTION(self) -> bool:
    return isinstance(self, LabeledMetricData.TIMING_DISTRIBUTION)
def is_common(self) ‑> bool
Expand source code
def is_common(self) -> bool:
    return isinstance(self, LabeledMetricData.COMMON)
def is_custom_distribution(self) ‑> bool
Expand source code
def is_custom_distribution(self) -> bool:
    return isinstance(self, LabeledMetricData.CUSTOM_DISTRIBUTION)
def is_memory_distribution(self) ‑> bool
Expand source code
def is_memory_distribution(self) -> bool:
    return isinstance(self, LabeledMetricData.MEMORY_DISTRIBUTION)
def is_timing_distribution(self) ‑> bool
Expand source code
def is_timing_distribution(self) -> bool:
    return isinstance(self, LabeledMetricData.TIMING_DISTRIBUTION)
class LabeledQuantityMetricType (labeled_metric_data: glean._uniffi.glean.LabeledMetricData,
labels: Set[str] | None = None)
Expand source code
class LabeledQuantityMetricType(LabeledMetricBase):
    _ctor = LabeledQuantity

This implements the developer-facing API for labeled metrics.

Instances of this class type are automatically generated by load_metrics(), allowing developers to record values that were previously registered in the metrics.yaml file.

Unlike most metric types, LabeledMetricType does not have its own corresponding storage, but records metrics for the underlying metric type T in the storage for that type. The only difference is that labeled metrics are stored with the special key $category.$name/$label. The collect method knows how to pull these special values back out of the individual metric storage and rearrange them correctly in the ping.

Ancestors

  • glean.metrics.labeled.LabeledMetricBase
class LabeledStringMetricType (labeled_metric_data: glean._uniffi.glean.LabeledMetricData,
labels: Set[str] | None = None)
Expand source code
class LabeledStringMetricType(LabeledMetricBase):
    _ctor = LabeledString

This implements the developer-facing API for labeled metrics.

Instances of this class type are automatically generated by load_metrics(), allowing developers to record values that were previously registered in the metrics.yaml file.

Unlike most metric types, LabeledMetricType does not have its own corresponding storage, but records metrics for the underlying metric type T in the storage for that type. The only difference is that labeled metrics are stored with the special key $category.$name/$label. The collect method knows how to pull these special values back out of the individual metric storage and rearrange them correctly in the ping.

Ancestors

  • glean.metrics.labeled.LabeledMetricBase
class Lifetime (*args, **kwds)
Expand source code
class Lifetime(enum.Enum):
    
    PING = 0
    
    APPLICATION = 1
    
    USER = 2

Create a collection of name/value pairs.

Example enumeration:

>>> class Color(Enum):
...     RED = 1
...     BLUE = 2
...     GREEN = 3

Access them by:

  • attribute access:

Color.RED

  • value lookup:

Color(1)

  • name lookup:

Color['RED']

Enumerations can be iterated over, and know how many members they have:

>>> len(Color)
3
>>> list(Color)
[<Color.RED: 1>, <Color.BLUE: 2>, <Color.GREEN: 3>]

Methods can be added to enumerations, and members can have their own attributes – see the documentation for details.

Ancestors

  • enum.Enum

Class variables

var APPLICATION

The type of the None singleton.

var PING

The type of the None singleton.

var USER

The type of the None singleton.

class MemoryDistributionMetricType (meta: CommonMetricData,
memory_unit: MemoryUnit)
Expand source code
class MemoryDistributionMetric(MemoryDistributionMetricProtocol):
    
    _handle: ctypes.c_uint64
    def __init__(self, meta: CommonMetricData,memory_unit: MemoryUnit):
        
        _UniffiFfiConverterTypeCommonMetricData.check_lower(meta)

        _UniffiFfiConverterTypeMemoryUnit.check_lower(memory_unit)
        _uniffi_lowered_args = (
            _UniffiFfiConverterTypeCommonMetricData.lower(meta),
            _UniffiFfiConverterTypeMemoryUnit.lower(memory_unit),
        )
        _uniffi_lift_return = _UniffiFfiConverterTypeMemoryDistributionMetric.lift
        _uniffi_error_converter = None
        _uniffi_ffi_result = _uniffi_rust_call_with_error(
            _uniffi_error_converter,
            _UniffiLib.uniffi_glean_core_fn_constructor_memorydistributionmetric_new,
            *_uniffi_lowered_args,
        )
        self._handle = _uniffi_ffi_result

    def __del__(self):
        # In case of partial initialization of instances.
        handle = getattr(self, "_handle", None)
        if handle is not None:
            _uniffi_rust_call(_UniffiLib.uniffi_glean_core_fn_free_memorydistributionmetric, handle)

    def _uniffi_clone_handle(self):
        return _uniffi_rust_call(_UniffiLib.uniffi_glean_core_fn_clone_memorydistributionmetric, self._handle)

    # Used by alternative constructors or any methods which return this type.
    @classmethod
    def _uniffi_make_instance(cls, handle):
        # Lightly yucky way to bypass the usual __init__ logic
        # and just create a new instance with the required handle.
        inst = cls.__new__(cls)
        inst._handle = handle
        return inst
    def accumulate(self, sample: int) -> None:
        
        _UniffiFfiConverterInt64.check_lower(sample)
        _uniffi_lowered_args = (
            self._uniffi_clone_handle(),
            _UniffiFfiConverterInt64.lower(sample),
        )
        _uniffi_lift_return = lambda val: None
        _uniffi_error_converter = None
        _uniffi_ffi_result = _uniffi_rust_call_with_error(
            _uniffi_error_converter,
            _UniffiLib.uniffi_glean_core_fn_method_memorydistributionmetric_accumulate,
            *_uniffi_lowered_args,
        )
        return _uniffi_lift_return(_uniffi_ffi_result)
    def accumulate_samples(self, samples: typing.List[int]) -> None:
        
        _UniffiFfiConverterSequenceInt64.check_lower(samples)
        _uniffi_lowered_args = (
            self._uniffi_clone_handle(),
            _UniffiFfiConverterSequenceInt64.lower(samples),
        )
        _uniffi_lift_return = lambda val: None
        _uniffi_error_converter = None
        _uniffi_ffi_result = _uniffi_rust_call_with_error(
            _uniffi_error_converter,
            _UniffiLib.uniffi_glean_core_fn_method_memorydistributionmetric_accumulate_samples,
            *_uniffi_lowered_args,
        )
        return _uniffi_lift_return(_uniffi_ffi_result)
    def test_get_num_recorded_errors(self, error: ErrorType) -> int:
        
        _UniffiFfiConverterTypeErrorType.check_lower(error)
        _uniffi_lowered_args = (
            self._uniffi_clone_handle(),
            _UniffiFfiConverterTypeErrorType.lower(error),
        )
        _uniffi_lift_return = _UniffiFfiConverterInt32.lift
        _uniffi_error_converter = None
        _uniffi_ffi_result = _uniffi_rust_call_with_error(
            _uniffi_error_converter,
            _UniffiLib.uniffi_glean_core_fn_method_memorydistributionmetric_test_get_num_recorded_errors,
            *_uniffi_lowered_args,
        )
        return _uniffi_lift_return(_uniffi_ffi_result)
    def test_get_value(self, ping_name: typing.Union[object, typing.Optional[str]] = _DEFAULT) -> typing.Optional[DistributionData]:
        
        if ping_name is _DEFAULT:
            ping_name = None
        _UniffiFfiConverterOptionalString.check_lower(ping_name)
        _uniffi_lowered_args = (
            self._uniffi_clone_handle(),
            _UniffiFfiConverterOptionalString.lower(ping_name),
        )
        _uniffi_lift_return = _UniffiFfiConverterOptionalTypeDistributionData.lift
        _uniffi_error_converter = None
        _uniffi_ffi_result = _uniffi_rust_call_with_error(
            _uniffi_error_converter,
            _UniffiLib.uniffi_glean_core_fn_method_memorydistributionmetric_test_get_value,
            *_uniffi_lowered_args,
        )
        return _uniffi_lift_return(_uniffi_ffi_result)

Base class for protocol classes.

Protocol classes are defined as::

class Proto(Protocol):
    def meth(self) -> int:
        ...

Such classes are primarily used with static type checkers that recognize structural subtyping (static duck-typing).

For example::

class C:
    def meth(self) -> int:
        return 0

def func(x: Proto) -> int:
    return x.meth()

func(C())  # Passes static type check

See PEP 544 for details. Protocol classes decorated with @typing.runtime_checkable act as simple-minded runtime protocols that check only the presence of given attributes, ignoring their type signatures. Protocol classes can be generic, they are defined as::

class GenProto[T](Protocol):
    def meth(self) -> T:
        ...

Ancestors

  • glean._uniffi.glean.MemoryDistributionMetricProtocol
  • typing.Protocol
  • typing.Generic

Methods

def accumulate(self, sample: int) ‑> None
Expand source code
def accumulate(self, sample: int) -> None:
    
    _UniffiFfiConverterInt64.check_lower(sample)
    _uniffi_lowered_args = (
        self._uniffi_clone_handle(),
        _UniffiFfiConverterInt64.lower(sample),
    )
    _uniffi_lift_return = lambda val: None
    _uniffi_error_converter = None
    _uniffi_ffi_result = _uniffi_rust_call_with_error(
        _uniffi_error_converter,
        _UniffiLib.uniffi_glean_core_fn_method_memorydistributionmetric_accumulate,
        *_uniffi_lowered_args,
    )
    return _uniffi_lift_return(_uniffi_ffi_result)
def accumulate_samples(self, samples: typing.List[int]) ‑> None
Expand source code
def accumulate_samples(self, samples: typing.List[int]) -> None:
    
    _UniffiFfiConverterSequenceInt64.check_lower(samples)
    _uniffi_lowered_args = (
        self._uniffi_clone_handle(),
        _UniffiFfiConverterSequenceInt64.lower(samples),
    )
    _uniffi_lift_return = lambda val: None
    _uniffi_error_converter = None
    _uniffi_ffi_result = _uniffi_rust_call_with_error(
        _uniffi_error_converter,
        _UniffiLib.uniffi_glean_core_fn_method_memorydistributionmetric_accumulate_samples,
        *_uniffi_lowered_args,
    )
    return _uniffi_lift_return(_uniffi_ffi_result)
def test_get_num_recorded_errors(self, error: ErrorType) ‑> int
Expand source code
def test_get_num_recorded_errors(self, error: ErrorType) -> int:
    
    _UniffiFfiConverterTypeErrorType.check_lower(error)
    _uniffi_lowered_args = (
        self._uniffi_clone_handle(),
        _UniffiFfiConverterTypeErrorType.lower(error),
    )
    _uniffi_lift_return = _UniffiFfiConverterInt32.lift
    _uniffi_error_converter = None
    _uniffi_ffi_result = _uniffi_rust_call_with_error(
        _uniffi_error_converter,
        _UniffiLib.uniffi_glean_core_fn_method_memorydistributionmetric_test_get_num_recorded_errors,
        *_uniffi_lowered_args,
    )
    return _uniffi_lift_return(_uniffi_ffi_result)
def test_get_value(self,
ping_name: typing.Union[glean.metrics.object, typing.Optional[str]] = <object object>) ‑> glean._uniffi.glean.DistributionData | None
Expand source code
def test_get_value(self, ping_name: typing.Union[object, typing.Optional[str]] = _DEFAULT) -> typing.Optional[DistributionData]:
    
    if ping_name is _DEFAULT:
        ping_name = None
    _UniffiFfiConverterOptionalString.check_lower(ping_name)
    _uniffi_lowered_args = (
        self._uniffi_clone_handle(),
        _UniffiFfiConverterOptionalString.lower(ping_name),
    )
    _uniffi_lift_return = _UniffiFfiConverterOptionalTypeDistributionData.lift
    _uniffi_error_converter = None
    _uniffi_ffi_result = _uniffi_rust_call_with_error(
        _uniffi_error_converter,
        _UniffiLib.uniffi_glean_core_fn_method_memorydistributionmetric_test_get_value,
        *_uniffi_lowered_args,
    )
    return _uniffi_lift_return(_uniffi_ffi_result)
class MemoryUnit (*args, **kwds)
Expand source code
class MemoryUnit(enum.Enum):
    
    BYTE = 0
    
    KILOBYTE = 1
    
    MEGABYTE = 2
    
    GIGABYTE = 3

Create a collection of name/value pairs.

Example enumeration:

>>> class Color(Enum):
...     RED = 1
...     BLUE = 2
...     GREEN = 3

Access them by:

  • attribute access:

Color.RED

  • value lookup:

Color(1)

  • name lookup:

Color['RED']

Enumerations can be iterated over, and know how many members they have:

>>> len(Color)
3
>>> list(Color)
[<Color.RED: 1>, <Color.BLUE: 2>, <Color.GREEN: 3>]

Methods can be added to enumerations, and members can have their own attributes – see the documentation for details.

Ancestors

  • enum.Enum

Class variables

var BYTE

The type of the None singleton.

var GIGABYTE

The type of the None singleton.

var KILOBYTE

The type of the None singleton.

var MEGABYTE

The type of the None singleton.

class NumeratorMetricType (meta: CommonMetricData)
Expand source code
class NumeratorMetric(NumeratorMetricProtocol):
    
    _handle: ctypes.c_uint64
    def __init__(self, meta: CommonMetricData):
        
        _UniffiFfiConverterTypeCommonMetricData.check_lower(meta)
        _uniffi_lowered_args = (
            _UniffiFfiConverterTypeCommonMetricData.lower(meta),
        )
        _uniffi_lift_return = _UniffiFfiConverterTypeNumeratorMetric.lift
        _uniffi_error_converter = None
        _uniffi_ffi_result = _uniffi_rust_call_with_error(
            _uniffi_error_converter,
            _UniffiLib.uniffi_glean_core_fn_constructor_numeratormetric_new,
            *_uniffi_lowered_args,
        )
        self._handle = _uniffi_ffi_result

    def __del__(self):
        # In case of partial initialization of instances.
        handle = getattr(self, "_handle", None)
        if handle is not None:
            _uniffi_rust_call(_UniffiLib.uniffi_glean_core_fn_free_numeratormetric, handle)

    def _uniffi_clone_handle(self):
        return _uniffi_rust_call(_UniffiLib.uniffi_glean_core_fn_clone_numeratormetric, self._handle)

    # Used by alternative constructors or any methods which return this type.
    @classmethod
    def _uniffi_make_instance(cls, handle):
        # Lightly yucky way to bypass the usual __init__ logic
        # and just create a new instance with the required handle.
        inst = cls.__new__(cls)
        inst._handle = handle
        return inst
    def add_to_numerator(self, amount: int) -> None:
        
        _UniffiFfiConverterInt32.check_lower(amount)
        _uniffi_lowered_args = (
            self._uniffi_clone_handle(),
            _UniffiFfiConverterInt32.lower(amount),
        )
        _uniffi_lift_return = lambda val: None
        _uniffi_error_converter = None
        _uniffi_ffi_result = _uniffi_rust_call_with_error(
            _uniffi_error_converter,
            _UniffiLib.uniffi_glean_core_fn_method_numeratormetric_add_to_numerator,
            *_uniffi_lowered_args,
        )
        return _uniffi_lift_return(_uniffi_ffi_result)
    def test_get_num_recorded_errors(self, error: ErrorType) -> int:
        
        _UniffiFfiConverterTypeErrorType.check_lower(error)
        _uniffi_lowered_args = (
            self._uniffi_clone_handle(),
            _UniffiFfiConverterTypeErrorType.lower(error),
        )
        _uniffi_lift_return = _UniffiFfiConverterInt32.lift
        _uniffi_error_converter = None
        _uniffi_ffi_result = _uniffi_rust_call_with_error(
            _uniffi_error_converter,
            _UniffiLib.uniffi_glean_core_fn_method_numeratormetric_test_get_num_recorded_errors,
            *_uniffi_lowered_args,
        )
        return _uniffi_lift_return(_uniffi_ffi_result)
    def test_get_value(self, ping_name: typing.Union[object, typing.Optional[str]] = _DEFAULT) -> typing.Optional[Rate]:
        
        if ping_name is _DEFAULT:
            ping_name = None
        _UniffiFfiConverterOptionalString.check_lower(ping_name)
        _uniffi_lowered_args = (
            self._uniffi_clone_handle(),
            _UniffiFfiConverterOptionalString.lower(ping_name),
        )
        _uniffi_lift_return = _UniffiFfiConverterOptionalTypeRate.lift
        _uniffi_error_converter = None
        _uniffi_ffi_result = _uniffi_rust_call_with_error(
            _uniffi_error_converter,
            _UniffiLib.uniffi_glean_core_fn_method_numeratormetric_test_get_value,
            *_uniffi_lowered_args,
        )
        return _uniffi_lift_return(_uniffi_ffi_result)

Base class for protocol classes.

Protocol classes are defined as::

class Proto(Protocol):
    def meth(self) -> int:
        ...

Such classes are primarily used with static type checkers that recognize structural subtyping (static duck-typing).

For example::

class C:
    def meth(self) -> int:
        return 0

def func(x: Proto) -> int:
    return x.meth()

func(C())  # Passes static type check

See PEP 544 for details. Protocol classes decorated with @typing.runtime_checkable act as simple-minded runtime protocols that check only the presence of given attributes, ignoring their type signatures. Protocol classes can be generic, they are defined as::

class GenProto[T](Protocol):
    def meth(self) -> T:
        ...

Ancestors

  • glean._uniffi.glean.NumeratorMetricProtocol
  • typing.Protocol
  • typing.Generic

Methods

def add_to_numerator(self, amount: int) ‑> None
Expand source code
def add_to_numerator(self, amount: int) -> None:
    
    _UniffiFfiConverterInt32.check_lower(amount)
    _uniffi_lowered_args = (
        self._uniffi_clone_handle(),
        _UniffiFfiConverterInt32.lower(amount),
    )
    _uniffi_lift_return = lambda val: None
    _uniffi_error_converter = None
    _uniffi_ffi_result = _uniffi_rust_call_with_error(
        _uniffi_error_converter,
        _UniffiLib.uniffi_glean_core_fn_method_numeratormetric_add_to_numerator,
        *_uniffi_lowered_args,
    )
    return _uniffi_lift_return(_uniffi_ffi_result)
def test_get_num_recorded_errors(self, error: ErrorType) ‑> int
Expand source code
def test_get_num_recorded_errors(self, error: ErrorType) -> int:
    
    _UniffiFfiConverterTypeErrorType.check_lower(error)
    _uniffi_lowered_args = (
        self._uniffi_clone_handle(),
        _UniffiFfiConverterTypeErrorType.lower(error),
    )
    _uniffi_lift_return = _UniffiFfiConverterInt32.lift
    _uniffi_error_converter = None
    _uniffi_ffi_result = _uniffi_rust_call_with_error(
        _uniffi_error_converter,
        _UniffiLib.uniffi_glean_core_fn_method_numeratormetric_test_get_num_recorded_errors,
        *_uniffi_lowered_args,
    )
    return _uniffi_lift_return(_uniffi_ffi_result)
def test_get_value(self,
ping_name: typing.Union[glean.metrics.object, typing.Optional[str]] = <object object>) ‑> glean._uniffi.glean.Rate | None
Expand source code
def test_get_value(self, ping_name: typing.Union[object, typing.Optional[str]] = _DEFAULT) -> typing.Optional[Rate]:
    
    if ping_name is _DEFAULT:
        ping_name = None
    _UniffiFfiConverterOptionalString.check_lower(ping_name)
    _uniffi_lowered_args = (
        self._uniffi_clone_handle(),
        _UniffiFfiConverterOptionalString.lower(ping_name),
    )
    _uniffi_lift_return = _UniffiFfiConverterOptionalTypeRate.lift
    _uniffi_error_converter = None
    _uniffi_ffi_result = _uniffi_rust_call_with_error(
        _uniffi_error_converter,
        _UniffiLib.uniffi_glean_core_fn_method_numeratormetric_test_get_value,
        *_uniffi_lowered_args,
    )
    return _uniffi_lift_return(_uniffi_ffi_result)
class ObjectMetricType (common_metric_data: glean._uniffi.glean.CommonMetricData, ty: Any)
Expand source code
class ObjectMetricType(Generic[T]):
    """
    This implements the developer facing API for recording events.

    Instances of this class type are automatically generated by
    `glean.load_metrics`, allowing developers to record values that were
    previously registered in the metrics.yaml file.

    The event API only exposes the `ObjectMetricType.set` method, which
    takes care of validating the input data and making sure that limits are
    enforced.
    """

    def __init__(
        self,
        common_metric_data: CommonMetricData,
        ty: Any,
    ):
        self._inner = ObjectMetric(common_metric_data)
        self._objty = ty

    def set(self, obj: T) -> None:
        """
        Set the object.
        Args:
            extra: optional. The extra keys and values for this event.
                   The maximum length for values is 100.
        """

        if isinstance(obj, self._objty):
            inner_obj = obj.into_serialized_object()
            self._inner.set_string(inner_obj)
        else:
            self._inner.record_schema_error()

    def test_get_value(self, ping_name: Optional[str] = None) -> Optional[dict]:
        """
        Returns the stored value for testing purposes only.

        Args:
            ping_name (str): (default: first value in send_in_pings) The name
                of the ping to retrieve the metric for.

        Returns:
            value (list of RecordedEventData): value of the stored events.
        """
        data = self._inner.test_get_value(ping_name)
        if data:
            return json.loads(data)

        return None

    def test_get_num_recorded_errors(self, error_type: ErrorType) -> int:
        """
        Returns the number of errors recorded for the given metric.

        Args:
            error_type (ErrorType): The type of error recorded.
            ping_name (str): (default: first value in send_in_pings) The name
                of the ping to retrieve the metric for.

        Returns:
            num_errors (int): The number of errors recorded for the metric for
                the given error type.
        """
        return self._inner.test_get_num_recorded_errors(error_type)

This implements the developer facing API for recording events.

Instances of this class type are automatically generated by load_metrics(), allowing developers to record values that were previously registered in the metrics.yaml file.

The event API only exposes the ObjectMetricType.set() method, which takes care of validating the input data and making sure that limits are enforced.

Ancestors

  • typing.Generic

Methods

def set(self, obj: ~T) ‑> None
Expand source code
def set(self, obj: T) -> None:
    """
    Set the object.
    Args:
        extra: optional. The extra keys and values for this event.
               The maximum length for values is 100.
    """

    if isinstance(obj, self._objty):
        inner_obj = obj.into_serialized_object()
        self._inner.set_string(inner_obj)
    else:
        self._inner.record_schema_error()

Set the object.

Args

extra
optional. The extra keys and values for this event. The maximum length for values is 100.
def test_get_num_recorded_errors(self, error_type: glean._uniffi.glean.ErrorType) ‑> int
Expand source code
def test_get_num_recorded_errors(self, error_type: ErrorType) -> int:
    """
    Returns the number of errors recorded for the given metric.

    Args:
        error_type (ErrorType): The type of error recorded.
        ping_name (str): (default: first value in send_in_pings) The name
            of the ping to retrieve the metric for.

    Returns:
        num_errors (int): The number of errors recorded for the metric for
            the given error type.
    """
    return self._inner.test_get_num_recorded_errors(error_type)

Returns the number of errors recorded for the given metric.

Args

error_type : ErrorType
The type of error recorded.
ping_name : str
(default: first value in send_in_pings) The name of the ping to retrieve the metric for.

Returns

num_errors (int): The number of errors recorded for the metric for the given error type.

def test_get_value(self, ping_name: str | None = None) ‑> dict | None
Expand source code
def test_get_value(self, ping_name: Optional[str] = None) -> Optional[dict]:
    """
    Returns the stored value for testing purposes only.

    Args:
        ping_name (str): (default: first value in send_in_pings) The name
            of the ping to retrieve the metric for.

    Returns:
        value (list of RecordedEventData): value of the stored events.
    """
    data = self._inner.test_get_value(ping_name)
    if data:
        return json.loads(data)

    return None

Returns the stored value for testing purposes only.

Args

ping_name : str
(default: first value in send_in_pings) The name of the ping to retrieve the metric for.

Returns

value (list of RecordedEventData): value of the stored events.

class ObjectSerialize
Expand source code
class ObjectSerialize:
    """
    A class that can be converted into key-value pairs of event extras.
    This will be automatically implemented for event properties of an [ObjectMetricType].
    """

    def into_serialized_object(self) -> str:
        """
        Convert the event extras into a key-value dict:
        """
        return json.dumps(self, cls=EncodeObject)

A class that can be converted into key-value pairs of event extras. This will be automatically implemented for event properties of an [ObjectMetricType].

Methods

def into_serialized_object(self) ‑> str
Expand source code
def into_serialized_object(self) -> str:
    """
    Convert the event extras into a key-value dict:
    """
    return json.dumps(self, cls=EncodeObject)

Convert the event extras into a key-value dict:

class PingType (name: str,
include_client_id: bool,
send_if_empty: bool,
precise_timestamps: bool,
include_info_sections: bool,
schedules_pings: List[str],
reason_codes: List[str],
uploader_capabilities: List[str],
enabled: bool = True,
follows_collection_enabled: bool = True)
Expand source code
class PingType:
    def __init__(
        self,
        name: str,
        include_client_id: bool,
        send_if_empty: bool,
        precise_timestamps: bool,
        include_info_sections: bool,
        schedules_pings: List[str],
        reason_codes: List[str],
        uploader_capabilities: List[str],
        enabled: bool = True,
        follows_collection_enabled: bool = True,
    ):
        """
        This implements the developer facing API for custom pings.

        The Ping API only exposes the `PingType.submit` method, which schedules a
        ping for eventual uploading.
        """
        self._reason_codes = reason_codes
        self._inner = GleanPingType(
            name,
            include_client_id,
            send_if_empty,
            precise_timestamps,
            include_info_sections,
            enabled,
            schedules_pings,
            reason_codes,
            follows_collection_enabled,
            uploader_capabilities,
        )
        self._test_callback = None  # type: Optional[Callable[[Optional[str]], None]]

    def test_before_next_submit(self, cb: Callable[[Optional[str]], None]):
        """
        **Test-only API**

        Attach a callback to be called right before a new ping is submitted.
        The provided function is called exactly once before submitting a ping.

        Note: The callback will be called on any call to submit.
        A ping might not be sent afterwards, e.g. if the ping is otherwise empty (and
        `send_if_empty` is `False`).
        """
        self._test_callback = cb

    def submit(self, reason: Optional[int] = None) -> None:
        """
        Collect and submit the ping for eventual uploading.

        If the ping currently contains no content, it will not be sent.

        Args:
            reason (enum, optional): The reason the ping was submitted.
        """
        reason_string: Optional[str] = None
        if reason is not None:
            reason_string = self._reason_codes[reason]
        else:
            reason_string = None

        if self._test_callback is not None:
            self._test_callback(reason_string)
            self._test_callback = None

        self._inner.submit(reason_string)

    def set_enabled(self, enabled: bool) -> None:
        """
        Enable or disable a ping.

        Disabling a ping causes all data for that ping to be removed from storage
        and all pending pings of that type to be deleted.
        """
        self._inner.set_enabled(enabled)

This implements the developer facing API for custom pings.

The Ping API only exposes the PingType.submit() method, which schedules a ping for eventual uploading.

Methods

def set_enabled(self, enabled: bool) ‑> None
Expand source code
def set_enabled(self, enabled: bool) -> None:
    """
    Enable or disable a ping.

    Disabling a ping causes all data for that ping to be removed from storage
    and all pending pings of that type to be deleted.
    """
    self._inner.set_enabled(enabled)

Enable or disable a ping.

Disabling a ping causes all data for that ping to be removed from storage and all pending pings of that type to be deleted.

def submit(self, reason: int | None = None) ‑> None
Expand source code
def submit(self, reason: Optional[int] = None) -> None:
    """
    Collect and submit the ping for eventual uploading.

    If the ping currently contains no content, it will not be sent.

    Args:
        reason (enum, optional): The reason the ping was submitted.
    """
    reason_string: Optional[str] = None
    if reason is not None:
        reason_string = self._reason_codes[reason]
    else:
        reason_string = None

    if self._test_callback is not None:
        self._test_callback(reason_string)
        self._test_callback = None

    self._inner.submit(reason_string)

Collect and submit the ping for eventual uploading.

If the ping currently contains no content, it will not be sent.

Args

reason : enum, optional
The reason the ping was submitted.
def test_before_next_submit(self, cb: Callable[[str | None], None])
Expand source code
def test_before_next_submit(self, cb: Callable[[Optional[str]], None]):
    """
    **Test-only API**

    Attach a callback to be called right before a new ping is submitted.
    The provided function is called exactly once before submitting a ping.

    Note: The callback will be called on any call to submit.
    A ping might not be sent afterwards, e.g. if the ping is otherwise empty (and
    `send_if_empty` is `False`).
    """
    self._test_callback = cb

Test-only API

Attach a callback to be called right before a new ping is submitted. The provided function is called exactly once before submitting a ping.

Note: The callback will be called on any call to submit. A ping might not be sent afterwards, e.g. if the ping is otherwise empty (and send_if_empty is False).

class QuantityMetricType (meta: CommonMetricData)
Expand source code
class QuantityMetric(QuantityMetricProtocol):
    
    _handle: ctypes.c_uint64
    def __init__(self, meta: CommonMetricData):
        
        _UniffiFfiConverterTypeCommonMetricData.check_lower(meta)
        _uniffi_lowered_args = (
            _UniffiFfiConverterTypeCommonMetricData.lower(meta),
        )
        _uniffi_lift_return = _UniffiFfiConverterTypeQuantityMetric.lift
        _uniffi_error_converter = None
        _uniffi_ffi_result = _uniffi_rust_call_with_error(
            _uniffi_error_converter,
            _UniffiLib.uniffi_glean_core_fn_constructor_quantitymetric_new,
            *_uniffi_lowered_args,
        )
        self._handle = _uniffi_ffi_result

    def __del__(self):
        # In case of partial initialization of instances.
        handle = getattr(self, "_handle", None)
        if handle is not None:
            _uniffi_rust_call(_UniffiLib.uniffi_glean_core_fn_free_quantitymetric, handle)

    def _uniffi_clone_handle(self):
        return _uniffi_rust_call(_UniffiLib.uniffi_glean_core_fn_clone_quantitymetric, self._handle)

    # Used by alternative constructors or any methods which return this type.
    @classmethod
    def _uniffi_make_instance(cls, handle):
        # Lightly yucky way to bypass the usual __init__ logic
        # and just create a new instance with the required handle.
        inst = cls.__new__(cls)
        inst._handle = handle
        return inst
    def set(self, value: int) -> None:
        
        _UniffiFfiConverterInt64.check_lower(value)
        _uniffi_lowered_args = (
            self._uniffi_clone_handle(),
            _UniffiFfiConverterInt64.lower(value),
        )
        _uniffi_lift_return = lambda val: None
        _uniffi_error_converter = None
        _uniffi_ffi_result = _uniffi_rust_call_with_error(
            _uniffi_error_converter,
            _UniffiLib.uniffi_glean_core_fn_method_quantitymetric_set,
            *_uniffi_lowered_args,
        )
        return _uniffi_lift_return(_uniffi_ffi_result)
    def test_get_num_recorded_errors(self, error: ErrorType) -> int:
        
        _UniffiFfiConverterTypeErrorType.check_lower(error)
        _uniffi_lowered_args = (
            self._uniffi_clone_handle(),
            _UniffiFfiConverterTypeErrorType.lower(error),
        )
        _uniffi_lift_return = _UniffiFfiConverterInt32.lift
        _uniffi_error_converter = None
        _uniffi_ffi_result = _uniffi_rust_call_with_error(
            _uniffi_error_converter,
            _UniffiLib.uniffi_glean_core_fn_method_quantitymetric_test_get_num_recorded_errors,
            *_uniffi_lowered_args,
        )
        return _uniffi_lift_return(_uniffi_ffi_result)
    def test_get_value(self, ping_name: typing.Union[object, typing.Optional[str]] = _DEFAULT) -> typing.Optional[int]:
        
        if ping_name is _DEFAULT:
            ping_name = None
        _UniffiFfiConverterOptionalString.check_lower(ping_name)
        _uniffi_lowered_args = (
            self._uniffi_clone_handle(),
            _UniffiFfiConverterOptionalString.lower(ping_name),
        )
        _uniffi_lift_return = _UniffiFfiConverterOptionalInt64.lift
        _uniffi_error_converter = None
        _uniffi_ffi_result = _uniffi_rust_call_with_error(
            _uniffi_error_converter,
            _UniffiLib.uniffi_glean_core_fn_method_quantitymetric_test_get_value,
            *_uniffi_lowered_args,
        )
        return _uniffi_lift_return(_uniffi_ffi_result)

Base class for protocol classes.

Protocol classes are defined as::

class Proto(Protocol):
    def meth(self) -> int:
        ...

Such classes are primarily used with static type checkers that recognize structural subtyping (static duck-typing).

For example::

class C:
    def meth(self) -> int:
        return 0

def func(x: Proto) -> int:
    return x.meth()

func(C())  # Passes static type check

See PEP 544 for details. Protocol classes decorated with @typing.runtime_checkable act as simple-minded runtime protocols that check only the presence of given attributes, ignoring their type signatures. Protocol classes can be generic, they are defined as::

class GenProto[T](Protocol):
    def meth(self) -> T:
        ...

Ancestors

  • glean._uniffi.glean.QuantityMetricProtocol
  • typing.Protocol
  • typing.Generic

Methods

def set(self, value: int) ‑> None
Expand source code
def set(self, value: int) -> None:
    
    _UniffiFfiConverterInt64.check_lower(value)
    _uniffi_lowered_args = (
        self._uniffi_clone_handle(),
        _UniffiFfiConverterInt64.lower(value),
    )
    _uniffi_lift_return = lambda val: None
    _uniffi_error_converter = None
    _uniffi_ffi_result = _uniffi_rust_call_with_error(
        _uniffi_error_converter,
        _UniffiLib.uniffi_glean_core_fn_method_quantitymetric_set,
        *_uniffi_lowered_args,
    )
    return _uniffi_lift_return(_uniffi_ffi_result)
def test_get_num_recorded_errors(self, error: ErrorType) ‑> int
Expand source code
def test_get_num_recorded_errors(self, error: ErrorType) -> int:
    
    _UniffiFfiConverterTypeErrorType.check_lower(error)
    _uniffi_lowered_args = (
        self._uniffi_clone_handle(),
        _UniffiFfiConverterTypeErrorType.lower(error),
    )
    _uniffi_lift_return = _UniffiFfiConverterInt32.lift
    _uniffi_error_converter = None
    _uniffi_ffi_result = _uniffi_rust_call_with_error(
        _uniffi_error_converter,
        _UniffiLib.uniffi_glean_core_fn_method_quantitymetric_test_get_num_recorded_errors,
        *_uniffi_lowered_args,
    )
    return _uniffi_lift_return(_uniffi_ffi_result)
def test_get_value(self,
ping_name: typing.Union[glean.metrics.object, typing.Optional[str]] = <object object>) ‑> int | None
Expand source code
def test_get_value(self, ping_name: typing.Union[object, typing.Optional[str]] = _DEFAULT) -> typing.Optional[int]:
    
    if ping_name is _DEFAULT:
        ping_name = None
    _UniffiFfiConverterOptionalString.check_lower(ping_name)
    _uniffi_lowered_args = (
        self._uniffi_clone_handle(),
        _UniffiFfiConverterOptionalString.lower(ping_name),
    )
    _uniffi_lift_return = _UniffiFfiConverterOptionalInt64.lift
    _uniffi_error_converter = None
    _uniffi_ffi_result = _uniffi_rust_call_with_error(
        _uniffi_error_converter,
        _UniffiLib.uniffi_glean_core_fn_method_quantitymetric_test_get_value,
        *_uniffi_lowered_args,
    )
    return _uniffi_lift_return(_uniffi_ffi_result)
class RateMetricType (meta: CommonMetricData)
Expand source code
class RateMetric(RateMetricProtocol):
    
    _handle: ctypes.c_uint64
    def __init__(self, meta: CommonMetricData):
        
        _UniffiFfiConverterTypeCommonMetricData.check_lower(meta)
        _uniffi_lowered_args = (
            _UniffiFfiConverterTypeCommonMetricData.lower(meta),
        )
        _uniffi_lift_return = _UniffiFfiConverterTypeRateMetric.lift
        _uniffi_error_converter = None
        _uniffi_ffi_result = _uniffi_rust_call_with_error(
            _uniffi_error_converter,
            _UniffiLib.uniffi_glean_core_fn_constructor_ratemetric_new,
            *_uniffi_lowered_args,
        )
        self._handle = _uniffi_ffi_result

    def __del__(self):
        # In case of partial initialization of instances.
        handle = getattr(self, "_handle", None)
        if handle is not None:
            _uniffi_rust_call(_UniffiLib.uniffi_glean_core_fn_free_ratemetric, handle)

    def _uniffi_clone_handle(self):
        return _uniffi_rust_call(_UniffiLib.uniffi_glean_core_fn_clone_ratemetric, self._handle)

    # Used by alternative constructors or any methods which return this type.
    @classmethod
    def _uniffi_make_instance(cls, handle):
        # Lightly yucky way to bypass the usual __init__ logic
        # and just create a new instance with the required handle.
        inst = cls.__new__(cls)
        inst._handle = handle
        return inst
    def add_to_denominator(self, amount: int) -> None:
        
        _UniffiFfiConverterInt32.check_lower(amount)
        _uniffi_lowered_args = (
            self._uniffi_clone_handle(),
            _UniffiFfiConverterInt32.lower(amount),
        )
        _uniffi_lift_return = lambda val: None
        _uniffi_error_converter = None
        _uniffi_ffi_result = _uniffi_rust_call_with_error(
            _uniffi_error_converter,
            _UniffiLib.uniffi_glean_core_fn_method_ratemetric_add_to_denominator,
            *_uniffi_lowered_args,
        )
        return _uniffi_lift_return(_uniffi_ffi_result)
    def add_to_numerator(self, amount: int) -> None:
        
        _UniffiFfiConverterInt32.check_lower(amount)
        _uniffi_lowered_args = (
            self._uniffi_clone_handle(),
            _UniffiFfiConverterInt32.lower(amount),
        )
        _uniffi_lift_return = lambda val: None
        _uniffi_error_converter = None
        _uniffi_ffi_result = _uniffi_rust_call_with_error(
            _uniffi_error_converter,
            _UniffiLib.uniffi_glean_core_fn_method_ratemetric_add_to_numerator,
            *_uniffi_lowered_args,
        )
        return _uniffi_lift_return(_uniffi_ffi_result)
    def test_get_num_recorded_errors(self, error: ErrorType) -> int:
        
        _UniffiFfiConverterTypeErrorType.check_lower(error)
        _uniffi_lowered_args = (
            self._uniffi_clone_handle(),
            _UniffiFfiConverterTypeErrorType.lower(error),
        )
        _uniffi_lift_return = _UniffiFfiConverterInt32.lift
        _uniffi_error_converter = None
        _uniffi_ffi_result = _uniffi_rust_call_with_error(
            _uniffi_error_converter,
            _UniffiLib.uniffi_glean_core_fn_method_ratemetric_test_get_num_recorded_errors,
            *_uniffi_lowered_args,
        )
        return _uniffi_lift_return(_uniffi_ffi_result)
    def test_get_value(self, ping_name: typing.Union[object, typing.Optional[str]] = _DEFAULT) -> typing.Optional[Rate]:
        
        if ping_name is _DEFAULT:
            ping_name = None
        _UniffiFfiConverterOptionalString.check_lower(ping_name)
        _uniffi_lowered_args = (
            self._uniffi_clone_handle(),
            _UniffiFfiConverterOptionalString.lower(ping_name),
        )
        _uniffi_lift_return = _UniffiFfiConverterOptionalTypeRate.lift
        _uniffi_error_converter = None
        _uniffi_ffi_result = _uniffi_rust_call_with_error(
            _uniffi_error_converter,
            _UniffiLib.uniffi_glean_core_fn_method_ratemetric_test_get_value,
            *_uniffi_lowered_args,
        )
        return _uniffi_lift_return(_uniffi_ffi_result)

Base class for protocol classes.

Protocol classes are defined as::

class Proto(Protocol):
    def meth(self) -> int:
        ...

Such classes are primarily used with static type checkers that recognize structural subtyping (static duck-typing).

For example::

class C:
    def meth(self) -> int:
        return 0

def func(x: Proto) -> int:
    return x.meth()

func(C())  # Passes static type check

See PEP 544 for details. Protocol classes decorated with @typing.runtime_checkable act as simple-minded runtime protocols that check only the presence of given attributes, ignoring their type signatures. Protocol classes can be generic, they are defined as::

class GenProto[T](Protocol):
    def meth(self) -> T:
        ...

Ancestors

  • glean._uniffi.glean.RateMetricProtocol
  • typing.Protocol
  • typing.Generic

Methods

def add_to_denominator(self, amount: int) ‑> None
Expand source code
def add_to_denominator(self, amount: int) -> None:
    
    _UniffiFfiConverterInt32.check_lower(amount)
    _uniffi_lowered_args = (
        self._uniffi_clone_handle(),
        _UniffiFfiConverterInt32.lower(amount),
    )
    _uniffi_lift_return = lambda val: None
    _uniffi_error_converter = None
    _uniffi_ffi_result = _uniffi_rust_call_with_error(
        _uniffi_error_converter,
        _UniffiLib.uniffi_glean_core_fn_method_ratemetric_add_to_denominator,
        *_uniffi_lowered_args,
    )
    return _uniffi_lift_return(_uniffi_ffi_result)
def add_to_numerator(self, amount: int) ‑> None
Expand source code
def add_to_numerator(self, amount: int) -> None:
    
    _UniffiFfiConverterInt32.check_lower(amount)
    _uniffi_lowered_args = (
        self._uniffi_clone_handle(),
        _UniffiFfiConverterInt32.lower(amount),
    )
    _uniffi_lift_return = lambda val: None
    _uniffi_error_converter = None
    _uniffi_ffi_result = _uniffi_rust_call_with_error(
        _uniffi_error_converter,
        _UniffiLib.uniffi_glean_core_fn_method_ratemetric_add_to_numerator,
        *_uniffi_lowered_args,
    )
    return _uniffi_lift_return(_uniffi_ffi_result)
def test_get_num_recorded_errors(self, error: ErrorType) ‑> int
Expand source code
def test_get_num_recorded_errors(self, error: ErrorType) -> int:
    
    _UniffiFfiConverterTypeErrorType.check_lower(error)
    _uniffi_lowered_args = (
        self._uniffi_clone_handle(),
        _UniffiFfiConverterTypeErrorType.lower(error),
    )
    _uniffi_lift_return = _UniffiFfiConverterInt32.lift
    _uniffi_error_converter = None
    _uniffi_ffi_result = _uniffi_rust_call_with_error(
        _uniffi_error_converter,
        _UniffiLib.uniffi_glean_core_fn_method_ratemetric_test_get_num_recorded_errors,
        *_uniffi_lowered_args,
    )
    return _uniffi_lift_return(_uniffi_ffi_result)
def test_get_value(self,
ping_name: typing.Union[glean.metrics.object, typing.Optional[str]] = <object object>) ‑> glean._uniffi.glean.Rate | None
Expand source code
def test_get_value(self, ping_name: typing.Union[object, typing.Optional[str]] = _DEFAULT) -> typing.Optional[Rate]:
    
    if ping_name is _DEFAULT:
        ping_name = None
    _UniffiFfiConverterOptionalString.check_lower(ping_name)
    _uniffi_lowered_args = (
        self._uniffi_clone_handle(),
        _UniffiFfiConverterOptionalString.lower(ping_name),
    )
    _uniffi_lift_return = _UniffiFfiConverterOptionalTypeRate.lift
    _uniffi_error_converter = None
    _uniffi_ffi_result = _uniffi_rust_call_with_error(
        _uniffi_error_converter,
        _UniffiLib.uniffi_glean_core_fn_method_ratemetric_test_get_value,
        *_uniffi_lowered_args,
    )
    return _uniffi_lift_return(_uniffi_ffi_result)
class RecordedEvent (*, timestamp: int, category: str, name: str, extra: typing.Optional[dict[str, str]])
Expand source code
@dataclass
class RecordedEvent:
    def __init__(self, *, timestamp:int, category:str, name:str, extra:typing.Optional[dict[str, str]]):
        self.timestamp = timestamp
        self.category = category
        self.name = name
        self.extra = extra
        
        

    
    def __str__(self):
        return "RecordedEvent(timestamp={}, category={}, name={}, extra={})".format(self.timestamp, self.category, self.name, self.extra)
    def __eq__(self, other):
        if self.timestamp != other.timestamp:
            return False
        if self.category != other.category:
            return False
        if self.name != other.name:
            return False
        if self.extra != other.extra:
            return False
        return True

RecordedEvent(*, timestamp: 'int', category: 'str', name: 'str', extra: 'typing.Optional[dict[str, str]]')

class RecordedExperiment (*, branch: str, extra: typing.Optional[dict[str, str]])
Expand source code
@dataclass
class RecordedExperiment:
    def __init__(self, *, branch:str, extra:typing.Optional[dict[str, str]]):
        self.branch = branch
        self.extra = extra
        
        

    
    def __str__(self):
        return "RecordedExperiment(branch={}, extra={})".format(self.branch, self.extra)
    def __eq__(self, other):
        if self.branch != other.branch:
            return False
        if self.extra != other.extra:
            return False
        return True

RecordedExperiment(*, branch: 'str', extra: 'typing.Optional[dict[str, str]]')

class StringListMetricType (meta: CommonMetricData)
Expand source code
class StringListMetric(StringListMetricProtocol):
    
    _handle: ctypes.c_uint64
    def __init__(self, meta: CommonMetricData):
        
        _UniffiFfiConverterTypeCommonMetricData.check_lower(meta)
        _uniffi_lowered_args = (
            _UniffiFfiConverterTypeCommonMetricData.lower(meta),
        )
        _uniffi_lift_return = _UniffiFfiConverterTypeStringListMetric.lift
        _uniffi_error_converter = None
        _uniffi_ffi_result = _uniffi_rust_call_with_error(
            _uniffi_error_converter,
            _UniffiLib.uniffi_glean_core_fn_constructor_stringlistmetric_new,
            *_uniffi_lowered_args,
        )
        self._handle = _uniffi_ffi_result

    def __del__(self):
        # In case of partial initialization of instances.
        handle = getattr(self, "_handle", None)
        if handle is not None:
            _uniffi_rust_call(_UniffiLib.uniffi_glean_core_fn_free_stringlistmetric, handle)

    def _uniffi_clone_handle(self):
        return _uniffi_rust_call(_UniffiLib.uniffi_glean_core_fn_clone_stringlistmetric, self._handle)

    # Used by alternative constructors or any methods which return this type.
    @classmethod
    def _uniffi_make_instance(cls, handle):
        # Lightly yucky way to bypass the usual __init__ logic
        # and just create a new instance with the required handle.
        inst = cls.__new__(cls)
        inst._handle = handle
        return inst
    def add(self, value: str) -> None:
        
        _UniffiFfiConverterString.check_lower(value)
        _uniffi_lowered_args = (
            self._uniffi_clone_handle(),
            _UniffiFfiConverterString.lower(value),
        )
        _uniffi_lift_return = lambda val: None
        _uniffi_error_converter = None
        _uniffi_ffi_result = _uniffi_rust_call_with_error(
            _uniffi_error_converter,
            _UniffiLib.uniffi_glean_core_fn_method_stringlistmetric_add,
            *_uniffi_lowered_args,
        )
        return _uniffi_lift_return(_uniffi_ffi_result)
    def set(self, value: typing.List[str]) -> None:
        
        _UniffiFfiConverterSequenceString.check_lower(value)
        _uniffi_lowered_args = (
            self._uniffi_clone_handle(),
            _UniffiFfiConverterSequenceString.lower(value),
        )
        _uniffi_lift_return = lambda val: None
        _uniffi_error_converter = None
        _uniffi_ffi_result = _uniffi_rust_call_with_error(
            _uniffi_error_converter,
            _UniffiLib.uniffi_glean_core_fn_method_stringlistmetric_set,
            *_uniffi_lowered_args,
        )
        return _uniffi_lift_return(_uniffi_ffi_result)
    def test_get_num_recorded_errors(self, error: ErrorType) -> int:
        
        _UniffiFfiConverterTypeErrorType.check_lower(error)
        _uniffi_lowered_args = (
            self._uniffi_clone_handle(),
            _UniffiFfiConverterTypeErrorType.lower(error),
        )
        _uniffi_lift_return = _UniffiFfiConverterInt32.lift
        _uniffi_error_converter = None
        _uniffi_ffi_result = _uniffi_rust_call_with_error(
            _uniffi_error_converter,
            _UniffiLib.uniffi_glean_core_fn_method_stringlistmetric_test_get_num_recorded_errors,
            *_uniffi_lowered_args,
        )
        return _uniffi_lift_return(_uniffi_ffi_result)
    def test_get_value(self, ping_name: typing.Union[object, typing.Optional[str]] = _DEFAULT) -> typing.Optional[typing.List[str]]:
        
        if ping_name is _DEFAULT:
            ping_name = None
        _UniffiFfiConverterOptionalString.check_lower(ping_name)
        _uniffi_lowered_args = (
            self._uniffi_clone_handle(),
            _UniffiFfiConverterOptionalString.lower(ping_name),
        )
        _uniffi_lift_return = _UniffiFfiConverterOptionalSequenceString.lift
        _uniffi_error_converter = None
        _uniffi_ffi_result = _uniffi_rust_call_with_error(
            _uniffi_error_converter,
            _UniffiLib.uniffi_glean_core_fn_method_stringlistmetric_test_get_value,
            *_uniffi_lowered_args,
        )
        return _uniffi_lift_return(_uniffi_ffi_result)

Base class for protocol classes.

Protocol classes are defined as::

class Proto(Protocol):
    def meth(self) -> int:
        ...

Such classes are primarily used with static type checkers that recognize structural subtyping (static duck-typing).

For example::

class C:
    def meth(self) -> int:
        return 0

def func(x: Proto) -> int:
    return x.meth()

func(C())  # Passes static type check

See PEP 544 for details. Protocol classes decorated with @typing.runtime_checkable act as simple-minded runtime protocols that check only the presence of given attributes, ignoring their type signatures. Protocol classes can be generic, they are defined as::

class GenProto[T](Protocol):
    def meth(self) -> T:
        ...

Ancestors

  • glean._uniffi.glean.StringListMetricProtocol
  • typing.Protocol
  • typing.Generic

Methods

def add(self, value: str) ‑> None
Expand source code
def add(self, value: str) -> None:
    
    _UniffiFfiConverterString.check_lower(value)
    _uniffi_lowered_args = (
        self._uniffi_clone_handle(),
        _UniffiFfiConverterString.lower(value),
    )
    _uniffi_lift_return = lambda val: None
    _uniffi_error_converter = None
    _uniffi_ffi_result = _uniffi_rust_call_with_error(
        _uniffi_error_converter,
        _UniffiLib.uniffi_glean_core_fn_method_stringlistmetric_add,
        *_uniffi_lowered_args,
    )
    return _uniffi_lift_return(_uniffi_ffi_result)
def set(self, value: typing.List[str]) ‑> None
Expand source code
def set(self, value: typing.List[str]) -> None:
    
    _UniffiFfiConverterSequenceString.check_lower(value)
    _uniffi_lowered_args = (
        self._uniffi_clone_handle(),
        _UniffiFfiConverterSequenceString.lower(value),
    )
    _uniffi_lift_return = lambda val: None
    _uniffi_error_converter = None
    _uniffi_ffi_result = _uniffi_rust_call_with_error(
        _uniffi_error_converter,
        _UniffiLib.uniffi_glean_core_fn_method_stringlistmetric_set,
        *_uniffi_lowered_args,
    )
    return _uniffi_lift_return(_uniffi_ffi_result)
def test_get_num_recorded_errors(self, error: ErrorType) ‑> int
Expand source code
def test_get_num_recorded_errors(self, error: ErrorType) -> int:
    
    _UniffiFfiConverterTypeErrorType.check_lower(error)
    _uniffi_lowered_args = (
        self._uniffi_clone_handle(),
        _UniffiFfiConverterTypeErrorType.lower(error),
    )
    _uniffi_lift_return = _UniffiFfiConverterInt32.lift
    _uniffi_error_converter = None
    _uniffi_ffi_result = _uniffi_rust_call_with_error(
        _uniffi_error_converter,
        _UniffiLib.uniffi_glean_core_fn_method_stringlistmetric_test_get_num_recorded_errors,
        *_uniffi_lowered_args,
    )
    return _uniffi_lift_return(_uniffi_ffi_result)
def test_get_value(self,
ping_name: typing.Union[glean.metrics.object, typing.Optional[str]] = <object object>) ‑> List[str] | None
Expand source code
def test_get_value(self, ping_name: typing.Union[object, typing.Optional[str]] = _DEFAULT) -> typing.Optional[typing.List[str]]:
    
    if ping_name is _DEFAULT:
        ping_name = None
    _UniffiFfiConverterOptionalString.check_lower(ping_name)
    _uniffi_lowered_args = (
        self._uniffi_clone_handle(),
        _UniffiFfiConverterOptionalString.lower(ping_name),
    )
    _uniffi_lift_return = _UniffiFfiConverterOptionalSequenceString.lift
    _uniffi_error_converter = None
    _uniffi_ffi_result = _uniffi_rust_call_with_error(
        _uniffi_error_converter,
        _UniffiLib.uniffi_glean_core_fn_method_stringlistmetric_test_get_value,
        *_uniffi_lowered_args,
    )
    return _uniffi_lift_return(_uniffi_ffi_result)
class StringMetricType (common_metric_data: glean._uniffi.glean.CommonMetricData)
Expand source code
class StringMetricType:
    """
    This implements the developer facing API for recording string metrics.

    Instances of this class type are automatically generated by
    `glean.load_metrics`, allowing developers to record values that were
    previously registered in the metrics.yaml file.

    The string API only exposes the `StringMetricType.set` method, which
    takes care of validating the input data and making sure that limits are
    enforced.
    """

    def __init__(self, common_metric_data: CommonMetricData):
        self._inner = StringMetric(common_metric_data)

    def set(self, value: str) -> None:
        """
        Set a string value.

        Args:
            value (str): This is a user-defined string value. If the length of
                the string exceeds the maximum length, it will be truncated.
        """
        if value is None:
            return

        self._inner.set(value)

    def test_get_value(self, ping_name: Optional[str] = None) -> Optional[str]:
        return self._inner.test_get_value(ping_name)

    def test_get_num_recorded_errors(self, error_type: ErrorType) -> int:
        return self._inner.test_get_num_recorded_errors(error_type)

This implements the developer facing API for recording string metrics.

Instances of this class type are automatically generated by load_metrics(), allowing developers to record values that were previously registered in the metrics.yaml file.

The string API only exposes the StringMetricType.set() method, which takes care of validating the input data and making sure that limits are enforced.

Methods

def set(self, value: str) ‑> None
Expand source code
def set(self, value: str) -> None:
    """
    Set a string value.

    Args:
        value (str): This is a user-defined string value. If the length of
            the string exceeds the maximum length, it will be truncated.
    """
    if value is None:
        return

    self._inner.set(value)

Set a string value.

Args

value : str
This is a user-defined string value. If the length of the string exceeds the maximum length, it will be truncated.
def test_get_num_recorded_errors(self, error_type: glean._uniffi.glean.ErrorType) ‑> int
Expand source code
def test_get_num_recorded_errors(self, error_type: ErrorType) -> int:
    return self._inner.test_get_num_recorded_errors(error_type)
def test_get_value(self, ping_name: str | None = None) ‑> str | None
Expand source code
def test_get_value(self, ping_name: Optional[str] = None) -> Optional[str]:
    return self._inner.test_get_value(ping_name)
class TextMetricType (meta: CommonMetricData)
Expand source code
class TextMetric(TextMetricProtocol):
    
    _handle: ctypes.c_uint64
    def __init__(self, meta: CommonMetricData):
        
        _UniffiFfiConverterTypeCommonMetricData.check_lower(meta)
        _uniffi_lowered_args = (
            _UniffiFfiConverterTypeCommonMetricData.lower(meta),
        )
        _uniffi_lift_return = _UniffiFfiConverterTypeTextMetric.lift
        _uniffi_error_converter = None
        _uniffi_ffi_result = _uniffi_rust_call_with_error(
            _uniffi_error_converter,
            _UniffiLib.uniffi_glean_core_fn_constructor_textmetric_new,
            *_uniffi_lowered_args,
        )
        self._handle = _uniffi_ffi_result

    def __del__(self):
        # In case of partial initialization of instances.
        handle = getattr(self, "_handle", None)
        if handle is not None:
            _uniffi_rust_call(_UniffiLib.uniffi_glean_core_fn_free_textmetric, handle)

    def _uniffi_clone_handle(self):
        return _uniffi_rust_call(_UniffiLib.uniffi_glean_core_fn_clone_textmetric, self._handle)

    # Used by alternative constructors or any methods which return this type.
    @classmethod
    def _uniffi_make_instance(cls, handle):
        # Lightly yucky way to bypass the usual __init__ logic
        # and just create a new instance with the required handle.
        inst = cls.__new__(cls)
        inst._handle = handle
        return inst
    def set(self, value: str) -> None:
        
        _UniffiFfiConverterString.check_lower(value)
        _uniffi_lowered_args = (
            self._uniffi_clone_handle(),
            _UniffiFfiConverterString.lower(value),
        )
        _uniffi_lift_return = lambda val: None
        _uniffi_error_converter = None
        _uniffi_ffi_result = _uniffi_rust_call_with_error(
            _uniffi_error_converter,
            _UniffiLib.uniffi_glean_core_fn_method_textmetric_set,
            *_uniffi_lowered_args,
        )
        return _uniffi_lift_return(_uniffi_ffi_result)
    def test_get_num_recorded_errors(self, error: ErrorType) -> int:
        
        _UniffiFfiConverterTypeErrorType.check_lower(error)
        _uniffi_lowered_args = (
            self._uniffi_clone_handle(),
            _UniffiFfiConverterTypeErrorType.lower(error),
        )
        _uniffi_lift_return = _UniffiFfiConverterInt32.lift
        _uniffi_error_converter = None
        _uniffi_ffi_result = _uniffi_rust_call_with_error(
            _uniffi_error_converter,
            _UniffiLib.uniffi_glean_core_fn_method_textmetric_test_get_num_recorded_errors,
            *_uniffi_lowered_args,
        )
        return _uniffi_lift_return(_uniffi_ffi_result)
    def test_get_value(self, ping_name: typing.Union[object, typing.Optional[str]] = _DEFAULT) -> typing.Optional[str]:
        
        if ping_name is _DEFAULT:
            ping_name = None
        _UniffiFfiConverterOptionalString.check_lower(ping_name)
        _uniffi_lowered_args = (
            self._uniffi_clone_handle(),
            _UniffiFfiConverterOptionalString.lower(ping_name),
        )
        _uniffi_lift_return = _UniffiFfiConverterOptionalString.lift
        _uniffi_error_converter = None
        _uniffi_ffi_result = _uniffi_rust_call_with_error(
            _uniffi_error_converter,
            _UniffiLib.uniffi_glean_core_fn_method_textmetric_test_get_value,
            *_uniffi_lowered_args,
        )
        return _uniffi_lift_return(_uniffi_ffi_result)

Base class for protocol classes.

Protocol classes are defined as::

class Proto(Protocol):
    def meth(self) -> int:
        ...

Such classes are primarily used with static type checkers that recognize structural subtyping (static duck-typing).

For example::

class C:
    def meth(self) -> int:
        return 0

def func(x: Proto) -> int:
    return x.meth()

func(C())  # Passes static type check

See PEP 544 for details. Protocol classes decorated with @typing.runtime_checkable act as simple-minded runtime protocols that check only the presence of given attributes, ignoring their type signatures. Protocol classes can be generic, they are defined as::

class GenProto[T](Protocol):
    def meth(self) -> T:
        ...

Ancestors

  • glean._uniffi.glean.TextMetricProtocol
  • typing.Protocol
  • typing.Generic

Methods

def set(self, value: str) ‑> None
Expand source code
def set(self, value: str) -> None:
    
    _UniffiFfiConverterString.check_lower(value)
    _uniffi_lowered_args = (
        self._uniffi_clone_handle(),
        _UniffiFfiConverterString.lower(value),
    )
    _uniffi_lift_return = lambda val: None
    _uniffi_error_converter = None
    _uniffi_ffi_result = _uniffi_rust_call_with_error(
        _uniffi_error_converter,
        _UniffiLib.uniffi_glean_core_fn_method_textmetric_set,
        *_uniffi_lowered_args,
    )
    return _uniffi_lift_return(_uniffi_ffi_result)
def test_get_num_recorded_errors(self, error: ErrorType) ‑> int
Expand source code
def test_get_num_recorded_errors(self, error: ErrorType) -> int:
    
    _UniffiFfiConverterTypeErrorType.check_lower(error)
    _uniffi_lowered_args = (
        self._uniffi_clone_handle(),
        _UniffiFfiConverterTypeErrorType.lower(error),
    )
    _uniffi_lift_return = _UniffiFfiConverterInt32.lift
    _uniffi_error_converter = None
    _uniffi_ffi_result = _uniffi_rust_call_with_error(
        _uniffi_error_converter,
        _UniffiLib.uniffi_glean_core_fn_method_textmetric_test_get_num_recorded_errors,
        *_uniffi_lowered_args,
    )
    return _uniffi_lift_return(_uniffi_ffi_result)
def test_get_value(self,
ping_name: typing.Union[glean.metrics.object, typing.Optional[str]] = <object object>) ‑> str | None
Expand source code
def test_get_value(self, ping_name: typing.Union[object, typing.Optional[str]] = _DEFAULT) -> typing.Optional[str]:
    
    if ping_name is _DEFAULT:
        ping_name = None
    _UniffiFfiConverterOptionalString.check_lower(ping_name)
    _uniffi_lowered_args = (
        self._uniffi_clone_handle(),
        _UniffiFfiConverterOptionalString.lower(ping_name),
    )
    _uniffi_lift_return = _UniffiFfiConverterOptionalString.lift
    _uniffi_error_converter = None
    _uniffi_ffi_result = _uniffi_rust_call_with_error(
        _uniffi_error_converter,
        _UniffiLib.uniffi_glean_core_fn_method_textmetric_test_get_value,
        *_uniffi_lowered_args,
    )
    return _uniffi_lift_return(_uniffi_ffi_result)
class TimeUnit (*args, **kwds)
Expand source code
class TimeUnit(enum.Enum):
    
    NANOSECOND = 0
    
    MICROSECOND = 1
    
    MILLISECOND = 2
    
    SECOND = 3
    
    MINUTE = 4
    
    HOUR = 5
    
    DAY = 6

Create a collection of name/value pairs.

Example enumeration:

>>> class Color(Enum):
...     RED = 1
...     BLUE = 2
...     GREEN = 3

Access them by:

  • attribute access:

Color.RED

  • value lookup:

Color(1)

  • name lookup:

Color['RED']

Enumerations can be iterated over, and know how many members they have:

>>> len(Color)
3
>>> list(Color)
[<Color.RED: 1>, <Color.BLUE: 2>, <Color.GREEN: 3>]

Methods can be added to enumerations, and members can have their own attributes – see the documentation for details.

Ancestors

  • enum.Enum

Class variables

var DAY

The type of the None singleton.

var HOUR

The type of the None singleton.

var MICROSECOND

The type of the None singleton.

var MILLISECOND

The type of the None singleton.

var MINUTE

The type of the None singleton.

var NANOSECOND

The type of the None singleton.

var SECOND

The type of the None singleton.

class TimerId (*, id: int)
Expand source code
@dataclass
class TimerId:
    def __init__(self, *, id:int):
        self.id = id
        
        

    
    def __str__(self):
        return "TimerId(id={})".format(self.id)
    def __eq__(self, other):
        if self.id != other.id:
            return False
        return True

TimerId(*, id: 'int')

class TimespanMetricType (common_metric_data: glean._uniffi.glean.CommonMetricData,
time_unit: glean._uniffi.glean.TimeUnit)
Expand source code
class TimespanMetricType:
    """
    This implements the developer facing API for recording timespan metrics.

    Instances of this class type are automatically generated by
    `glean.load_metrics`, allowing developers to record values that were
    previously registered in the metrics.yaml file.

    The timespan API exposes the `TimespanMetricType.start`,
    `TimespanMetricType.stop` and `TimespanMetricType.cancel` methods.
    """

    def __init__(
        self,
        common_metric_data: CommonMetricData,
        time_unit: TimeUnit,
    ):
        self._inner = TimespanMetric(common_metric_data, time_unit)

    def start(self) -> None:
        """
        Start tracking time for the provided metric.

        This records an error if it’s already tracking time (i.e. `start` was
        already called with no corresponding `stop`): in that case the original
        start time will be preserved.
        """
        self._inner.start()

    def stop(self) -> None:
        """
        Stop tracking time for the provided metric.

        Sets the metric to the elapsed time, but does not overwrite an already
        existing value.
        This will record an error if no `start` was called or there is an already
        existing value.
        """
        self._inner.stop()

    def cancel(self) -> None:
        """
        Abort a previous `start` call. No error is recorded if no `start` was called.
        """
        self._inner.cancel()

    class _TimespanContextManager:
        """
        A context manager for recording timings. Used by the `measure` method.
        """

        def __init__(self, timespan: "TimespanMetricType"):
            self._timespan = timespan

        def __enter__(self) -> None:
            self._timespan.start()

        def __exit__(self, type, value, tb) -> None:
            if tb is None:
                self._timespan.stop()
            else:
                self._timespan.cancel()

    def measure(self) -> "_TimespanContextManager":
        """
        Provides a context manager for measuring the time it takes to execute
        snippets of code in a `with` statement.

        If the contents of the `with` statement raise an exception, the timing
        is not recorded.

        Usage:
            with metrics.perf.timer.measure():
                # ... do something that takes time ...
        """
        return self._TimespanContextManager(self)

    def set_raw_nanos(self, elapsed_nanos: int) -> None:
        """
        Explicitly set the timespan value, in nanoseconds.

        This API should only be used if your library or application requires recording
        times in a way that can not make use of [start]/[stop]/[cancel].

        [setRawNanos] does not overwrite a running timer or an already existing value.

        Args:
            elapsed_nanos (int): The elapsed time to record, in nanoseconds.
        """
        self._inner.set_raw_nanos(elapsed_nanos)

    def test_get_value(self, ping_name: Optional[str] = None) -> Optional[int]:
        """
        Returns the stored value for testing purposes only.

        Args:
            ping_name (str): (default: first value in send_in_pings) The name
                of the ping to retrieve the metric for.

        Returns:
            value (bool): value of the stored metric.
        """
        return self._inner.test_get_value(ping_name)

    def test_get_num_recorded_errors(self, error_type: ErrorType) -> int:
        """
        Returns the number of errors recorded for the given metric.

        Args:
            error_type (ErrorType): The type of error recorded.
            ping_name (str): (default: first value in send_in_pings) The name
                of the ping to retrieve the metric for.

        Returns:
            num_errors (int): The number of errors recorded for the metric for
                the given error type.
        """
        return self._inner.test_get_num_recorded_errors(error_type)

This implements the developer facing API for recording timespan metrics.

Instances of this class type are automatically generated by load_metrics(), allowing developers to record values that were previously registered in the metrics.yaml file.

The timespan API exposes the TimespanMetricType.start(), TimespanMetricType.stop() and TimespanMetricType.cancel() methods.

Methods

def cancel(self) ‑> None
Expand source code
def cancel(self) -> None:
    """
    Abort a previous `start` call. No error is recorded if no `start` was called.
    """
    self._inner.cancel()

Abort a previous start call. No error is recorded if no start was called.

def measure(self) ‑> _TimespanContextManager
Expand source code
def measure(self) -> "_TimespanContextManager":
    """
    Provides a context manager for measuring the time it takes to execute
    snippets of code in a `with` statement.

    If the contents of the `with` statement raise an exception, the timing
    is not recorded.

    Usage:
        with metrics.perf.timer.measure():
            # ... do something that takes time ...
    """
    return self._TimespanContextManager(self)

Provides a context manager for measuring the time it takes to execute snippets of code in a with statement.

If the contents of the with statement raise an exception, the timing is not recorded.

Usage

with metrics.perf.timer.measure(): # … do something that takes time …

def set_raw_nanos(self, elapsed_nanos: int) ‑> None
Expand source code
def set_raw_nanos(self, elapsed_nanos: int) -> None:
    """
    Explicitly set the timespan value, in nanoseconds.

    This API should only be used if your library or application requires recording
    times in a way that can not make use of [start]/[stop]/[cancel].

    [setRawNanos] does not overwrite a running timer or an already existing value.

    Args:
        elapsed_nanos (int): The elapsed time to record, in nanoseconds.
    """
    self._inner.set_raw_nanos(elapsed_nanos)

Explicitly set the timespan value, in nanoseconds.

This API should only be used if your library or application requires recording times in a way that can not make use of [start]/[stop]/[cancel].

[setRawNanos] does not overwrite a running timer or an already existing value.

Args

elapsed_nanos : int
The elapsed time to record, in nanoseconds.
def start(self) ‑> None
Expand source code
def start(self) -> None:
    """
    Start tracking time for the provided metric.

    This records an error if it’s already tracking time (i.e. `start` was
    already called with no corresponding `stop`): in that case the original
    start time will be preserved.
    """
    self._inner.start()

Start tracking time for the provided metric.

This records an error if it’s already tracking time (i.e. start was already called with no corresponding stop): in that case the original start time will be preserved.

def stop(self) ‑> None
Expand source code
def stop(self) -> None:
    """
    Stop tracking time for the provided metric.

    Sets the metric to the elapsed time, but does not overwrite an already
    existing value.
    This will record an error if no `start` was called or there is an already
    existing value.
    """
    self._inner.stop()

Stop tracking time for the provided metric.

Sets the metric to the elapsed time, but does not overwrite an already existing value. This will record an error if no start was called or there is an already existing value.

def test_get_num_recorded_errors(self, error_type: glean._uniffi.glean.ErrorType) ‑> int
Expand source code
def test_get_num_recorded_errors(self, error_type: ErrorType) -> int:
    """
    Returns the number of errors recorded for the given metric.

    Args:
        error_type (ErrorType): The type of error recorded.
        ping_name (str): (default: first value in send_in_pings) The name
            of the ping to retrieve the metric for.

    Returns:
        num_errors (int): The number of errors recorded for the metric for
            the given error type.
    """
    return self._inner.test_get_num_recorded_errors(error_type)

Returns the number of errors recorded for the given metric.

Args

error_type : ErrorType
The type of error recorded.
ping_name : str
(default: first value in send_in_pings) The name of the ping to retrieve the metric for.

Returns

num_errors (int): The number of errors recorded for the metric for the given error type.

def test_get_value(self, ping_name: str | None = None) ‑> int | None
Expand source code
def test_get_value(self, ping_name: Optional[str] = None) -> Optional[int]:
    """
    Returns the stored value for testing purposes only.

    Args:
        ping_name (str): (default: first value in send_in_pings) The name
            of the ping to retrieve the metric for.

    Returns:
        value (bool): value of the stored metric.
    """
    return self._inner.test_get_value(ping_name)

Returns the stored value for testing purposes only.

Args

ping_name : str
(default: first value in send_in_pings) The name of the ping to retrieve the metric for.

Returns

value (bool): value of the stored metric.

class TimingDistributionMetricType (common_metric_data: glean._uniffi.glean.CommonMetricData,
time_unit: glean._uniffi.glean.TimeUnit)
Expand source code
class TimingDistributionMetricType:
    """
    This implements the developer facing API for recording timing distribution
    metrics.

    Instances of this class type are automatically generated by
    `glean.load_metrics`, allowing developers to record values that were
    previously registered in the metrics.yaml file.
    """

    def __init__(
        self,
        common_metric_data: CommonMetricData,
        time_unit: TimeUnit,
    ):
        self._inner = TimingDistributionMetric(common_metric_data, time_unit)

    def start(self) -> TimerId:
        """
        Start tracking time for the provided metric.
        Multiple timers can run simultaneously.

        Returns:
            timer_id: The object to associate with this timing.
        """
        return self._inner.start()

    def stop_and_accumulate(self, timer_id: TimerId) -> None:
        """
        Stop tracking time for the provided metric and associated timer id. Add a
        count to the corresponding bucket in the timing distribution.
        This will record an error if no `start` was called.

        Args:
            timer_id: The timer id associated with this timing. This allows for
                concurrent timing of events associated with different ids to
                the same timespan metric.
        """
        self._inner.stop_and_accumulate(timer_id)

    def cancel(self, timer_id: TimerId) -> None:
        """
        Abort a previous `start` call. No error is recorded if no `start` was called.

        Args:
            timer_id: The timer id associated with this timing. This allows for
                concurrent timing of events associated with different ids to
                the same timing distribution metric.
        """
        self._inner.cancel(timer_id)

    def accumulate_samples(self, samples: list) -> None:
        """
        Accumulates the provided samples in the metric.

        Args:
            samples: The list holding the samples to be recorded by the metric.
        """
        self._inner.accumulate_samples(samples)

    def accumulate_single_sample(self, sample: int) -> None:
        """
        Accumulates a single sample and appends it to the metric.

        Args:
            sample: The single sample to be recorded by the metric.
        """
        self._inner.accumulate_single_sample(sample)

    class _TimingDistributionContextManager:
        """
        A context manager for recording timings. Used by the `measure` method.
        """

        def __init__(self, timing_distribution: "TimingDistributionMetricType"):
            self._timing_distribution = timing_distribution

        def __enter__(self) -> None:
            self._timer_id = self._timing_distribution.start()

        def __exit__(self, type, value, tb) -> None:
            if tb is None:
                self._timing_distribution.stop_and_accumulate(self._timer_id)
            else:
                self._timing_distribution.cancel(self._timer_id)

    def measure(self) -> "_TimingDistributionContextManager":
        """
        Provides a context manager for measuring the time it takes to execute
        snippets of code in a `with` statement.

        If the contents of the `with` statement raise an exception, the timing
        is not recorded.

        Usage:
            with metrics.perf.timer.measure():
                # ... do something that takes time ...
        """
        return self._TimingDistributionContextManager(self)

    def test_get_value(self, ping_name: Optional[str] = None) -> Optional[DistributionData]:
        """
        Returns the stored value for testing purposes only.

        Args:
            ping_name (str): (default: first value in send_in_pings) The name
                of the ping to retrieve the metric for.

        Returns:
            value (DistriubutionData): value of the stored metric.
        """
        return self._inner.test_get_value(ping_name)

    def test_get_num_recorded_errors(self, error_type: ErrorType) -> int:
        """
        Returns the number of errors recorded for the given metric.

        Args:
            error_type (ErrorType): The type of error recorded.
            ping_name (str): (default: first value in send_in_pings) The name
                of the ping to retrieve the metric for.

        Returns:
            num_errors (int): The number of errors recorded for the metric for
                the given error type.
        """
        return self._inner.test_get_num_recorded_errors(error_type)

This implements the developer facing API for recording timing distribution metrics.

Instances of this class type are automatically generated by load_metrics(), allowing developers to record values that were previously registered in the metrics.yaml file.

Methods

def accumulate_samples(self, samples: list) ‑> None
Expand source code
def accumulate_samples(self, samples: list) -> None:
    """
    Accumulates the provided samples in the metric.

    Args:
        samples: The list holding the samples to be recorded by the metric.
    """
    self._inner.accumulate_samples(samples)

Accumulates the provided samples in the metric.

Args

samples
The list holding the samples to be recorded by the metric.
def accumulate_single_sample(self, sample: int) ‑> None
Expand source code
def accumulate_single_sample(self, sample: int) -> None:
    """
    Accumulates a single sample and appends it to the metric.

    Args:
        sample: The single sample to be recorded by the metric.
    """
    self._inner.accumulate_single_sample(sample)

Accumulates a single sample and appends it to the metric.

Args

sample
The single sample to be recorded by the metric.
def cancel(self, timer_id: glean._uniffi.glean.TimerId) ‑> None
Expand source code
def cancel(self, timer_id: TimerId) -> None:
    """
    Abort a previous `start` call. No error is recorded if no `start` was called.

    Args:
        timer_id: The timer id associated with this timing. This allows for
            concurrent timing of events associated with different ids to
            the same timing distribution metric.
    """
    self._inner.cancel(timer_id)

Abort a previous start call. No error is recorded if no start was called.

Args

timer_id
The timer id associated with this timing. This allows for concurrent timing of events associated with different ids to the same timing distribution metric.
def measure(self) ‑> _TimingDistributionContextManager
Expand source code
def measure(self) -> "_TimingDistributionContextManager":
    """
    Provides a context manager for measuring the time it takes to execute
    snippets of code in a `with` statement.

    If the contents of the `with` statement raise an exception, the timing
    is not recorded.

    Usage:
        with metrics.perf.timer.measure():
            # ... do something that takes time ...
    """
    return self._TimingDistributionContextManager(self)

Provides a context manager for measuring the time it takes to execute snippets of code in a with statement.

If the contents of the with statement raise an exception, the timing is not recorded.

Usage

with metrics.perf.timer.measure(): # … do something that takes time …

def start(self) ‑> glean._uniffi.glean.TimerId
Expand source code
def start(self) -> TimerId:
    """
    Start tracking time for the provided metric.
    Multiple timers can run simultaneously.

    Returns:
        timer_id: The object to associate with this timing.
    """
    return self._inner.start()

Start tracking time for the provided metric. Multiple timers can run simultaneously.

Returns

timer_id
The object to associate with this timing.
def stop_and_accumulate(self, timer_id: glean._uniffi.glean.TimerId) ‑> None
Expand source code
def stop_and_accumulate(self, timer_id: TimerId) -> None:
    """
    Stop tracking time for the provided metric and associated timer id. Add a
    count to the corresponding bucket in the timing distribution.
    This will record an error if no `start` was called.

    Args:
        timer_id: The timer id associated with this timing. This allows for
            concurrent timing of events associated with different ids to
            the same timespan metric.
    """
    self._inner.stop_and_accumulate(timer_id)

Stop tracking time for the provided metric and associated timer id. Add a count to the corresponding bucket in the timing distribution. This will record an error if no start was called.

Args

timer_id
The timer id associated with this timing. This allows for concurrent timing of events associated with different ids to the same timespan metric.
def test_get_num_recorded_errors(self, error_type: glean._uniffi.glean.ErrorType) ‑> int
Expand source code
def test_get_num_recorded_errors(self, error_type: ErrorType) -> int:
    """
    Returns the number of errors recorded for the given metric.

    Args:
        error_type (ErrorType): The type of error recorded.
        ping_name (str): (default: first value in send_in_pings) The name
            of the ping to retrieve the metric for.

    Returns:
        num_errors (int): The number of errors recorded for the metric for
            the given error type.
    """
    return self._inner.test_get_num_recorded_errors(error_type)

Returns the number of errors recorded for the given metric.

Args

error_type : ErrorType
The type of error recorded.
ping_name : str
(default: first value in send_in_pings) The name of the ping to retrieve the metric for.

Returns

num_errors (int): The number of errors recorded for the metric for the given error type.

def test_get_value(self, ping_name: str | None = None) ‑> glean._uniffi.glean.DistributionData | None
Expand source code
def test_get_value(self, ping_name: Optional[str] = None) -> Optional[DistributionData]:
    """
    Returns the stored value for testing purposes only.

    Args:
        ping_name (str): (default: first value in send_in_pings) The name
            of the ping to retrieve the metric for.

    Returns:
        value (DistriubutionData): value of the stored metric.
    """
    return self._inner.test_get_value(ping_name)

Returns the stored value for testing purposes only.

Args

ping_name : str
(default: first value in send_in_pings) The name of the ping to retrieve the metric for.

Returns

value (DistriubutionData): value of the stored metric.

class UrlMetricType (common_metric_data: glean._uniffi.glean.CommonMetricData)
Expand source code
class UrlMetricType:
    """
    This implements the developer facing API for recording URL metrics.

    Instances of this class type are automatically generated by
    `glean.load_metrics`, allowing developers to record values that were
    previously registered in the metrics.yaml file.

    The url API only exposes the `UrlMetricType.set` method, which
    takes care of validating the input data and making sure that limits are
    enforced.
    See https://mozilla.github.io/glean/book/reference/metrics/url.html#limits
    """

    def __init__(self, common_metric_data: CommonMetricData):
        self._inner = UrlMetric(common_metric_data)

    def set(self, value: str) -> None:
        """
        Set a URL value.

        Args:
            value (str): This is a user-defined URL value. If the length of
                the URL exceeds the maximum length, it will not be recorded.
        """
        if value is None:
            return

        self._inner.set(value)

    def test_get_value(self, ping_name: Optional[str] = None) -> Optional[str]:
        return self._inner.test_get_value(ping_name)

    def test_get_num_recorded_errors(self, error_type: ErrorType) -> int:
        return self._inner.test_get_num_recorded_errors(error_type)

This implements the developer facing API for recording URL metrics.

Instances of this class type are automatically generated by load_metrics(), allowing developers to record values that were previously registered in the metrics.yaml file.

The url API only exposes the UrlMetricType.set() method, which takes care of validating the input data and making sure that limits are enforced. See https://mozilla.github.io/glean/book/reference/metrics/url.html#limits

Methods

def set(self, value: str) ‑> None
Expand source code
def set(self, value: str) -> None:
    """
    Set a URL value.

    Args:
        value (str): This is a user-defined URL value. If the length of
            the URL exceeds the maximum length, it will not be recorded.
    """
    if value is None:
        return

    self._inner.set(value)

Set a URL value.

Args

value : str
This is a user-defined URL value. If the length of the URL exceeds the maximum length, it will not be recorded.
def test_get_num_recorded_errors(self, error_type: glean._uniffi.glean.ErrorType) ‑> int
Expand source code
def test_get_num_recorded_errors(self, error_type: ErrorType) -> int:
    return self._inner.test_get_num_recorded_errors(error_type)
def test_get_value(self, ping_name: str | None = None) ‑> str | None
Expand source code
def test_get_value(self, ping_name: Optional[str] = None) -> Optional[str]:
    return self._inner.test_get_value(ping_name)
class UuidMetricType (common_metric_data: glean._uniffi.glean.CommonMetricData)
Expand source code
class UuidMetricType:
    """
    This implements the developer facing API for recording UUID metrics.

    Instances of this class type are automatically generated by
    `glean.load_metrics`, allowing developers to record values that were
    previously registered in the metrics.yaml file.

    The UUID API exposes the `UuidMetricType.generate_and_set` and
    `UuidMetricType.set` methods.
    """

    def __init__(self, common_metric_data: CommonMetricData):
        self._inner = UuidMetric(common_metric_data)

    def generate_and_set(self) -> Optional[uuid.UUID]:
        """
        Generate a new UUID value and set it in the metric store.
        """
        id = self._inner.generate_and_set()
        return uuid.UUID("urn:uuid:" + id)

    def set(self, value: Union[uuid.UUID, str]) -> None:
        """
        Explicitly set an existing UUID value.

        Args:
            value (uuid.UUID): A valid UUID to set the metric to.
        """
        self._inner.set(str(value))

    def test_get_value(self, ping_name: Optional[str] = None) -> Optional[uuid.UUID]:
        id = self._inner.test_get_value()
        if id:
            return uuid.UUID("urn:uuid:" + id)
        else:
            return None

    def test_get_num_recorded_errors(self, error_type: ErrorType) -> int:
        return self._inner.test_get_num_recorded_errors(error_type)

This implements the developer facing API for recording UUID metrics.

Instances of this class type are automatically generated by load_metrics(), allowing developers to record values that were previously registered in the metrics.yaml file.

The UUID API exposes the UuidMetricType.generate_and_set() and UuidMetricType.set() methods.

Methods

def generate_and_set(self) ‑> uuid.UUID | None
Expand source code
def generate_and_set(self) -> Optional[uuid.UUID]:
    """
    Generate a new UUID value and set it in the metric store.
    """
    id = self._inner.generate_and_set()
    return uuid.UUID("urn:uuid:" + id)

Generate a new UUID value and set it in the metric store.

def set(self, value: uuid.UUID | str) ‑> None
Expand source code
def set(self, value: Union[uuid.UUID, str]) -> None:
    """
    Explicitly set an existing UUID value.

    Args:
        value (uuid.UUID): A valid UUID to set the metric to.
    """
    self._inner.set(str(value))

Explicitly set an existing UUID value.

Args

value : uuid.UUID
A valid UUID to set the metric to.
def test_get_num_recorded_errors(self, error_type: glean._uniffi.glean.ErrorType) ‑> int
Expand source code
def test_get_num_recorded_errors(self, error_type: ErrorType) -> int:
    return self._inner.test_get_num_recorded_errors(error_type)
def test_get_value(self, ping_name: str | None = None) ‑> uuid.UUID | None
Expand source code
def test_get_value(self, ping_name: Optional[str] = None) -> Optional[uuid.UUID]:
    id = self._inner.test_get_value()
    if id:
        return uuid.UUID("urn:uuid:" + id)
    else:
        return None