Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ce269a3

Browse files
authored
Rename Measure to ValueRecorder (open-telemetry#761)
1 parent 24a564d commit ce269a3

File tree

12 files changed

+103
-102
lines changed

12 files changed

+103
-102
lines changed

docs/examples/basic_meter/basic_metrics.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
import time
2525

2626
from opentelemetry import metrics
27-
from opentelemetry.sdk.metrics import Counter, Measure, MeterProvider
27+
from opentelemetry.sdk.metrics import Counter, MeterProvider, ValueRecorder
2828
from opentelemetry.sdk.metrics.export import ConsoleMetricsExporter
2929
from opentelemetry.sdk.metrics.export.controller import PushController
3030

@@ -80,7 +80,7 @@ def usage(argv):
8080
description="size of requests",
8181
unit="1",
8282
value_type=int,
83-
metric_type=Measure,
83+
metric_type=ValueRecorder,
8484
label_keys=("environment",),
8585
)
8686

docs/examples/basic_meter/calling_conventions.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
import time
2020

2121
from opentelemetry import metrics
22-
from opentelemetry.sdk.metrics import Counter, Measure, MeterProvider
22+
from opentelemetry.sdk.metrics import Counter, MeterProvider, ValueRecorder
2323
from opentelemetry.sdk.metrics.export import ConsoleMetricsExporter
2424
from opentelemetry.sdk.metrics.export.controller import PushController
2525

@@ -43,7 +43,7 @@
4343
description="size of requests",
4444
unit="1",
4545
value_type=int,
46-
metric_type=Measure,
46+
metric_type=ValueRecorder,
4747
label_keys=("environment",),
4848
)
4949

ext/opentelemetry-ext-opencensusexporter/tests/test_otcollector_metrics_exporter.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323
from opentelemetry.ext.opencensusexporter import metrics_exporter
2424
from opentelemetry.sdk.metrics import (
2525
Counter,
26-
Measure,
2726
MeterProvider,
27+
ValueRecorder,
2828
get_labels_as_key,
2929
)
3030
from opentelemetry.sdk.metrics.export import (
@@ -76,7 +76,7 @@ def test_get_collector_metric_type(self):
7676
)
7777
self.assertIs(result, metrics_pb2.MetricDescriptor.CUMULATIVE_DOUBLE)
7878
result = metrics_exporter.get_collector_metric_type(
79-
Measure("testName", "testDescription", "unit", None, None)
79+
ValueRecorder("testName", "testDescription", "unit", None, None)
8080
)
8181
self.assertIs(result, metrics_pb2.MetricDescriptor.UNSPECIFIED)
8282

@@ -88,8 +88,8 @@ def test_get_collector_point(self):
8888
float_counter = self._meter.create_metric(
8989
"testName", "testDescription", "unit", float, Counter
9090
)
91-
measure = self._meter.create_metric(
92-
"testName", "testDescription", "unit", float, Measure
91+
valuerecorder = self._meter.create_metric(
92+
"testName", "testDescription", "unit", float, ValueRecorder
9393
)
9494
result = metrics_exporter.get_collector_point(
9595
MetricRecord(aggregator, self._key_labels, int_counter)
@@ -106,7 +106,7 @@ def test_get_collector_point(self):
106106
self.assertRaises(
107107
TypeError,
108108
metrics_exporter.get_collector_point(
109-
MetricRecord(aggregator, self._key_labels, measure)
109+
MetricRecord(aggregator, self._key_labels, valuerecorder)
110110
),
111111
)
112112

ext/opentelemetry-ext-prometheus/src/opentelemetry/ext/prometheus/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@
7979
UnknownMetricFamily,
8080
)
8181

82-
from opentelemetry.metrics import Counter, Measure, Metric
82+
from opentelemetry.metrics import Counter, Metric, ValueRecorder
8383
from opentelemetry.sdk.metrics.export import (
8484
MetricRecord,
8585
MetricsExporter,
@@ -164,7 +164,7 @@ def _translate_to_prometheus(self, metric_record: MetricRecord):
164164
labels=label_values, value=metric_record.aggregator.checkpoint
165165
)
166166
# TODO: Add support for histograms when supported in OT
167-
elif isinstance(metric_record.metric, Measure):
167+
elif isinstance(metric_record.metric, ValueRecorder):
168168
prometheus_metric = UnknownMetricFamily(
169169
name=metric_name,
170170
documentation=metric_record.metric.description,

opentelemetry-api/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
## Unreleased
44

5+
- Rename Measure to ValueRecorder in metrics
6+
([#761](https://github.com/open-telemetry/opentelemetry-python/pull/761))
7+
58
## 0.8b0
69

710
Released 2020-05-27

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

Lines changed: 22 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,13 @@
1919
The `Meter` class is used to construct `Metric` s to record raw statistics
2020
as well as metrics with predefined aggregation.
2121
22+
`Meter` s can be obtained via the `MeterProvider`, corresponding to the name
23+
of the instrumenting library and (optionally) a version.
24+
2225
See the `metrics api`_ spec for terminology and context clarification.
2326
2427
.. _metrics api:
25-
https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/api-metrics.md
26-
27-
.. versionadded:: 0.1.0
28-
.. versionchanged:: 0.5.0
29-
``meter_provider`` was replaced by `get_meter_provider`,
30-
``set_preferred_meter_provider_implementation`` was replaced by
31-
`set_meter_provider`.
28+
https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/metrics/api.md
3229
"""
3330
import abc
3431
from logging import getLogger
@@ -54,7 +51,7 @@ def add(self, value: ValueT) -> None:
5451
"""
5552

5653
def record(self, value: ValueT) -> None:
57-
"""No-op implementation of `BoundMeasure` record.
54+
"""No-op implementation of `BoundValueRecorder` record.
5855
5956
Args:
6057
value: The value to record to the bound metric instrument.
@@ -73,12 +70,12 @@ def add(self, value: ValueT) -> None:
7370
"""
7471

7572

76-
class BoundMeasure:
73+
class BoundValueRecorder:
7774
def record(self, value: ValueT) -> None:
78-
"""Records the given ``value`` to this bound measure.
75+
"""Records the given ``value`` to this bound valuerecorder.
7976
8077
Args:
81-
value: The value to record to the bound measure.
78+
value: The value to record to the bound valuerecorder.
8279
"""
8380

8481

@@ -94,12 +91,7 @@ def bind(self, labels: Dict[str, str]) -> "object":
9491
"""Gets a bound metric instrument.
9592
9693
Bound metric instruments are useful to reduce the cost of repeatedly
97-
recording a metric with a pre-defined set of label values. All metric
98-
kinds (counter, measure) support declaring a set of required label
99-
keys. The values corresponding to these keys should be specified in
100-
every bound metric instrument. "Unspecified" label values, in cases
101-
where a bound metric instrument is requested but a value was not
102-
provided are permitted.
94+
recording a metric with a pre-defined set of label values.
10395
10496
Args:
10597
labels: Labels to associate with the bound instrument.
@@ -126,10 +118,10 @@ def add(self, value: ValueT, labels: Dict[str, str]) -> None:
126118
"""
127119

128120
def record(self, value: ValueT, labels: Dict[str, str]) -> None:
129-
"""No-op implementation of `Measure` record.
121+
"""No-op implementation of `ValueRecorder` record.
130122
131123
Args:
132-
value: The value to record to this measure metric.
124+
value: The value to record to this valuerecorder metric.
133125
labels: Labels to associate with the bound instrument.
134126
"""
135127

@@ -150,21 +142,18 @@ def add(self, value: ValueT, labels: Dict[str, str]) -> None:
150142
"""
151143

152144

153-
class Measure(Metric):
154-
"""A measure type metric that represent raw stats that are recorded.
155-
156-
Measure metrics represent raw statistics that are recorded.
157-
"""
145+
class ValueRecorder(Metric):
146+
"""A valuerecorder type metric that represent raw stats."""
158147

159-
def bind(self, labels: Dict[str, str]) -> "BoundMeasure":
160-
"""Gets a `BoundMeasure`."""
161-
return BoundMeasure()
148+
def bind(self, labels: Dict[str, str]) -> "BoundValueRecorder":
149+
"""Gets a `BoundValueRecorder`."""
150+
return BoundValueRecorder()
162151

163152
def record(self, value: ValueT, labels: Dict[str, str]) -> None:
164-
"""Records the ``value`` to the measure.
153+
"""Records the ``value`` to the valuerecorder.
165154
166155
Args:
167-
value: The value to record to this measure metric.
156+
value: The value to record to this valuerecorder metric.
168157
labels: Labels to associate with the bound instrument.
169158
"""
170159

@@ -251,17 +240,17 @@ def get_meter(
251240
return DefaultMeter()
252241

253242

254-
MetricT = TypeVar("MetricT", Counter, Measure, Observer)
243+
MetricT = TypeVar("MetricT", Counter, ValueRecorder, Observer)
255244
ObserverCallbackT = Callable[[Observer], None]
256245

257246

258247
# pylint: disable=unused-argument
259248
class Meter(abc.ABC):
260249
"""An interface to allow the recording of metrics.
261250
262-
`Metric` s are used for recording pre-defined aggregation (counter),
263-
or raw values (measure) in which the aggregation and labels
264-
for the exported metric are deferred.
251+
`Metric` s or metric instruments, are devices used for capturing raw
252+
measurements. Each metric instrument supports a single method, each with
253+
fixed interpretation to capture measurements.
265254
"""
266255

267256
@abc.abstractmethod

opentelemetry-api/tests/metrics/test_metrics.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,14 @@ def test_counter_add(self):
3535
counter = metrics.Counter()
3636
counter.add(1, {})
3737

38-
def test_measure(self):
39-
measure = metrics.Measure()
40-
bound_measure = measure.bind({})
41-
self.assertIsInstance(bound_measure, metrics.BoundMeasure)
38+
def test_valuerecorder(self):
39+
valuerecorder = metrics.ValueRecorder()
40+
bound_valuerecorder = valuerecorder.bind({})
41+
self.assertIsInstance(bound_valuerecorder, metrics.BoundValueRecorder)
4242

43-
def test_measure_record(self):
44-
measure = metrics.Measure()
45-
measure.record(1, {})
43+
def test_valuerecorder_record(self):
44+
valuerecorder = metrics.ValueRecorder()
45+
valuerecorder.record(1, {})
4646

4747
def test_default_bound_metric(self):
4848
bound_instrument = metrics.DefaultBoundInstrument()
@@ -52,9 +52,9 @@ def test_bound_counter(self):
5252
bound_counter = metrics.BoundCounter()
5353
bound_counter.add(1)
5454

55-
def test_bound_measure(self):
56-
bound_measure = metrics.BoundMeasure()
57-
bound_measure.record(1)
55+
def test_bound_valuerecorder(self):
56+
bound_valuerecorder = metrics.BoundValueRecorder()
57+
bound_valuerecorder.record(1)
5858

5959
def test_observer(self):
6060
observer = metrics.DefaultObserver()

opentelemetry-sdk/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
## Unreleased
44

5+
- Rename Measure to ValueRecorder in metrics
6+
([#761](https://github.com/open-telemetry/opentelemetry-python/pull/761))
7+
58
## 0.8b0
69

710
Released 2020-05-27

opentelemetry-sdk/src/opentelemetry/sdk/metrics/__init__.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,9 @@ def add(self, value: metrics_api.ValueT) -> None:
9797
self.update(value)
9898

9999

100-
class BoundMeasure(metrics_api.BoundMeasure, BaseBoundInstrument):
100+
class BoundValueRecorder(metrics_api.BoundValueRecorder, BaseBoundInstrument):
101101
def record(self, value: metrics_api.ValueT) -> None:
102-
"""See `opentelemetry.metrics.BoundMeasure.record`."""
102+
"""See `opentelemetry.metrics.BoundValueRecorder.record`."""
103103
if self._validate_update(value):
104104
self.update(value)
105105

@@ -174,15 +174,15 @@ def add(self, value: metrics_api.ValueT, labels: Dict[str, str]) -> None:
174174
UPDATE_FUNCTION = add
175175

176176

177-
class Measure(Metric, metrics_api.Measure):
178-
"""See `opentelemetry.metrics.Measure`."""
177+
class ValueRecorder(Metric, metrics_api.ValueRecorder):
178+
"""See `opentelemetry.metrics.ValueRecorder`."""
179179

180-
BOUND_INSTR_TYPE = BoundMeasure
180+
BOUND_INSTR_TYPE = BoundValueRecorder
181181

182182
def record(
183183
self, value: metrics_api.ValueT, labels: Dict[str, str]
184184
) -> None:
185-
"""See `opentelemetry.metrics.Measure.record`."""
185+
"""See `opentelemetry.metrics.ValueRecorder.record`."""
186186
bound_intrument = self.bind(labels)
187187
bound_intrument.record(value)
188188
bound_intrument.release()

opentelemetry-sdk/src/opentelemetry/sdk/metrics/export/aggregate.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ def merge(self, other):
7272

7373

7474
class MinMaxSumCountAggregator(Aggregator):
75-
"""Agregator for Measure metrics that keeps min, max, sum and count."""
75+
"""Aggregator for ValueRecorder metrics that keeps min, max, sum, count."""
7676

7777
_TYPE = namedtuple("minmaxsumcount", "min max sum count")
7878
_EMPTY = _TYPE(None, None, None, 0)

opentelemetry-sdk/src/opentelemetry/sdk/metrics/export/batcher.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
import abc
1616
from typing import Sequence, Type
1717

18-
from opentelemetry.metrics import Counter, Measure, MetricT, Observer
18+
from opentelemetry.metrics import Counter, MetricT, Observer, ValueRecorder
1919
from opentelemetry.sdk.metrics.export import MetricRecord
2020
from opentelemetry.sdk.metrics.export.aggregate import (
2121
Aggregator,
@@ -49,7 +49,7 @@ def aggregator_for(self, metric_type: Type[MetricT]) -> Aggregator:
4949
# pylint:disable=R0201
5050
if issubclass(metric_type, Counter):
5151
return CounterAggregator()
52-
if issubclass(metric_type, Measure):
52+
if issubclass(metric_type, ValueRecorder):
5353
return MinMaxSumCountAggregator()
5454
if issubclass(metric_type, Observer):
5555
return ObserverAggregator()

0 commit comments

Comments
 (0)