From 4a7e95cae4dd7c838397b60df2159cf4b021ef79 Mon Sep 17 00:00:00 2001 From: Diego Hurtado Date: Thu, 25 Nov 2021 17:15:10 -0600 Subject: [PATCH 01/13] Refactor Meter and MeterProvider Fixes #2292 --- .../src/opentelemetry/util/_time.py | 1 - opentelemetry-sdk/setup.cfg | 2 + .../opentelemetry/sdk/_metrics/__init__.py | 276 ++++++++++++------ .../sdk/_metrics/metric_exporter.py | 17 ++ .../sdk/_metrics/metric_reader.py | 17 ++ .../src/opentelemetry/sdk/_metrics/view.py | 18 ++ .../tests/metrics/test_metrics.py | 141 +-------- 7 files changed, 236 insertions(+), 236 deletions(-) create mode 100644 opentelemetry-sdk/src/opentelemetry/sdk/_metrics/metric_exporter.py create mode 100644 opentelemetry-sdk/src/opentelemetry/sdk/_metrics/metric_reader.py create mode 100644 opentelemetry-sdk/src/opentelemetry/sdk/_metrics/view.py diff --git a/opentelemetry-api/src/opentelemetry/util/_time.py b/opentelemetry-api/src/opentelemetry/util/_time.py index ceaca22e8d4..a3fd113ce3c 100644 --- a/opentelemetry-api/src/opentelemetry/util/_time.py +++ b/opentelemetry-api/src/opentelemetry/util/_time.py @@ -28,7 +28,6 @@ def _time_ns() -> int: return int(time() * 1e9) - else: from time import time_ns diff --git a/opentelemetry-sdk/setup.cfg b/opentelemetry-sdk/setup.cfg index e78448dd820..eb6b81d5e15 100644 --- a/opentelemetry-sdk/setup.cfg +++ b/opentelemetry-sdk/setup.cfg @@ -45,6 +45,8 @@ include_package_data = True install_requires = opentelemetry-api == 1.7.1 opentelemetry-semantic-conventions == 0.26b1 + # FIXME Remove when 3.6 is no longer supported + dataclasses == 0.8; python_version < '3.7' [options.packages.find] where = src diff --git a/opentelemetry-sdk/src/opentelemetry/sdk/_metrics/__init__.py b/opentelemetry-sdk/src/opentelemetry/sdk/_metrics/__init__.py index 1f306f68b31..5b003647aac 100644 --- a/opentelemetry-sdk/src/opentelemetry/sdk/_metrics/__init__.py +++ b/opentelemetry-sdk/src/opentelemetry/sdk/_metrics/__init__.py @@ -12,17 +12,28 @@ # See the License for the specific language governing permissions and # limitations under the License. -# pylint: disable=function-redefined,too-many-ancestors - -from abc import ABC, abstractmethod from atexit import register, unregister from logging import getLogger -from typing import Optional +from threading import Lock +from typing import Optional, Sequence from opentelemetry._metrics import Meter as APIMeter from opentelemetry._metrics import MeterProvider as APIMeterProvider from opentelemetry._metrics import _DefaultMeter +from opentelemetry._metrics.instrument import Counter as APICounter +from opentelemetry._metrics.instrument import Histogram as APIHistogram +from opentelemetry._metrics.instrument import ( + ObservableCounter as APIObservableCounter, +) from opentelemetry._metrics.instrument import ( + ObservableGauge as APIObservableGauge, +) +from opentelemetry._metrics.instrument import ( + ObservableUpDownCounter as APIObservableUpDownCounter, +) +from opentelemetry._metrics.instrument import Synchronous +from opentelemetry._metrics.instrument import UpDownCounter as APIUpDownCounter +from opentelemetry.sdk._metrics.instrument import ( Counter, Histogram, ObservableCounter, @@ -30,6 +41,9 @@ ObservableUpDownCounter, UpDownCounter, ) +from opentelemetry.sdk._metrics.metric_exporter import MetricExporter +from opentelemetry.sdk._metrics.metric_reader import MetricReader +from opentelemetry.sdk._metrics.view import View from opentelemetry.sdk.resources import Resource from opentelemetry.sdk.util.instrumentation import InstrumentationInfo @@ -37,6 +51,8 @@ class Meter(APIMeter): + """See `opentelemetry._metrics.Meter`.""" + def __init__( self, instrumentation_info: InstrumentationInfo, @@ -46,37 +62,51 @@ def __init__( self._instrumentation_info = instrumentation_info self._meter_provider = meter_provider - def create_counter(self, name, unit=None, description=None) -> Counter: - # FIXME implement this method - pass + def create_counter(self, name, unit=None, description=None) -> APICounter: + # pylint: disable=protected-access + return self._meter_provider._create_counter( + self._instrumentation_info, name, unit, description + ) def create_up_down_counter( self, name, unit=None, description=None - ) -> UpDownCounter: - # FIXME implement this method - pass + ) -> APIUpDownCounter: + # pylint: disable=protected-access + return self._meter_provider._create_up_down_counter( + self._instrumentation_info, name, unit, description + ) def create_observable_counter( self, name, callback, unit=None, description=None - ) -> ObservableCounter: - # FIXME implement this method - pass + ) -> APIObservableCounter: + # pylint: disable=protected-access + return self._meter_provider._create_observable_counter( + self._instrumentation_info, name, unit, description + ) - def create_histogram(self, name, unit=None, description=None) -> Histogram: - # FIXME implement this method - pass + def create_histogram( + self, name, unit=None, description=None + ) -> APIHistogram: + # pylint: disable=protected-access + return self._meter_provider._create_histogram( + self._instrumentation_info, name, unit, description + ) def create_observable_gauge( self, name, callback, unit=None, description=None - ) -> ObservableGauge: - # FIXME implement this method - pass + ) -> APIObservableGauge: + # pylint: disable=protected-access + return self._meter_provider._create_observable_gauge( + self._instrumentation_info, name, unit, description + ) def create_observable_up_down_counter( self, name, callback, unit=None, description=None - ) -> ObservableUpDownCounter: - # FIXME implement this method - pass + ) -> APIObservableUpDownCounter: + # pylint: disable=protected-access + return self._meter_provider._create_observable_up_down_counter( + self._instrumentation_info, name, unit, description + ) class MeterProvider(APIMeterProvider): @@ -84,57 +114,127 @@ class MeterProvider(APIMeterProvider): def __init__( self, + metric_exporters: Sequence[MetricExporter] = (), + metric_readers: Sequence[MetricReader] = (), + views: Sequence[View] = (), resource: Resource = Resource.create({}), shutdown_on_exit: bool = True, + use_always_matching_view: bool = True, ): - self._resource = resource + self._lock = Lock() self._atexit_handler = None + self.__use_always_matching_view = use_always_matching_view if shutdown_on_exit: self._atexit_handler = register(self.shutdown) - self._metric_readers = [] - self._metric_exporters = [] - self._views = [] - self._shutdown = False + self.__metric_readers = metric_readers - def get_meter( - self, - name: str, - version: Optional[str] = None, - schema_url: Optional[str] = None, - ) -> Meter: + for metric_reader in self._metric_readers: + metric_reader._register_meter_provider(self) - if self._shutdown: - _logger.warning( - "A shutdown `MeterProvider` can not provide a `Meter`" - ) - return _DefaultMeter(name, version=version, schema_url=schema_url) + self.__metric_exporters = metric_exporters - return Meter(InstrumentationInfo(name, version, schema_url), self) + self.__views = views - def shutdown(self): - # FIXME implement a timeout + if self.__use_always_matching_view: + self.__views = [*self.__views, View(instrument_name="*")] - if self._shutdown: - _logger.warning("shutdown can only be called once") - return False + self.__resource = resource + self._shutdown = False + self.__synchronous_instruments = [] + self.__asynchronous_instruments = [] - result = True + @property + def _metric_readers(self): + return self.__metric_readers - for metric_reader in self._metric_readers: - result = result and metric_reader.shutdown() + @property + def _use_always_matching_view(self): + return self.__use_always_matching_view - for metric_exporter in self._metric_exporters: - result = result and metric_exporter.shutdown() + @property + def _resource(self): + return self.__resource - self._shutdown = True + @property + def _metric_exporters(self): + return self.__metric_exporters - if self._atexit_handler is not None: - unregister(self._atexit_handler) - self._atexit_handler = None + @property + def _views(self): + return self.__views - return result + @property + def _synchronous_instruments(self): + return self.__synchronous_instruments + + @property + def _asynchronous_instruments(self): + return self.__asynchronous_instruments + + def _create_instrument( + self, instrument_type, instrumentation_info, name, unit, description + ): + + instrument = instrument_type( + instrumentation_info, name, unit=unit, description=description + ) + + with self._lock: + if isinstance(instrument, Synchronous): + self.__synchronous_instruments.append(instrument) + + else: + self.__asynchronous_instruments.append(instrument) + + return instrument + + def _create_counter( + self, instrumentation_info, name, unit, description + ) -> APICounter: + return self._create_instrument( + Counter, instrumentation_info, name, unit, description + ) + + def _create_up_down_counter( + self, instrumentation_info, name, unit, description + ) -> APIUpDownCounter: + return self._create_instrument( + UpDownCounter, instrumentation_info, name, unit, description + ) + + def _create_observable_counter( + self, instrumentation_info, name, unit, description + ) -> APIObservableCounter: + return self._create_instrument( + ObservableCounter, instrumentation_info, name, unit, description + ) + + def _create_histogram( + self, instrumentation_info, name, unit, description + ) -> APIHistogram: + return self._create_instrument( + Histogram, instrumentation_info, name, unit, description + ) + + def _create_observable_gauge( + self, instrumentation_info, name, unit, description + ) -> ObservableGauge: + return self._create_instrument( + ObservableGauge, instrumentation_info, name, unit, description + ) + + def _create_observable_up_down_counter( + self, instrumentation_info, name, unit, description + ) -> ObservableUpDownCounter: + return self._create_instrument( + ObservableUpDownCounter, + instrumentation_info, + name, + unit, + description, + ) def force_flush(self) -> bool: @@ -161,56 +261,40 @@ def force_flush(self) -> bool: return metric_reader_result and metric_exporter_result - def register_metric_reader(self, metric_reader: "MetricReader") -> None: - # FIXME protect this method against race conditions - self._metric_readers.append(metric_reader) - - def register_metric_exporter( - self, metric_exporter: "MetricExporter" - ) -> None: - # FIXME protect this method against race conditions - self._metric_exporters.append(metric_exporter) - - def register_view(self, view: "View") -> None: - # FIXME protect this method against race conditions - self._views.append(view) - - -class MetricReader(ABC): - def __init__(self): - self._shutdown = False - - @abstractmethod - def collect(self): - pass - def shutdown(self): - # FIXME this will need a Once wrapper - self._shutdown = True + # FIXME implement a timeout + + if self._shutdown: + _logger.warning("shutdown can only be called once") + return False + result = True -class MetricExporter(ABC): - def __init__(self): - self._shutdown = False + for metric_reader in self._metric_readers: + result = result and metric_reader.shutdown() - @abstractmethod - def export(self): - pass + for metric_exporter in self._metric_exporters: + result = result and metric_exporter.shutdown() - def shutdown(self): - # FIXME this will need a Once wrapper self._shutdown = True + if self._atexit_handler is not None: + unregister(self._atexit_handler) + self._atexit_handler = None -class View: - pass - + return result -class ConsoleMetricExporter(MetricExporter): - def export(self): - pass + def get_meter( + self, + name: str, + version: Optional[str] = None, + schema_url: Optional[str] = None, + ) -> Meter: + if self._shutdown: + _logger.warning( + "A shutdown `MeterProvider` can not provide a `Meter`" + ) + return _DefaultMeter(name, version=version, schema_url=schema_url) -class SDKMetricReader(MetricReader): - def collect(self): - pass + return Meter(InstrumentationInfo(name, version, schema_url), self) diff --git a/opentelemetry-sdk/src/opentelemetry/sdk/_metrics/metric_exporter.py b/opentelemetry-sdk/src/opentelemetry/sdk/_metrics/metric_exporter.py new file mode 100644 index 00000000000..e9c6d6aae07 --- /dev/null +++ b/opentelemetry-sdk/src/opentelemetry/sdk/_metrics/metric_exporter.py @@ -0,0 +1,17 @@ +# Copyright The OpenTelemetry Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + + +class MetricExporter: + pass diff --git a/opentelemetry-sdk/src/opentelemetry/sdk/_metrics/metric_reader.py b/opentelemetry-sdk/src/opentelemetry/sdk/_metrics/metric_reader.py new file mode 100644 index 00000000000..4bbae6501ca --- /dev/null +++ b/opentelemetry-sdk/src/opentelemetry/sdk/_metrics/metric_reader.py @@ -0,0 +1,17 @@ +# Copyright The OpenTelemetry Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + + +class MetricReader: + pass diff --git a/opentelemetry-sdk/src/opentelemetry/sdk/_metrics/view.py b/opentelemetry-sdk/src/opentelemetry/sdk/_metrics/view.py new file mode 100644 index 00000000000..483fc631f1d --- /dev/null +++ b/opentelemetry-sdk/src/opentelemetry/sdk/_metrics/view.py @@ -0,0 +1,18 @@ +# Copyright The OpenTelemetry Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + + +class View: + def __init__(self, instrument_name=None): + pass diff --git a/opentelemetry-sdk/tests/metrics/test_metrics.py b/opentelemetry-sdk/tests/metrics/test_metrics.py index b473f4f69fb..4ac3d077151 100644 --- a/opentelemetry-sdk/tests/metrics/test_metrics.py +++ b/opentelemetry-sdk/tests/metrics/test_metrics.py @@ -15,14 +15,8 @@ from logging import WARNING from unittest import TestCase -from unittest.mock import Mock -from opentelemetry.sdk._metrics import ( - ConsoleMetricExporter, - MeterProvider, - SDKMetricReader, - View, -) +from opentelemetry.sdk._metrics import MeterProvider from opentelemetry.sdk.resources import Resource @@ -40,7 +34,7 @@ def test_meter_provider_resource(self): self.assertIsInstance(meter_provider_1._resource, Resource) resource = Resource({"key": "value"}) - self.assertIs(MeterProvider(resource)._resource, resource) + self.assertIs(MeterProvider(resource=resource)._resource, resource) def test_get_meter(self): """ @@ -58,75 +52,6 @@ def test_get_meter(self): self.assertEqual(meter._instrumentation_info.version, "version") self.assertEqual(meter._instrumentation_info.schema_url, "schema_url") - def test_register_metric_reader(self): - """ " - `MeterProvider` provides a way to configure `SDKMetricReader`s. - """ - - meter_provider = MeterProvider() - - self.assertTrue(hasattr(meter_provider, "register_metric_reader")) - - metric_reader = SDKMetricReader() - - meter_provider.register_metric_reader(metric_reader) - - self.assertTrue(meter_provider._metric_readers, [metric_reader]) - - def test_register_metric_exporter(self): - """ " - `MeterProvider` provides a way to configure `ConsoleMetricExporter`s. - """ - - meter_provider = MeterProvider() - - self.assertTrue(hasattr(meter_provider, "register_metric_exporter")) - - metric_exporter = ConsoleMetricExporter() - - meter_provider.register_metric_exporter(metric_exporter) - - self.assertTrue(meter_provider._metric_exporters, [metric_exporter]) - - def test_register_view(self): - """ " - `MeterProvider` provides a way to configure `View`s. - """ - - meter_provider = MeterProvider() - - self.assertTrue(hasattr(meter_provider, "register_view")) - - view = View() - - meter_provider.register_view(view) - - self.assertTrue(meter_provider._views, [view]) - - def test_meter_configuration(self): - """ - Any updated configuration is applied to all returned `Meter`s. - """ - - meter_provider = MeterProvider() - - view_0 = View() - - meter_provider.register_view(view_0) - - meter_0 = meter_provider.get_meter("meter_0") - meter_1 = meter_provider.get_meter("meter_1") - - self.assertEqual(meter_0._meter_provider._views, [view_0]) - self.assertEqual(meter_1._meter_provider._views, [view_0]) - - view_1 = View() - - meter_provider.register_view(view_1) - - self.assertEqual(meter_0._meter_provider._views, [view_0, view_1]) - self.assertEqual(meter_1._meter_provider._views, [view_0, view_1]) - def test_shutdown_subsequent_calls(self): """ No subsequent attempts to get a `Meter` are allowed after calling @@ -141,65 +66,3 @@ def test_shutdown_subsequent_calls(self): with self.assertLogs(level=WARNING): meter_provider.shutdown() - - def test_shutdown_result(self): - """ - `MeterProvider.shutdown` provides a way to let the caller know if it - succeeded or failed. - - `MeterProvider.shutdown` is implemented by at least invoking - ``shutdown`` on all registered `SDKMetricReader`s and `ConsoleMetricExporter`s. - """ - - meter_provider = MeterProvider() - - meter_provider.register_metric_reader( - Mock(**{"shutdown.return_value": True}) - ) - meter_provider.register_metric_exporter( - Mock(**{"shutdown.return_value": True}) - ) - - self.assertTrue(meter_provider.shutdown()) - - meter_provider = MeterProvider() - - meter_provider.register_metric_reader( - Mock(**{"shutdown.return_value": True}) - ) - meter_provider.register_metric_exporter( - Mock(**{"shutdown.return_value": False}) - ) - - self.assertFalse(meter_provider.shutdown()) - - def test_force_flush_result(self): - """ - `MeterProvider.force_flush` provides a way to let the caller know if it - succeeded or failed. - - `MeterProvider.force_flush` is implemented by at least invoking - ``force_flush`` on all registered `SDKMetricReader`s and `ConsoleMetricExporter`s. - """ - - meter_provider = MeterProvider() - - meter_provider.register_metric_reader( - Mock(**{"force_flush.return_value": True}) - ) - meter_provider.register_metric_exporter( - Mock(**{"force_flush.return_value": True}) - ) - - self.assertTrue(meter_provider.force_flush()) - - meter_provider = MeterProvider() - - meter_provider.register_metric_reader( - Mock(**{"force_flush.return_value": True}) - ) - meter_provider.register_metric_exporter( - Mock(**{"force_flush.return_value": False}) - ) - - self.assertFalse(meter_provider.force_flush()) From 598d15ecf07b25e4c89d5897c0e0a7d5fe69dc55 Mon Sep 17 00:00:00 2001 From: Diego Hurtado Date: Tue, 7 Dec 2021 22:10:07 -0600 Subject: [PATCH 02/13] Remove synchronous instruments list --- .../src/opentelemetry/sdk/_metrics/__init__.py | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/opentelemetry-sdk/src/opentelemetry/sdk/_metrics/__init__.py b/opentelemetry-sdk/src/opentelemetry/sdk/_metrics/__init__.py index 5b003647aac..17f2800dbf7 100644 --- a/opentelemetry-sdk/src/opentelemetry/sdk/_metrics/__init__.py +++ b/opentelemetry-sdk/src/opentelemetry/sdk/_metrics/__init__.py @@ -20,6 +20,7 @@ from opentelemetry._metrics import Meter as APIMeter from opentelemetry._metrics import MeterProvider as APIMeterProvider from opentelemetry._metrics import _DefaultMeter +from opentelemetry._metrics.instrument import Asynchronous from opentelemetry._metrics.instrument import Counter as APICounter from opentelemetry._metrics.instrument import Histogram as APIHistogram from opentelemetry._metrics.instrument import ( @@ -31,7 +32,6 @@ from opentelemetry._metrics.instrument import ( ObservableUpDownCounter as APIObservableUpDownCounter, ) -from opentelemetry._metrics.instrument import Synchronous from opentelemetry._metrics.instrument import UpDownCounter as APIUpDownCounter from opentelemetry.sdk._metrics.instrument import ( Counter, @@ -142,7 +142,6 @@ def __init__( self.__resource = resource self._shutdown = False - self.__synchronous_instruments = [] self.__asynchronous_instruments = [] @property @@ -165,10 +164,6 @@ def _metric_exporters(self): def _views(self): return self.__views - @property - def _synchronous_instruments(self): - return self.__synchronous_instruments - @property def _asynchronous_instruments(self): return self.__asynchronous_instruments @@ -181,11 +176,8 @@ def _create_instrument( instrumentation_info, name, unit=unit, description=description ) - with self._lock: - if isinstance(instrument, Synchronous): - self.__synchronous_instruments.append(instrument) - - else: + if isinstance(instrument, Asynchronous): + with self._lock: self.__asynchronous_instruments.append(instrument) return instrument From dbeb4d94b0adfdec91796af88df674a202eebca6 Mon Sep 17 00:00:00 2001 From: Diego Hurtado Date: Tue, 7 Dec 2021 22:13:07 -0600 Subject: [PATCH 03/13] Undo changes to _time.py --- opentelemetry-api/src/opentelemetry/util/_time.py | 1 + 1 file changed, 1 insertion(+) diff --git a/opentelemetry-api/src/opentelemetry/util/_time.py b/opentelemetry-api/src/opentelemetry/util/_time.py index a3fd113ce3c..ceaca22e8d4 100644 --- a/opentelemetry-api/src/opentelemetry/util/_time.py +++ b/opentelemetry-api/src/opentelemetry/util/_time.py @@ -28,6 +28,7 @@ def _time_ns() -> int: return int(time() * 1e9) + else: from time import time_ns From c9e9ad3040f2281766a42e8124e0cbcea79c9d75 Mon Sep 17 00:00:00 2001 From: Diego Hurtado Date: Tue, 7 Dec 2021 22:23:32 -0600 Subject: [PATCH 04/13] Make lint pass --- opentelemetry-api/src/opentelemetry/util/_time.py | 1 - 1 file changed, 1 deletion(-) diff --git a/opentelemetry-api/src/opentelemetry/util/_time.py b/opentelemetry-api/src/opentelemetry/util/_time.py index ceaca22e8d4..a3fd113ce3c 100644 --- a/opentelemetry-api/src/opentelemetry/util/_time.py +++ b/opentelemetry-api/src/opentelemetry/util/_time.py @@ -28,7 +28,6 @@ def _time_ns() -> int: return int(time() * 1e9) - else: from time import time_ns From 79887bd94480fbbf05c1aebe82bae7d0d0cc9092 Mon Sep 17 00:00:00 2001 From: Diego Hurtado Date: Tue, 7 Dec 2021 23:05:54 -0600 Subject: [PATCH 05/13] Remove unnecesary docstring --- opentelemetry-sdk/src/opentelemetry/sdk/_metrics/__init__.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/opentelemetry-sdk/src/opentelemetry/sdk/_metrics/__init__.py b/opentelemetry-sdk/src/opentelemetry/sdk/_metrics/__init__.py index 17f2800dbf7..a7257b5d426 100644 --- a/opentelemetry-sdk/src/opentelemetry/sdk/_metrics/__init__.py +++ b/opentelemetry-sdk/src/opentelemetry/sdk/_metrics/__init__.py @@ -51,8 +51,6 @@ class Meter(APIMeter): - """See `opentelemetry._metrics.Meter`.""" - def __init__( self, instrumentation_info: InstrumentationInfo, From 0450a0b214b7723f8a3ce2e8e6389fad92ace7fc Mon Sep 17 00:00:00 2001 From: Diego Hurtado Date: Tue, 7 Dec 2021 23:59:48 -0600 Subject: [PATCH 06/13] Remove _create_instrument --- .../opentelemetry/sdk/_metrics/__init__.py | 64 ++++----- .../opentelemetry/sdk/_metrics/instrument.py | 132 ++++++++---------- 2 files changed, 89 insertions(+), 107 deletions(-) diff --git a/opentelemetry-sdk/src/opentelemetry/sdk/_metrics/__init__.py b/opentelemetry-sdk/src/opentelemetry/sdk/_metrics/__init__.py index a7257b5d426..bfc07e78d53 100644 --- a/opentelemetry-sdk/src/opentelemetry/sdk/_metrics/__init__.py +++ b/opentelemetry-sdk/src/opentelemetry/sdk/_metrics/__init__.py @@ -20,7 +20,6 @@ from opentelemetry._metrics import Meter as APIMeter from opentelemetry._metrics import MeterProvider as APIMeterProvider from opentelemetry._metrics import _DefaultMeter -from opentelemetry._metrics.instrument import Asynchronous from opentelemetry._metrics.instrument import Counter as APICounter from opentelemetry._metrics.instrument import Histogram as APIHistogram from opentelemetry._metrics.instrument import ( @@ -166,66 +165,57 @@ def _views(self): def _asynchronous_instruments(self): return self.__asynchronous_instruments - def _create_instrument( - self, instrument_type, instrumentation_info, name, unit, description - ): - - instrument = instrument_type( - instrumentation_info, name, unit=unit, description=description - ) - - if isinstance(instrument, Asynchronous): - with self._lock: - self.__asynchronous_instruments.append(instrument) - - return instrument - - def _create_counter( + def _create_counter( # pylint: disable=no-self-use self, instrumentation_info, name, unit, description ) -> APICounter: - return self._create_instrument( - Counter, instrumentation_info, name, unit, description - ) + return Counter(instrumentation_info, name, unit, description) - def _create_up_down_counter( + def _create_up_down_counter( # pylint: disable=no-self-use self, instrumentation_info, name, unit, description ) -> APIUpDownCounter: - return self._create_instrument( - UpDownCounter, instrumentation_info, name, unit, description - ) + return UpDownCounter(instrumentation_info, name, unit, description) def _create_observable_counter( self, instrumentation_info, name, unit, description ) -> APIObservableCounter: - return self._create_instrument( - ObservableCounter, instrumentation_info, name, unit, description + instrument = ObservableCounter( + instrumentation_info, name, unit, description ) - def _create_histogram( + with self._lock: + self.__asynchronous_instruments.append(instrument) + + return instrument + + def _create_histogram( # pylint: disable=no-self-use self, instrumentation_info, name, unit, description ) -> APIHistogram: - return self._create_instrument( - Histogram, instrumentation_info, name, unit, description - ) + return Histogram(instrumentation_info, name, unit, description) def _create_observable_gauge( self, instrumentation_info, name, unit, description ) -> ObservableGauge: - return self._create_instrument( - ObservableGauge, instrumentation_info, name, unit, description + instrument = ObservableGauge( + instrumentation_info, name, unit, description ) + with self._lock: + self.__asynchronous_instruments.append(instrument) + + return instrument + def _create_observable_up_down_counter( self, instrumentation_info, name, unit, description ) -> ObservableUpDownCounter: - return self._create_instrument( - ObservableUpDownCounter, - instrumentation_info, - name, - unit, - description, + instrument = ObservableUpDownCounter( + instrumentation_info, name, unit, description ) + with self._lock: + self.__asynchronous_instruments.append(instrument) + + return instrument + def force_flush(self) -> bool: # FIXME implement a timeout diff --git a/opentelemetry-sdk/src/opentelemetry/sdk/_metrics/instrument.py b/opentelemetry-sdk/src/opentelemetry/sdk/_metrics/instrument.py index fc63311ce7b..28ccaf1c683 100644 --- a/opentelemetry-sdk/src/opentelemetry/sdk/_metrics/instrument.py +++ b/opentelemetry-sdk/src/opentelemetry/sdk/_metrics/instrument.py @@ -19,142 +19,134 @@ # all instances. Implementations of these classes must not make any change to # this default dictionary in __init__. +from opentelemetry._metrics.instrument import Counter as APICounter +from opentelemetry._metrics.instrument import Histogram as APIHistogram from opentelemetry._metrics.instrument import ( - Counter, - Histogram, - ObservableCounter, - ObservableGauge, - ObservableUpDownCounter, - UpDownCounter, + ObservableCounter as APIObservableCounter, ) -from opentelemetry.sdk._metrics.aggregation import ( - ExplicitBucketHistogramAggregation, - LastValueAggregation, - SumAggregation, +from opentelemetry._metrics.instrument import ( + ObservableGauge as APIObservableGauge, +) +from opentelemetry._metrics.instrument import ( + ObservableUpDownCounter as APIObservableUpDownCounter, ) +from opentelemetry._metrics.instrument import UpDownCounter as APIUpDownCounter +from opentelemetry.sdk.util.instrumentation import InstrumentationInfo class _Instrument: def __init__( self, - name, - unit="", - description="", - aggregation=None, - aggregation_config={}, + instrumentation_info: InstrumentationInfo, + name: str, + unit: str = "", + description: str = "", ): - self._attributes_aggregations = {} - self._aggregation = aggregation - self._aggregation_config = aggregation_config - aggregation(self, **aggregation_config) + self._instrumentation_info = instrumentation_info + super().__init__(name, unit=unit, description=description) -class Counter(_Instrument, Counter): +class Counter(_Instrument, APICounter): def __init__( self, - name, - unit="", - description="", - aggregation=SumAggregation, - aggregation_config={}, + instrumentation_info: InstrumentationInfo, + name: str, + unit: str = "", + description: str = "", ): super().__init__( + instrumentation_info, name, unit=unit, description=description, - aggregation=aggregation, - aggregation_config=aggregation_config, ) + def add(self, amount, attributes=None): + # FIXME check that the amount is non negative + pass -class UpDownCounter(_Instrument, UpDownCounter): + +class UpDownCounter(_Instrument, APIUpDownCounter): def __init__( self, - name, - unit="", - description="", - aggregation=SumAggregation, - aggregation_config={}, + instrumentation_info: InstrumentationInfo, + name: str, + unit: str = "", + description: str = "", ): super().__init__( + instrumentation_info, name, unit=unit, description=description, - aggregation=aggregation, - aggregation_config=aggregation_config, ) + def add(self, amount, attributes=None): + pass + -class ObservableCounter(_Instrument, ObservableCounter): +class ObservableCounter(_Instrument, APIObservableCounter): def __init__( self, - name, - callback, - unit="", - description="", - aggregation=SumAggregation, - aggregation_config={}, + instrumentation_info: InstrumentationInfo, + name: str, + unit: str = "", + description: str = "", ): super().__init__( + instrumentation_info, name, unit=unit, description=description, - aggregation=aggregation, - aggregation_config=aggregation_config, ) -class ObservableUpDownCounter(_Instrument, ObservableUpDownCounter): +class ObservableUpDownCounter(_Instrument, APIObservableUpDownCounter): def __init__( self, - name, - callback, - unit="", - description="", - aggregation=SumAggregation, - aggregation_config={}, + instrumentation_info: InstrumentationInfo, + name: str, + unit: str = "", + description: str = "", ): super().__init__( + instrumentation_info, name, unit=unit, description=description, - aggregation=aggregation, - aggregation_config=aggregation_config, ) -class Histogram(_Instrument, Histogram): +class Histogram(_Instrument, APIHistogram): def __init__( self, - name, - unit="", - description="", - aggregation=ExplicitBucketHistogramAggregation, - aggregation_config={}, + instrumentation_info: InstrumentationInfo, + name: str, + unit: str = "", + description: str = "", ): super().__init__( + instrumentation_info, name, unit=unit, description=description, - aggregation=aggregation, - aggregation_config=aggregation_config, ) + def record(self, amount, attributes=None): + pass + -class ObservableGauge(_Instrument, ObservableGauge): +class ObservableGauge(_Instrument, APIObservableGauge): def __init__( self, - name, - callback, - unit="", - description="", - aggregation=LastValueAggregation, - aggregation_config={}, + instrumentation_info: InstrumentationInfo, + name: str, + unit: str = "", + description: str = "", ): super().__init__( + instrumentation_info, name, unit=unit, description=description, - aggregation=aggregation, - aggregation_config=aggregation_config, ) From cbb4cb89414f087577cecda2cd22802d8dbcc3d7 Mon Sep 17 00:00:00 2001 From: Diego Hurtado Date: Wed, 8 Dec 2021 09:24:32 -0600 Subject: [PATCH 07/13] Add missing callback --- .../opentelemetry/sdk/_metrics/instrument.py | 10 ++- .../tests/metrics/test_metrics.py | 61 ++++++++++++++++++- 2 files changed, 69 insertions(+), 2 deletions(-) diff --git a/opentelemetry-sdk/src/opentelemetry/sdk/_metrics/instrument.py b/opentelemetry-sdk/src/opentelemetry/sdk/_metrics/instrument.py index 28ccaf1c683..cd1510f4220 100644 --- a/opentelemetry-sdk/src/opentelemetry/sdk/_metrics/instrument.py +++ b/opentelemetry-sdk/src/opentelemetry/sdk/_metrics/instrument.py @@ -30,6 +30,7 @@ from opentelemetry._metrics.instrument import ( ObservableUpDownCounter as APIObservableUpDownCounter, ) +from opentelemetry._metrics.instrument import TCallback from opentelemetry._metrics.instrument import UpDownCounter as APIUpDownCounter from opentelemetry.sdk.util.instrumentation import InstrumentationInfo @@ -39,11 +40,12 @@ def __init__( self, instrumentation_info: InstrumentationInfo, name: str, + *args, unit: str = "", description: str = "", ): self._instrumentation_info = instrumentation_info - super().__init__(name, unit=unit, description=description) + super().__init__(name, *args, unit=unit, description=description) class Counter(_Instrument, APICounter): @@ -90,12 +92,14 @@ def __init__( self, instrumentation_info: InstrumentationInfo, name: str, + callback: TCallback, unit: str = "", description: str = "", ): super().__init__( instrumentation_info, name, + callback, unit=unit, description=description, ) @@ -106,12 +110,14 @@ def __init__( self, instrumentation_info: InstrumentationInfo, name: str, + callback: TCallback, unit: str = "", description: str = "", ): super().__init__( instrumentation_info, name, + callback, unit=unit, description=description, ) @@ -141,12 +147,14 @@ def __init__( self, instrumentation_info: InstrumentationInfo, name: str, + callback: TCallback, unit: str = "", description: str = "", ): super().__init__( instrumentation_info, name, + callback, unit=unit, description=description, ) diff --git a/opentelemetry-sdk/tests/metrics/test_metrics.py b/opentelemetry-sdk/tests/metrics/test_metrics.py index 4ac3d077151..0077d5b1cdd 100644 --- a/opentelemetry-sdk/tests/metrics/test_metrics.py +++ b/opentelemetry-sdk/tests/metrics/test_metrics.py @@ -15,8 +15,17 @@ from logging import WARNING from unittest import TestCase +from unittest.mock import Mock -from opentelemetry.sdk._metrics import MeterProvider +from opentelemetry.sdk._metrics import Meter, MeterProvider +from opentelemetry.sdk._metrics.instrument import ( + Counter, + Histogram, + ObservableCounter, + ObservableGauge, + ObservableUpDownCounter, + UpDownCounter, +) from opentelemetry.sdk.resources import Resource @@ -66,3 +75,53 @@ def test_shutdown_subsequent_calls(self): with self.assertLogs(level=WARNING): meter_provider.shutdown() + + +class TestMeter(TestCase): + def setUp(self): + self.meter = Meter(Mock(), MeterProvider()) + + def test_create_counter(self): + counter = self.meter.create_counter( + "name", unit="unit", description="description" + ) + + self.assertIsInstance(counter, Counter) + + def test_create_up_down_counter(self): + up_down_counter = self.meter.create_up_down_counter( + "name", unit="unit", description="description" + ) + + self.assertIsInstance(up_down_counter, UpDownCounter) + + def test_create_observable_counter(self): + observable_counter = self.meter.create_observable_counter( + "name", Mock(), unit="unit", description="description" + ) + + self.assertIsInstance(observable_counter, ObservableCounter) + + def test_create_histogram(self): + histogram = self.meter.create_histogram( + "name", unit="unit", description="description" + ) + + self.assertIsInstance(histogram, Histogram) + + def test_create_observable_gauge(self): + observable_gauge = self.meter.create_observable_gauge( + "name", Mock(), unit="unit", description="description" + ) + + self.assertIsInstance(observable_gauge, ObservableGauge) + + def test_create_observable_up_down_counter(self): + observable_up_down_counter = ( + self.meter.create_observable_up_down_counter( + "name", Mock(), unit="unit", description="description" + ) + ) + self.assertIsInstance( + observable_up_down_counter, ObservableUpDownCounter + ) From d93b4301fe9f337a06f33cdd633f450359d27481 Mon Sep 17 00:00:00 2001 From: Diego Hurtado Date: Wed, 8 Dec 2021 10:13:31 -0600 Subject: [PATCH 08/13] Remove instrument creating methods from MeterProvider --- .../opentelemetry/sdk/_metrics/__init__.py | 78 ++----------------- 1 file changed, 6 insertions(+), 72 deletions(-) diff --git a/opentelemetry-sdk/src/opentelemetry/sdk/_metrics/__init__.py b/opentelemetry-sdk/src/opentelemetry/sdk/_metrics/__init__.py index bfc07e78d53..c932fa572c7 100644 --- a/opentelemetry-sdk/src/opentelemetry/sdk/_metrics/__init__.py +++ b/opentelemetry-sdk/src/opentelemetry/sdk/_metrics/__init__.py @@ -60,48 +60,38 @@ def __init__( self._meter_provider = meter_provider def create_counter(self, name, unit=None, description=None) -> APICounter: - # pylint: disable=protected-access - return self._meter_provider._create_counter( - self._instrumentation_info, name, unit, description - ) + return Counter(self._instrumentation_info, name, unit, description) def create_up_down_counter( self, name, unit=None, description=None ) -> APIUpDownCounter: - # pylint: disable=protected-access - return self._meter_provider._create_up_down_counter( + return UpDownCounter( self._instrumentation_info, name, unit, description ) def create_observable_counter( self, name, callback, unit=None, description=None ) -> APIObservableCounter: - # pylint: disable=protected-access - return self._meter_provider._create_observable_counter( + return ObservableCounter( self._instrumentation_info, name, unit, description ) def create_histogram( self, name, unit=None, description=None ) -> APIHistogram: - # pylint: disable=protected-access - return self._meter_provider._create_histogram( - self._instrumentation_info, name, unit, description - ) + return Histogram(self._instrumentation_info, name, unit, description) def create_observable_gauge( self, name, callback, unit=None, description=None ) -> APIObservableGauge: - # pylint: disable=protected-access - return self._meter_provider._create_observable_gauge( + return ObservableGauge( self._instrumentation_info, name, unit, description ) def create_observable_up_down_counter( self, name, callback, unit=None, description=None ) -> APIObservableUpDownCounter: - # pylint: disable=protected-access - return self._meter_provider._create_observable_up_down_counter( + return ObservableUpDownCounter( self._instrumentation_info, name, unit, description ) @@ -139,7 +129,6 @@ def __init__( self.__resource = resource self._shutdown = False - self.__asynchronous_instruments = [] @property def _metric_readers(self): @@ -161,61 +150,6 @@ def _metric_exporters(self): def _views(self): return self.__views - @property - def _asynchronous_instruments(self): - return self.__asynchronous_instruments - - def _create_counter( # pylint: disable=no-self-use - self, instrumentation_info, name, unit, description - ) -> APICounter: - return Counter(instrumentation_info, name, unit, description) - - def _create_up_down_counter( # pylint: disable=no-self-use - self, instrumentation_info, name, unit, description - ) -> APIUpDownCounter: - return UpDownCounter(instrumentation_info, name, unit, description) - - def _create_observable_counter( - self, instrumentation_info, name, unit, description - ) -> APIObservableCounter: - instrument = ObservableCounter( - instrumentation_info, name, unit, description - ) - - with self._lock: - self.__asynchronous_instruments.append(instrument) - - return instrument - - def _create_histogram( # pylint: disable=no-self-use - self, instrumentation_info, name, unit, description - ) -> APIHistogram: - return Histogram(instrumentation_info, name, unit, description) - - def _create_observable_gauge( - self, instrumentation_info, name, unit, description - ) -> ObservableGauge: - instrument = ObservableGauge( - instrumentation_info, name, unit, description - ) - - with self._lock: - self.__asynchronous_instruments.append(instrument) - - return instrument - - def _create_observable_up_down_counter( - self, instrumentation_info, name, unit, description - ) -> ObservableUpDownCounter: - instrument = ObservableUpDownCounter( - instrumentation_info, name, unit, description - ) - - with self._lock: - self.__asynchronous_instruments.append(instrument) - - return instrument - def force_flush(self) -> bool: # FIXME implement a timeout From 389011de482f6dbc0a13d4bff0c8506a7ca409f1 Mon Sep 17 00:00:00 2001 From: Diego Hurtado Date: Wed, 8 Dec 2021 10:22:33 -0600 Subject: [PATCH 09/13] Remove views and other attributes --- .../opentelemetry/sdk/_metrics/__init__.py | 35 ++----------------- .../src/opentelemetry/sdk/_metrics/view.py | 18 ---------- 2 files changed, 3 insertions(+), 50 deletions(-) delete mode 100644 opentelemetry-sdk/src/opentelemetry/sdk/_metrics/view.py diff --git a/opentelemetry-sdk/src/opentelemetry/sdk/_metrics/__init__.py b/opentelemetry-sdk/src/opentelemetry/sdk/_metrics/__init__.py index c932fa572c7..0063dfce893 100644 --- a/opentelemetry-sdk/src/opentelemetry/sdk/_metrics/__init__.py +++ b/opentelemetry-sdk/src/opentelemetry/sdk/_metrics/__init__.py @@ -42,7 +42,6 @@ ) from opentelemetry.sdk._metrics.metric_exporter import MetricExporter from opentelemetry.sdk._metrics.metric_reader import MetricReader -from opentelemetry.sdk._metrics.view import View from opentelemetry.sdk.resources import Resource from opentelemetry.sdk.util.instrumentation import InstrumentationInfo @@ -103,53 +102,25 @@ def __init__( self, metric_exporters: Sequence[MetricExporter] = (), metric_readers: Sequence[MetricReader] = (), - views: Sequence[View] = (), resource: Resource = Resource.create({}), shutdown_on_exit: bool = True, - use_always_matching_view: bool = True, ): self._lock = Lock() self._atexit_handler = None - self.__use_always_matching_view = use_always_matching_view if shutdown_on_exit: self._atexit_handler = register(self.shutdown) - self.__metric_readers = metric_readers + self._metric_readers = metric_readers for metric_reader in self._metric_readers: metric_reader._register_meter_provider(self) - self.__metric_exporters = metric_exporters + self._metric_exporters = metric_exporters - self.__views = views - - if self.__use_always_matching_view: - self.__views = [*self.__views, View(instrument_name="*")] - - self.__resource = resource + self._resource = resource self._shutdown = False - @property - def _metric_readers(self): - return self.__metric_readers - - @property - def _use_always_matching_view(self): - return self.__use_always_matching_view - - @property - def _resource(self): - return self.__resource - - @property - def _metric_exporters(self): - return self.__metric_exporters - - @property - def _views(self): - return self.__views - def force_flush(self) -> bool: # FIXME implement a timeout diff --git a/opentelemetry-sdk/src/opentelemetry/sdk/_metrics/view.py b/opentelemetry-sdk/src/opentelemetry/sdk/_metrics/view.py deleted file mode 100644 index 483fc631f1d..00000000000 --- a/opentelemetry-sdk/src/opentelemetry/sdk/_metrics/view.py +++ /dev/null @@ -1,18 +0,0 @@ -# Copyright The OpenTelemetry Authors -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - - -class View: - def __init__(self, instrument_name=None): - pass From 94b8d2e4a0655234e24fa95570d06e1e60a864d3 Mon Sep 17 00:00:00 2001 From: Diego Hurtado Date: Wed, 8 Dec 2021 10:35:47 -0600 Subject: [PATCH 10/13] Removed dataclass dependency --- opentelemetry-sdk/setup.cfg | 2 -- 1 file changed, 2 deletions(-) diff --git a/opentelemetry-sdk/setup.cfg b/opentelemetry-sdk/setup.cfg index eb6b81d5e15..e78448dd820 100644 --- a/opentelemetry-sdk/setup.cfg +++ b/opentelemetry-sdk/setup.cfg @@ -45,8 +45,6 @@ include_package_data = True install_requires = opentelemetry-api == 1.7.1 opentelemetry-semantic-conventions == 0.26b1 - # FIXME Remove when 3.6 is no longer supported - dataclasses == 0.8; python_version < '3.7' [options.packages.find] where = src From e57b2d3bba68b7bdb2f547084f744e3fa63c5026 Mon Sep 17 00:00:00 2001 From: Diego Hurtado Date: Wed, 8 Dec 2021 10:52:11 -0600 Subject: [PATCH 11/13] Add warning --- .../src/opentelemetry/sdk/_metrics/__init__.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/opentelemetry-sdk/src/opentelemetry/sdk/_metrics/__init__.py b/opentelemetry-sdk/src/opentelemetry/sdk/_metrics/__init__.py index 0063dfce893..6628d7ca694 100644 --- a/opentelemetry-sdk/src/opentelemetry/sdk/_metrics/__init__.py +++ b/opentelemetry-sdk/src/opentelemetry/sdk/_metrics/__init__.py @@ -158,9 +158,15 @@ def shutdown(self): for metric_reader in self._metric_readers: result = result and metric_reader.shutdown() + if not result: + _logger.warning("A MetricReader failed to shutdown") + for metric_exporter in self._metric_exporters: result = result and metric_exporter.shutdown() + if not result: + _logger.warning("A MetricExporter failed to shutdown") + self._shutdown = True if self._atexit_handler is not None: From 52b0dcc0dfc57812436c44f16452ca57ef2cf8b5 Mon Sep 17 00:00:00 2001 From: Diego Hurtado Date: Wed, 8 Dec 2021 11:56:42 -0600 Subject: [PATCH 12/13] Add export directory --- .../src/opentelemetry/sdk/_metrics/__init__.py | 2 +- .../opentelemetry/sdk/_metrics/export/__init__.py | 13 +++++++++++++ .../sdk/_metrics/{ => export}/metric_exporter.py | 0 3 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 opentelemetry-sdk/src/opentelemetry/sdk/_metrics/export/__init__.py rename opentelemetry-sdk/src/opentelemetry/sdk/_metrics/{ => export}/metric_exporter.py (100%) diff --git a/opentelemetry-sdk/src/opentelemetry/sdk/_metrics/__init__.py b/opentelemetry-sdk/src/opentelemetry/sdk/_metrics/__init__.py index 6628d7ca694..0feb5361d01 100644 --- a/opentelemetry-sdk/src/opentelemetry/sdk/_metrics/__init__.py +++ b/opentelemetry-sdk/src/opentelemetry/sdk/_metrics/__init__.py @@ -32,6 +32,7 @@ ObservableUpDownCounter as APIObservableUpDownCounter, ) from opentelemetry._metrics.instrument import UpDownCounter as APIUpDownCounter +from opentelemetry.sdk._metrics.export.metric_exporter import MetricExporter from opentelemetry.sdk._metrics.instrument import ( Counter, Histogram, @@ -40,7 +41,6 @@ ObservableUpDownCounter, UpDownCounter, ) -from opentelemetry.sdk._metrics.metric_exporter import MetricExporter from opentelemetry.sdk._metrics.metric_reader import MetricReader from opentelemetry.sdk.resources import Resource from opentelemetry.sdk.util.instrumentation import InstrumentationInfo diff --git a/opentelemetry-sdk/src/opentelemetry/sdk/_metrics/export/__init__.py b/opentelemetry-sdk/src/opentelemetry/sdk/_metrics/export/__init__.py new file mode 100644 index 00000000000..b0a6f428417 --- /dev/null +++ b/opentelemetry-sdk/src/opentelemetry/sdk/_metrics/export/__init__.py @@ -0,0 +1,13 @@ +# Copyright The OpenTelemetry Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. diff --git a/opentelemetry-sdk/src/opentelemetry/sdk/_metrics/metric_exporter.py b/opentelemetry-sdk/src/opentelemetry/sdk/_metrics/export/metric_exporter.py similarity index 100% rename from opentelemetry-sdk/src/opentelemetry/sdk/_metrics/metric_exporter.py rename to opentelemetry-sdk/src/opentelemetry/sdk/_metrics/export/metric_exporter.py From 24a04a44643b5c7ddb04ddac27d55da12f3fe98e Mon Sep 17 00:00:00 2001 From: Diego Hurtado Date: Wed, 8 Dec 2021 14:12:47 -0600 Subject: [PATCH 13/13] Add missing callbacks --- .../src/opentelemetry/sdk/_metrics/__init__.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/opentelemetry-sdk/src/opentelemetry/sdk/_metrics/__init__.py b/opentelemetry-sdk/src/opentelemetry/sdk/_metrics/__init__.py index 0feb5361d01..bf04d8fe1f6 100644 --- a/opentelemetry-sdk/src/opentelemetry/sdk/_metrics/__init__.py +++ b/opentelemetry-sdk/src/opentelemetry/sdk/_metrics/__init__.py @@ -72,7 +72,7 @@ def create_observable_counter( self, name, callback, unit=None, description=None ) -> APIObservableCounter: return ObservableCounter( - self._instrumentation_info, name, unit, description + self._instrumentation_info, name, callback, unit, description ) def create_histogram( @@ -84,14 +84,14 @@ def create_observable_gauge( self, name, callback, unit=None, description=None ) -> APIObservableGauge: return ObservableGauge( - self._instrumentation_info, name, unit, description + self._instrumentation_info, name, callback, unit, description ) def create_observable_up_down_counter( self, name, callback, unit=None, description=None ) -> APIObservableUpDownCounter: return ObservableUpDownCounter( - self._instrumentation_info, name, unit, description + self._instrumentation_info, name, callback, unit, description )