Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/opentelemetry/metrics/_internal/observation.py: 62%
16 statements
« prev ^ index » next coverage.py v7.2.7, created at 2023-06-07 06:35 +0000
« prev ^ index » next coverage.py v7.2.7, created at 2023-06-07 06:35 +0000
1# Copyright The OpenTelemetry Authors
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
15from typing import Union
17from opentelemetry.util.types import Attributes
20class Observation:
21 """A measurement observed in an asynchronous instrument
23 Return/yield instances of this class from asynchronous instrument callbacks.
25 Args:
26 value: The float or int measured value
27 attributes: The measurement's attributes
28 """
30 def __init__(
31 self, value: Union[int, float], attributes: Attributes = None
32 ) -> None:
33 self._value = value
34 self._attributes = attributes
36 @property
37 def value(self) -> Union[float, int]:
38 return self._value
40 @property
41 def attributes(self) -> Attributes:
42 return self._attributes
44 def __eq__(self, other: object) -> bool:
45 return (
46 isinstance(other, Observation)
47 and self.value == other.value
48 and self.attributes == other.attributes
49 )
51 def __repr__(self) -> str:
52 return f"Observation(value={self.value}, attributes={self.attributes})"