Skip to content

Commit c2a28e2

Browse files
author
alrex
authored
Merge branch 'metrics_new' into merge_main_0
2 parents bd40e7d + 4254a0b commit c2a28e2

File tree

6 files changed

+25
-404
lines changed

6 files changed

+25
-404
lines changed

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

+7-17
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,7 @@ def get_meter(
5555
version=None,
5656
schema_url=None,
5757
) -> "Meter":
58-
if name is None or name == "":
59-
_logger.warning("Invalid name: %s", name)
58+
pass
6059

6160

6261
class _DefaultMeterProvider(MeterProvider):
@@ -104,24 +103,17 @@ def version(self):
104103
def schema_url(self):
105104
return self._schema_url
106105

107-
def _secure_instrument_name(self, name):
108-
name = name.lower()
109-
110-
if name in self._instrument_names:
111-
_logger.error("Instrument name %s has been used already", name)
112-
113-
else:
114-
self._instrument_names.add(name)
106+
# FIXME check that the instrument name has not been used already
115107

116108
@abstractmethod
117109
def create_counter(self, name, unit="", description="") -> Counter:
118-
self._secure_instrument_name(name)
110+
pass
119111

120112
@abstractmethod
121113
def create_up_down_counter(
122114
self, name, unit="", description=""
123115
) -> UpDownCounter:
124-
self._secure_instrument_name(name)
116+
pass
125117

126118
@abstractmethod
127119
def create_observable_counter(
@@ -206,23 +198,21 @@ def cpu_time_callback(states_to_include: set[str]) -> Iterable[Iterable[Measurem
206198
description: A description for this instrument and what it measures.
207199
"""
208200

209-
self._secure_instrument_name(name)
210-
211201
@abstractmethod
212202
def create_histogram(self, name, unit="", description="") -> Histogram:
213-
self._secure_instrument_name(name)
203+
pass
214204

215205
@abstractmethod
216206
def create_observable_gauge(
217207
self, name, callback, unit="", description=""
218208
) -> ObservableGauge:
219-
self._secure_instrument_name(name)
209+
pass
220210

221211
@abstractmethod
222212
def create_observable_up_down_counter(
223213
self, name, callback, unit="", description=""
224214
) -> ObservableUpDownCounter:
225-
self._secure_instrument_name(name)
215+
pass
226216

227217

228218
class ProxyMeter(Meter):

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

+12-68
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
from abc import ABC, abstractmethod
2020
from collections import abc as collections_abc
2121
from logging import getLogger
22-
from re import compile as compile_
2322
from typing import Callable, Generator, Iterable, Union
2423

2524
from opentelemetry.metrics.measurement import Measurement
@@ -33,44 +32,13 @@
3332

3433

3534
class Instrument(ABC):
36-
37-
_name_regex = compile_(r"[a-zA-Z][-.\w]{0,62}")
38-
39-
@property
40-
def name(self):
41-
return self._name
42-
43-
@property
44-
def unit(self):
45-
return self._unit
46-
47-
@property
48-
def description(self):
49-
return self._description
50-
5135
@abstractmethod
5236
def __init__(self, name, unit="", description=""):
37+
pass
5338

54-
if name is None or self._name_regex.fullmatch(name) is None:
55-
_logger.error("Invalid instrument name %s", name)
56-
57-
else:
58-
self._name = name
59-
60-
if unit is None:
61-
self._unit = ""
62-
elif len(unit) > 63:
63-
_logger.error("unit must be 63 characters or shorter")
64-
65-
elif any(ord(character) > 127 for character in unit):
66-
_logger.error("unit must only contain ASCII characters")
67-
else:
68-
self._unit = unit
69-
70-
if description is None:
71-
description = ""
72-
73-
self._description = description
39+
# FIXME check that the instrument name is valid
40+
# FIXME check that the unit is 63 characters or shorter
41+
# FIXME check that the unit contains only ASCII characters
7442

7543

7644
class Synchronous(Instrument):
@@ -96,11 +64,10 @@ def __init__(
9664
self._callback = callback
9765
elif isinstance(callback, collections_abc.Generator):
9866
self._callback = self._wrap_generator_callback(callback)
99-
else:
100-
_logger.error("callback must be a callable or generator")
67+
# FIXME check that callback is a callable or generator
10168

69+
@staticmethod
10270
def _wrap_generator_callback(
103-
self,
10471
generator_callback: _TInstrumentCallbackGenerator,
10572
) -> _TInstrumentCallback:
10673
"""Wraps a generator style callback into a callable one"""
@@ -115,30 +82,13 @@ def inner() -> Iterable[Measurement]:
11582
return next(generator_callback)
11683
except StopIteration:
11784
has_items = False
118-
_logger.error(
119-
"callback generator for instrument %s ran out of measurements",
120-
self._name,
121-
)
85+
# FIXME handle the situation where the callback generator has
86+
# run out of measurements
12287
return []
12388

12489
return inner
12590

126-
def callback(self):
127-
measurements = self._callback()
128-
if not isinstance(measurements, collections_abc.Iterable):
129-
_logger.error(
130-
"Callback must return an iterable of Measurement, got %s",
131-
type(measurements),
132-
)
133-
return
134-
for measurement in measurements:
135-
if not isinstance(measurement, Measurement):
136-
_logger.error(
137-
"Callback must return an iterable of Measurement, "
138-
"iterable contained type %s",
139-
type(measurement),
140-
)
141-
yield measurement
91+
# FIXME check that callbacks return an iterable of Measurements
14292

14393

14494
class _Adding(Instrument):
@@ -160,8 +110,8 @@ class _NonMonotonic(_Adding):
160110
class Counter(_Monotonic, Synchronous):
161111
@abstractmethod
162112
def add(self, amount, attributes=None):
163-
if amount < 0:
164-
_logger.error("Amount must be non-negative")
113+
# FIXME check that the amount is non negative
114+
pass
165115

166116

167117
class DefaultCounter(Counter):
@@ -187,13 +137,7 @@ def add(self, amount, attributes=None):
187137

188138

189139
class ObservableCounter(_Monotonic, Asynchronous):
190-
def callback(self):
191-
measurements = super().callback()
192-
193-
for measurement in measurements:
194-
if measurement.value < 0:
195-
_logger.error("Amount must be non-negative")
196-
yield measurement
140+
pass
197141

198142

199143
class DefaultObservableCounter(ObservableCounter):

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ def cpu_time_callback() -> Iterable[Measurement]:
104104
unit="s",
105105
description="CPU time",
106106
)
107-
measurements = list(observable_counter.callback())
107+
measurements = list(observable_counter._callback())
108108
self.assertEqual(measurements, self.measurements_expected)
109109

110110
def test_cpu_time_generator(self):
@@ -182,5 +182,5 @@ def cpu_time_generator() -> Generator[
182182
unit="s",
183183
description="CPU time",
184184
)
185-
measurements = list(observable_counter.callback())
185+
measurements = list(observable_counter._callback())
186186
self.assertEqual(measurements, self.measurements_expected)

0 commit comments

Comments
 (0)