Skip to content

Commit df869a4

Browse files
committed
Rename Measurement to Observation
Fixes #2451
1 parent 1b00f31 commit df869a4

File tree

7 files changed

+55
-53
lines changed

7 files changed

+55
-53
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99

1010
## [1.11.0-0.30b0](https://github.com/open-telemetry/opentelemetry-python/releases/tag/v1.11.0-0.30b0) - 2022-04-18
1111

12+
- Rename API Measurement to Observation
13+
([#2451](https://github.com/open-telemetry/opentelemetry-python/pull/2451))
1214
- Add support for zero or more callbacks
1315
([#2602](https://github.com/open-telemetry/opentelemetry-python/pull/2602))
1416
- Fix parsing of trace flags when extracting traceparent

opentelemetry-api/src/opentelemetry/_metrics/instrument.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,12 @@
3030

3131
# pylint: disable=unused-import; needed for typing and sphinx
3232
from opentelemetry import _metrics as metrics
33-
from opentelemetry._metrics.measurement import Measurement
33+
from opentelemetry._metrics.observation import Observation
3434

3535
InstrumentT = TypeVar("InstrumentT", bound="Instrument")
3636
CallbackT = Union[
37-
Callable[[], Iterable[Measurement]],
38-
Generator[Iterable[Measurement], None, None],
37+
Callable[[], Iterable[Observation]],
38+
Generator[Iterable[Observation], None, None],
3939
]
4040

4141

opentelemetry-api/src/opentelemetry/_metrics/measurement.py renamed to opentelemetry-api/src/opentelemetry/_metrics/observation.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
from opentelemetry.util.types import Attributes
1818

1919

20-
class Measurement:
20+
class Observation:
2121
"""A measurement observed in an asynchronous instrument
2222
2323
Return/yield instances of this class from asynchronous instrument callbacks.
@@ -43,10 +43,10 @@ def attributes(self) -> Attributes:
4343

4444
def __eq__(self, other: object) -> bool:
4545
return (
46-
isinstance(other, Measurement)
46+
isinstance(other, Observation)
4747
and self.value == other.value
4848
and self.attributes == other.attributes
4949
)
5050

5151
def __repr__(self) -> str:
52-
return f"Measurement(value={self.value}, attributes={self.attributes})"
52+
return f"Observation(value={self.value}, attributes={self.attributes})"

opentelemetry-api/tests/metrics/test_measurement.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,33 +14,33 @@
1414

1515
from unittest import TestCase
1616

17-
from opentelemetry._metrics.measurement import Measurement
17+
from opentelemetry._metrics.observation import Observation
1818

1919

20-
class TestMeasurement(TestCase):
20+
class TestObservation(TestCase):
2121
def test_measurement_init(self):
2222
try:
2323
# int
24-
Measurement(321, {"hello": "world"})
24+
Observation(321, {"hello": "world"})
2525

2626
# float
27-
Measurement(321.321, {"hello": "world"})
27+
Observation(321.321, {"hello": "world"})
2828
except Exception: # pylint: disable=broad-except
2929
self.fail(
30-
"Unexpected exception raised when instantiating Measurement"
30+
"Unexpected exception raised when instantiating Observation"
3131
)
3232

3333
def test_measurement_equality(self):
3434
self.assertEqual(
35-
Measurement(321, {"hello": "world"}),
36-
Measurement(321, {"hello": "world"}),
35+
Observation(321, {"hello": "world"}),
36+
Observation(321, {"hello": "world"}),
3737
)
3838

3939
self.assertNotEqual(
40-
Measurement(321, {"hello": "world"}),
41-
Measurement(321.321, {"hello": "world"}),
40+
Observation(321, {"hello": "world"}),
41+
Observation(321.321, {"hello": "world"}),
4242
)
4343
self.assertNotEqual(
44-
Measurement(321, {"baz": "world"}),
45-
Measurement(321, {"hello": "world"}),
44+
Observation(321, {"baz": "world"}),
45+
Observation(321, {"hello": "world"}),
4646
)

opentelemetry-sdk/tests/metrics/integration_test/test_cpu_time.py

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
from unittest import TestCase
1919

2020
from opentelemetry._metrics.instrument import Instrument
21-
from opentelemetry._metrics.measurement import Measurement as APIMeasurement
21+
from opentelemetry._metrics.observation import Observation
2222
from opentelemetry.sdk._metrics import MeterProvider
2323
from opentelemetry.sdk._metrics.measurement import Measurement
2424

@@ -139,38 +139,38 @@ def create_measurements_expected(
139139
]
140140

141141
def test_cpu_time_callback(self):
142-
def cpu_time_callback() -> Iterable[APIMeasurement]:
142+
def cpu_time_callback() -> Iterable[Observation]:
143143
procstat = io.StringIO(self.procstat_str)
144144
procstat.readline() # skip the first line
145145
for line in procstat:
146146
if not line.startswith("cpu"):
147147
break
148148
cpu, *states = line.split()
149-
yield APIMeasurement(
149+
yield Observation(
150150
int(states[0]) / 100, {"cpu": cpu, "state": "user"}
151151
)
152-
yield APIMeasurement(
152+
yield Observation(
153153
int(states[1]) / 100, {"cpu": cpu, "state": "nice"}
154154
)
155-
yield APIMeasurement(
155+
yield Observation(
156156
int(states[2]) / 100, {"cpu": cpu, "state": "system"}
157157
)
158-
yield APIMeasurement(
158+
yield Observation(
159159
int(states[3]) / 100, {"cpu": cpu, "state": "idle"}
160160
)
161-
yield APIMeasurement(
161+
yield Observation(
162162
int(states[4]) / 100, {"cpu": cpu, "state": "iowait"}
163163
)
164-
yield APIMeasurement(
164+
yield Observation(
165165
int(states[5]) / 100, {"cpu": cpu, "state": "irq"}
166166
)
167-
yield APIMeasurement(
167+
yield Observation(
168168
int(states[6]) / 100, {"cpu": cpu, "state": "softirq"}
169169
)
170-
yield APIMeasurement(
170+
yield Observation(
171171
int(states[7]) / 100, {"cpu": cpu, "state": "guest"}
172172
)
173-
yield APIMeasurement(
173+
yield Observation(
174174
int(states[8]) / 100, {"cpu": cpu, "state": "guest_nice"}
175175
)
176176

@@ -188,7 +188,7 @@ def cpu_time_callback() -> Iterable[APIMeasurement]:
188188

189189
def test_cpu_time_generator(self):
190190
def cpu_time_generator() -> Generator[
191-
Iterable[APIMeasurement], None, None
191+
Iterable[Observation], None, None
192192
]:
193193
while True:
194194
measurements = []
@@ -199,54 +199,54 @@ def cpu_time_generator() -> Generator[
199199
break
200200
cpu, *states = line.split()
201201
measurements.append(
202-
APIMeasurement(
202+
Observation(
203203
int(states[0]) / 100,
204204
{"cpu": cpu, "state": "user"},
205205
)
206206
)
207207
measurements.append(
208-
APIMeasurement(
208+
Observation(
209209
int(states[1]) / 100,
210210
{"cpu": cpu, "state": "nice"},
211211
)
212212
)
213213
measurements.append(
214-
APIMeasurement(
214+
Observation(
215215
int(states[2]) / 100,
216216
{"cpu": cpu, "state": "system"},
217217
)
218218
)
219219
measurements.append(
220-
APIMeasurement(
220+
Observation(
221221
int(states[3]) / 100,
222222
{"cpu": cpu, "state": "idle"},
223223
)
224224
)
225225
measurements.append(
226-
APIMeasurement(
226+
Observation(
227227
int(states[4]) / 100,
228228
{"cpu": cpu, "state": "iowait"},
229229
)
230230
)
231231
measurements.append(
232-
APIMeasurement(
232+
Observation(
233233
int(states[5]) / 100, {"cpu": cpu, "state": "irq"}
234234
)
235235
)
236236
measurements.append(
237-
APIMeasurement(
237+
Observation(
238238
int(states[6]) / 100,
239239
{"cpu": cpu, "state": "softirq"},
240240
)
241241
)
242242
measurements.append(
243-
APIMeasurement(
243+
Observation(
244244
int(states[7]) / 100,
245245
{"cpu": cpu, "state": "guest"},
246246
)
247247
)
248248
measurements.append(
249-
APIMeasurement(
249+
Observation(
250250
int(states[8]) / 100,
251251
{"cpu": cpu, "state": "guest_nice"},
252252
)

opentelemetry-sdk/tests/metrics/test_in_memory_metric_reader.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
from unittest import TestCase
1616
from unittest.mock import Mock
1717

18-
from opentelemetry._metrics.measurement import Measurement
18+
from opentelemetry._metrics.observation import Observation
1919
from opentelemetry.sdk._metrics import MeterProvider
2020
from opentelemetry.sdk._metrics.export import InMemoryMetricReader
2121
from opentelemetry.sdk._metrics.point import (
@@ -70,7 +70,7 @@ def test_integration(self):
7070
meter = MeterProvider(metric_readers=[reader]).get_meter("test_meter")
7171
counter1 = meter.create_counter("counter1")
7272
meter.create_observable_gauge(
73-
"observable_gauge1", callbacks=[lambda: [Measurement(value=12)]]
73+
"observable_gauge1", callbacks=[lambda: [Observation(value=12)]]
7474
)
7575
counter1.add(1, {"foo": "1"})
7676
counter1.add(1, {"foo": "2"})

opentelemetry-sdk/tests/metrics/test_instrument.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
from unittest import TestCase
1616
from unittest.mock import Mock
1717

18-
from opentelemetry._metrics.measurement import Measurement as APIMeasurement
18+
from opentelemetry._metrics.observation import Observation
1919
from opentelemetry.sdk._metrics.instrument import (
2020
Counter,
2121
Histogram,
@@ -60,33 +60,33 @@ def test_add_non_monotonic(self):
6060

6161
def callable_callback_0():
6262
return [
63-
APIMeasurement(1, attributes=TEST_ATTRIBUTES),
64-
APIMeasurement(2, attributes=TEST_ATTRIBUTES),
65-
APIMeasurement(3, attributes=TEST_ATTRIBUTES),
63+
Observation(1, attributes=TEST_ATTRIBUTES),
64+
Observation(2, attributes=TEST_ATTRIBUTES),
65+
Observation(3, attributes=TEST_ATTRIBUTES),
6666
]
6767

6868

6969
def callable_callback_1():
7070
return [
71-
APIMeasurement(4, attributes=TEST_ATTRIBUTES),
72-
APIMeasurement(5, attributes=TEST_ATTRIBUTES),
73-
APIMeasurement(6, attributes=TEST_ATTRIBUTES),
71+
Observation(4, attributes=TEST_ATTRIBUTES),
72+
Observation(5, attributes=TEST_ATTRIBUTES),
73+
Observation(6, attributes=TEST_ATTRIBUTES),
7474
]
7575

7676

7777
def generator_callback_0():
7878
yield [
79-
APIMeasurement(1, attributes=TEST_ATTRIBUTES),
80-
APIMeasurement(2, attributes=TEST_ATTRIBUTES),
81-
APIMeasurement(3, attributes=TEST_ATTRIBUTES),
79+
Observation(1, attributes=TEST_ATTRIBUTES),
80+
Observation(2, attributes=TEST_ATTRIBUTES),
81+
Observation(3, attributes=TEST_ATTRIBUTES),
8282
]
8383

8484

8585
def generator_callback_1():
8686
yield [
87-
APIMeasurement(4, attributes=TEST_ATTRIBUTES),
88-
APIMeasurement(5, attributes=TEST_ATTRIBUTES),
89-
APIMeasurement(6, attributes=TEST_ATTRIBUTES),
87+
Observation(4, attributes=TEST_ATTRIBUTES),
88+
Observation(5, attributes=TEST_ATTRIBUTES),
89+
Observation(6, attributes=TEST_ATTRIBUTES),
9090
]
9191

9292

0 commit comments

Comments
 (0)