Skip to content

Commit

Permalink
Make measurement a concrete class (open-telemetry#2153)
Browse files Browse the repository at this point in the history
* Make Measurement a concrete class

* comments

* update changelog
  • Loading branch information
aabmass authored and ocelotl committed Nov 10, 2021
1 parent 3c42e66 commit 13aba06
Showing 1 changed file with 27 additions and 14 deletions.
41 changes: 27 additions & 14 deletions opentelemetry-api/src/opentelemetry/metrics/measurement.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,41 @@
# See the License for the specific language governing permissions and
# limitations under the License.

# pylint: disable=too-many-ancestors
# type:ignore
from typing import Union

from opentelemetry.util.types import Attributes

from abc import ABC, abstractmethod

class Measurement:
"""A measurement observed in an asynchronous instrument
Return/yield instances of this class from asynchronous instrument callbacks.
Args:
value: The float or int measured value
attributes: The measurement's attributes
"""

def __init__(
self, value: Union[int, float], attributes: Attributes = None
) -> None:
self._value = value
self._attributes = attributes

class Measurement(ABC):
@property
def value(self):
def value(self) -> Union[float, int]:
return self._value

@property
def attributes(self):
def attributes(self) -> Attributes:
return self._attributes

@abstractmethod
def __init__(self, value, attributes=None):
self._value = value
self._attributes = attributes

def __eq__(self, other: object) -> bool:
return (
isinstance(other, Measurement)
and self.value == other.value
and self.attributes == other.attributes
)

class DefaultMeasurement(Measurement):
def __init__(self, value, attributes=None):
super().__init__(value, attributes=attributes)
def __repr__(self) -> str:
return f"Measurement(value={self.value}, attributes={self.attributes})"

0 comments on commit 13aba06

Please sign in to comment.