Skip to content

Commit 0ec1641

Browse files
aabmassocelotl
authored andcommitted
Make measurement a concrete class (open-telemetry#2153)
* Make Measurement a concrete class * comments * update changelog
1 parent 7f30451 commit 0ec1641

File tree

1 file changed

+27
-14
lines changed

1 file changed

+27
-14
lines changed

opentelemetry-api/src/opentelemetry/metrics/measurement.py

+27-14
Original file line numberDiff line numberDiff line change
@@ -12,28 +12,41 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
# pylint: disable=too-many-ancestors
16-
# type:ignore
15+
from typing import Union
1716

17+
from opentelemetry.util.types import Attributes
1818

19-
from abc import ABC, abstractmethod
2019

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
2135

22-
class Measurement(ABC):
2336
@property
24-
def value(self):
37+
def value(self) -> Union[float, int]:
2538
return self._value
2639

2740
@property
28-
def attributes(self):
41+
def attributes(self) -> Attributes:
2942
return self._attributes
3043

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+
)
3650

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

Comments
 (0)