|
12 | 12 | # See the License for the specific language governing permissions and
|
13 | 13 | # limitations under the License.
|
14 | 14 |
|
15 |
| -# pylint: disable=too-many-ancestors |
16 |
| -# type:ignore |
| 15 | +from typing import Union |
17 | 16 |
|
| 17 | +from opentelemetry.util.types import Attributes |
18 | 18 |
|
19 |
| -from abc import ABC, abstractmethod |
20 | 19 |
|
| 20 | +class Measurement: |
| 21 | + """A measurement observed in an asynchronous instrument |
| 22 | +
|
| 23 | + Return/yield instances of this class from asynchronous instrument callbacks. |
| 24 | +
|
| 25 | + Args: |
| 26 | + value: The float or int measured value |
| 27 | + attributes: The measurement's attributes |
| 28 | + """ |
| 29 | + |
| 30 | + def __init__( |
| 31 | + self, value: Union[int, float], attributes: Attributes = None |
| 32 | + ) -> None: |
| 33 | + self._value = value |
| 34 | + self._attributes = attributes |
21 | 35 |
|
22 |
| -class Measurement(ABC): |
23 | 36 | @property
|
24 |
| - def value(self): |
| 37 | + def value(self) -> Union[float, int]: |
25 | 38 | return self._value
|
26 | 39 |
|
27 | 40 | @property
|
28 |
| - def attributes(self): |
| 41 | + def attributes(self) -> Attributes: |
29 | 42 | return self._attributes
|
30 | 43 |
|
31 |
| - @abstractmethod |
32 |
| - def __init__(self, value, attributes=None): |
33 |
| - self._value = value |
34 |
| - self._attributes = attributes |
35 |
| - |
| 44 | + def __eq__(self, other: object) -> bool: |
| 45 | + return ( |
| 46 | + isinstance(other, Measurement) |
| 47 | + and self.value == other.value |
| 48 | + and self.attributes == other.attributes |
| 49 | + ) |
36 | 50 |
|
37 |
| -class DefaultMeasurement(Measurement): |
38 |
| - def __init__(self, value, attributes=None): |
39 |
| - super().__init__(value, attributes=attributes) |
| 51 | + def __repr__(self) -> str: |
| 52 | + return f"Measurement(value={self.value}, attributes={self.attributes})" |
0 commit comments