Repository: open-telemetry/opentelemetry-python

Issue:
Error when using OTLP to export a SumObserver
**Describe your environment** 
Python 3.8.1
opentelemetry-exporter-otlp 0.16b0
opentelemetry-sdk 0.16b0
opentelemetry-instrumentation-system-metrics 0.16b0

**Steps to reproduce**
Tried to use the latest version of system-metrics instrumentation

**What is the expected behavior?**
Metrics to be exported as with v0.15b0

**What is the actual behavior?**
```
    export_record.instrument.meter.instrumentation_info.name
AttributeError: 'SumObserver' object has no attribute 'meter'
```

**Additional context**
The problem appears to be that Observers don't have a meter associated with them, which causes [this change](https://github.com/open-telemetry/opentelemetry-python/pull/1418) to trigger this error 



Discussion:

Resolving patch:
diff --git a/opentelemetry-sdk/src/opentelemetry/sdk/metrics/__init__.py b/opentelemetry-sdk/src/opentelemetry/sdk/metrics/__init__.py
--- a/opentelemetry-sdk/src/opentelemetry/sdk/metrics/__init__.py
+++ b/opentelemetry-sdk/src/opentelemetry/sdk/metrics/__init__.py
@@ -241,6 +241,7 @@ def __init__(
         description: str,
         unit: str,
         value_type: Type[metrics_api.ValueT],
+        meter: "Accumulator",
         label_keys: Sequence[str] = (),
         enabled: bool = True,
     ):
@@ -249,6 +250,7 @@ def __init__(
         self.description = description
         self.unit = unit
         self.value_type = value_type
+        self.meter = meter
         self.label_keys = label_keys
         self.enabled = enabled
 
@@ -477,7 +479,14 @@ def register_sumobserver(
         enabled: bool = True,
     ) -> metrics_api.SumObserver:
         ob = SumObserver(
-            callback, name, description, unit, value_type, label_keys, enabled
+            callback,
+            name,
+            description,
+            unit,
+            value_type,
+            self,
+            label_keys,
+            enabled,
         )
         with self.observers_lock:
             self.observers.add(ob)
@@ -494,7 +503,14 @@ def register_updownsumobserver(
         enabled: bool = True,
     ) -> metrics_api.UpDownSumObserver:
         ob = UpDownSumObserver(
-            callback, name, description, unit, value_type, label_keys, enabled
+            callback,
+            name,
+            description,
+            unit,
+            value_type,
+            self,
+            label_keys,
+            enabled,
         )
         with self.observers_lock:
             self.observers.add(ob)
@@ -511,7 +527,14 @@ def register_valueobserver(
         enabled: bool = True,
     ) -> metrics_api.ValueObserver:
         ob = ValueObserver(
-            callback, name, description, unit, value_type, label_keys, enabled
+            callback,
+            name,
+            description,
+            unit,
+            value_type,
+            self,
+            label_keys,
+            enabled,
         )
         with self.observers_lock:
             self.observers.add(ob)


Test patch:
diff --git a/exporter/opentelemetry-exporter-otlp/tests/test_otlp_metric_exporter.py b/exporter/opentelemetry-exporter-otlp/tests/test_otlp_metric_exporter.py
--- a/exporter/opentelemetry-exporter-otlp/tests/test_otlp_metric_exporter.py
+++ b/exporter/opentelemetry-exporter-otlp/tests/test_otlp_metric_exporter.py
@@ -15,7 +15,7 @@
 import os
 from collections import OrderedDict
 from unittest import TestCase
-from unittest.mock import patch
+from unittest.mock import Mock, patch
 
 from grpc import ChannelCredentials
 
@@ -41,7 +41,13 @@
 from opentelemetry.proto.resource.v1.resource_pb2 import (
     Resource as OTLPResource,
 )
-from opentelemetry.sdk.metrics import Counter, MeterProvider
+from opentelemetry.sdk.metrics import (
+    Counter,
+    MeterProvider,
+    SumObserver,
+    UpDownCounter,
+    UpDownSumObserver,
+)
 from opentelemetry.sdk.metrics.export import ExportRecord
 from opentelemetry.sdk.metrics.export.aggregate import SumAggregator
 from opentelemetry.sdk.resources import Resource as SDKResource
@@ -50,26 +56,12 @@
 
 
 class TestOTLPMetricExporter(TestCase):
-    @patch("opentelemetry.sdk.metrics.export.aggregate.time_ns")
-    def setUp(self, mock_time_ns):  # pylint: disable=arguments-differ
-        mock_time_ns.configure_mock(**{"return_value": 1})
+    def setUp(self):  # pylint: disable=arguments-differ
         self.exporter = OTLPMetricsExporter(insecure=True)
-        resource = SDKResource(OrderedDict([("a", 1), ("b", False)]))
-
-        self.counter_export_record = ExportRecord(
-            Counter(
-                "c",
-                "d",
-                "e",
-                int,
-                MeterProvider(resource=resource,).get_meter("name", "version"),
-                ("f",),
-            ),
-            [("g", "h")],
-            SumAggregator(),
-            resource,
+        self.resource = SDKResource(OrderedDict([("a", 1), ("b", False)]))
+        self.meter = MeterProvider(resource=self.resource,).get_meter(
+            "name", "version"
         )
-
         Configuration._reset()  # pylint: disable=protected-access
 
     def tearDown(self):
@@ -102,12 +94,20 @@ def test_no_credentials_error(self):
         with self.assertRaises(ValueError):
             OTLPMetricsExporter()
 
-    def test_translate_metrics(self):
-        # pylint: disable=no-member
+    @patch("opentelemetry.sdk.metrics.export.aggregate.time_ns")
+    def test_translate_counter_export_record(self, mock_time_ns):
+        mock_time_ns.configure_mock(**{"return_value": 1})
+
+        counter_export_record = ExportRecord(
+            Counter("c", "d", "e", int, self.meter, ("f",),),
+            [("g", "h")],
+            SumAggregator(),
+            self.resource,
+        )
 
-        self.counter_export_record.aggregator.checkpoint = 1
-        self.counter_export_record.aggregator.initial_checkpoint_timestamp = 1
-        self.counter_export_record.aggregator.last_update_timestamp = 1
+        counter_export_record.aggregator.checkpoint = 1
+        counter_export_record.aggregator.initial_checkpoint_timestamp = 1
+        counter_export_record.aggregator.last_update_timestamp = 1
 
         expected = ExportMetricsServiceRequest(
             resource_metrics=[
@@ -157,6 +157,203 @@ def test_translate_metrics(self):
         )
 
         # pylint: disable=protected-access
-        actual = self.exporter._translate_data([self.counter_export_record])
+        actual = self.exporter._translate_data([counter_export_record])
+
+        self.assertEqual(expected, actual)
+
+    @patch("opentelemetry.sdk.metrics.export.aggregate.time_ns")
+    def test_translate_sum_observer_export_record(self, mock_time_ns):
+        mock_time_ns.configure_mock(**{"return_value": 1})
+        counter_export_record = ExportRecord(
+            SumObserver(Mock(), "c", "d", "e", int, self.meter, ("f",),),
+            [("g", "h")],
+            SumAggregator(),
+            self.resource,
+        )
+
+        counter_export_record.aggregator.checkpoint = 1
+        counter_export_record.aggregator.initial_checkpoint_timestamp = 1
+        counter_export_record.aggregator.last_update_timestamp = 1
+
+        expected = ExportMetricsServiceRequest(
+            resource_metrics=[
+                ResourceMetrics(
+                    resource=OTLPResource(
+                        attributes=[
+                            KeyValue(key="a", value=AnyValue(int_value=1)),
+                            KeyValue(
+                                key="b", value=AnyValue(bool_value=False)
+                            ),
+                        ]
+                    ),
+                    instrumentation_library_metrics=[
+                        InstrumentationLibraryMetrics(
+                            instrumentation_library=InstrumentationLibrary(
+                                name="name", version="version",
+                            ),
+                            metrics=[
+                                OTLPMetric(
+                                    name="c",
+                                    description="d",
+                                    unit="e",
+                                    int_sum=IntSum(
+                                        data_points=[
+                                            IntDataPoint(
+                                                labels=[
+                                                    StringKeyValue(
+                                                        key="g", value="h"
+                                                    )
+                                                ],
+                                                value=1,
+                                                time_unix_nano=1,
+                                                start_time_unix_nano=1,
+                                            )
+                                        ],
+                                        aggregation_temporality=(
+                                            AggregationTemporality.AGGREGATION_TEMPORALITY_CUMULATIVE
+                                        ),
+                                        is_monotonic=True,
+                                    ),
+                                )
+                            ],
+                        )
+                    ],
+                )
+            ]
+        )
+
+        # pylint: disable=protected-access
+        actual = self.exporter._translate_data([counter_export_record])
+
+        self.assertEqual(expected, actual)
+
+    @patch("opentelemetry.sdk.metrics.export.aggregate.time_ns")
+    def test_translate_updowncounter_export_record(self, mock_time_ns):
+        mock_time_ns.configure_mock(**{"return_value": 1})
+
+        counter_export_record = ExportRecord(
+            UpDownCounter("c", "d", "e", int, self.meter),
+            [("g", "h")],
+            SumAggregator(),
+            self.resource,
+        )
+
+        counter_export_record.aggregator.checkpoint = 1
+        counter_export_record.aggregator.initial_checkpoint_timestamp = 1
+        counter_export_record.aggregator.last_update_timestamp = 1
+
+        expected = ExportMetricsServiceRequest(
+            resource_metrics=[
+                ResourceMetrics(
+                    resource=OTLPResource(
+                        attributes=[
+                            KeyValue(key="a", value=AnyValue(int_value=1)),
+                            KeyValue(
+                                key="b", value=AnyValue(bool_value=False)
+                            ),
+                        ]
+                    ),
+                    instrumentation_library_metrics=[
+                        InstrumentationLibraryMetrics(
+                            instrumentation_library=InstrumentationLibrary(
+                                name="name", version="version",
+                            ),
+                            metrics=[
+                                OTLPMetric(
+                                    name="c",
+                                    description="d",
+                                    unit="e",
+                                    int_sum=IntSum(
+                                        data_points=[
+                                            IntDataPoint(
+                                                labels=[
+                                                    StringKeyValue(
+                                                        key="g", value="h"
+                                                    )
+                                                ],
+                                                value=1,
+                                                time_unix_nano=1,
+                                                start_time_unix_nano=1,
+                                            )
+                                        ],
+                                        aggregation_temporality=(
+                                            AggregationTemporality.AGGREGATION_TEMPORALITY_CUMULATIVE
+                                        ),
+                                    ),
+                                )
+                            ],
+                        )
+                    ],
+                )
+            ]
+        )
+
+        # pylint: disable=protected-access
+        actual = self.exporter._translate_data([counter_export_record])
+
+        self.assertEqual(expected, actual)
+
+    @patch("opentelemetry.sdk.metrics.export.aggregate.time_ns")
+    def test_translate_updownsum_observer_export_record(self, mock_time_ns):
+        mock_time_ns.configure_mock(**{"return_value": 1})
+        counter_export_record = ExportRecord(
+            UpDownSumObserver(Mock(), "c", "d", "e", int, self.meter, ("f",),),
+            [("g", "h")],
+            SumAggregator(),
+            self.resource,
+        )
+
+        counter_export_record.aggregator.checkpoint = 1
+        counter_export_record.aggregator.initial_checkpoint_timestamp = 1
+        counter_export_record.aggregator.last_update_timestamp = 1
+
+        expected = ExportMetricsServiceRequest(
+            resource_metrics=[
+                ResourceMetrics(
+                    resource=OTLPResource(
+                        attributes=[
+                            KeyValue(key="a", value=AnyValue(int_value=1)),
+                            KeyValue(
+                                key="b", value=AnyValue(bool_value=False)
+                            ),
+                        ]
+                    ),
+                    instrumentation_library_metrics=[
+                        InstrumentationLibraryMetrics(
+                            instrumentation_library=InstrumentationLibrary(
+                                name="name", version="version",
+                            ),
+                            metrics=[
+                                OTLPMetric(
+                                    name="c",
+                                    description="d",
+                                    unit="e",
+                                    int_sum=IntSum(
+                                        data_points=[
+                                            IntDataPoint(
+                                                labels=[
+                                                    StringKeyValue(
+                                                        key="g", value="h"
+                                                    )
+                                                ],
+                                                value=1,
+                                                time_unix_nano=1,
+                                                start_time_unix_nano=1,
+                                            )
+                                        ],
+                                        aggregation_temporality=(
+                                            AggregationTemporality.AGGREGATION_TEMPORALITY_CUMULATIVE
+                                        ),
+                                    ),
+                                )
+                            ],
+                        )
+                    ],
+                )
+            ]
+        )
+
+        # pylint: disable=protected-access
+        actual = self.exporter._translate_data([counter_export_record])
 
         self.assertEqual(expected, actual)
diff --git a/opentelemetry-sdk/tests/metrics/test_metrics.py b/opentelemetry-sdk/tests/metrics/test_metrics.py
--- a/opentelemetry-sdk/tests/metrics/test_metrics.py
+++ b/opentelemetry-sdk/tests/metrics/test_metrics.py
@@ -13,7 +13,7 @@
 # limitations under the License.
 
 import unittest
-from unittest import mock
+from unittest.mock import Mock, patch
 
 from opentelemetry import metrics as metrics_api
 from opentelemetry.sdk import metrics, resources
@@ -41,7 +41,7 @@ def test_resource_empty(self):
         self.assertEqual(meter_provider.resource, resources._DEFAULT_RESOURCE)
 
     def test_start_pipeline(self):
-        exporter = mock.Mock()
+        exporter = Mock()
         meter_provider = metrics.MeterProvider()
         meter = meter_provider.get_meter(__name__)
         # pylint: disable=protected-access
@@ -53,8 +53,8 @@ def test_start_pipeline(self):
             meter_provider.shutdown()
 
     def test_shutdown(self):
-        controller = mock.Mock()
-        exporter = mock.Mock()
+        controller = Mock()
+        exporter = Mock()
         meter_provider = metrics.MeterProvider()
         # pylint: disable=protected-access
         meter_provider._controllers = [controller]
@@ -72,7 +72,7 @@ def test_extends_api(self):
 
     def test_collect_metrics(self):
         meter = metrics.MeterProvider().get_meter(__name__)
-        processor_mock = mock.Mock()
+        processor_mock = Mock()
         meter.processor = processor_mock
         counter = meter.create_counter("name", "desc", "unit", float,)
         labels = {"key1": "value1"}
@@ -83,14 +83,14 @@ def test_collect_metrics(self):
 
     def test_collect_no_metrics(self):
         meter = metrics.MeterProvider().get_meter(__name__)
-        processor_mock = mock.Mock()
+        processor_mock = Mock()
         meter.processor = processor_mock
         meter.collect()
         self.assertFalse(processor_mock.process.called)
 
     def test_collect_not_registered(self):
         meter = metrics.MeterProvider().get_meter(__name__)
-        processor_mock = mock.Mock()
+        processor_mock = Mock()
         meter.processor = processor_mock
         counter = metrics.Counter("name", "desc", "unit", float, meter)
         labels = {"key1": "value1"}
@@ -100,7 +100,7 @@ def test_collect_not_registered(self):
 
     def test_collect_disabled_metric(self):
         meter = metrics.MeterProvider().get_meter(__name__)
-        processor_mock = mock.Mock()
+        processor_mock = Mock()
         meter.processor = processor_mock
         counter = metrics.Counter("name", "desc", "unit", float, meter, False)
         labels = {"key1": "value1"}
@@ -111,7 +111,7 @@ def test_collect_disabled_metric(self):
 
     def test_collect_observers(self):
         meter = metrics.MeterProvider().get_meter(__name__)
-        processor_mock = mock.Mock()
+        processor_mock = Mock()
         meter.processor = processor_mock
 
         def callback(observer):
@@ -154,7 +154,7 @@ def test_record_batch(self):
         )
 
     def test_create_counter(self):
-        resource = mock.Mock(spec=resources.Resource)
+        resource = Mock(spec=resources.Resource)
         meter_provider = metrics.MeterProvider(resource=resource)
         meter = meter_provider.get_meter(__name__)
         counter = meter.create_counter("name", "desc", "unit", int,)
@@ -186,7 +186,7 @@ def test_create_valuerecorder(self):
     def test_register_sumobserver(self):
         meter = metrics.MeterProvider().get_meter(__name__)
 
-        callback = mock.Mock()
+        callback = Mock()
 
         observer = meter.register_sumobserver(
             callback, "name", "desc", "unit", int,
@@ -206,7 +206,7 @@ def test_register_sumobserver(self):
     def test_register_updownsumobserver(self):
         meter = metrics.MeterProvider().get_meter(__name__)
 
-        callback = mock.Mock()
+        callback = Mock()
 
         observer = meter.register_updownsumobserver(
             callback, "name", "desc", "unit", int,
@@ -226,7 +226,7 @@ def test_register_updownsumobserver(self):
     def test_register_valueobserver(self):
         meter = metrics.MeterProvider().get_meter(__name__)
 
-        callback = mock.Mock()
+        callback = Mock()
 
         observer = meter.register_valueobserver(
             callback, "name", "desc", "unit", int,
@@ -246,7 +246,7 @@ def test_register_valueobserver(self):
     def test_unregister_observer(self):
         meter = metrics.MeterProvider().get_meter(__name__)
 
-        callback = mock.Mock()
+        callback = Mock()
 
         observer = meter.register_valueobserver(
             callback, "name", "desc", "unit", int, metrics.ValueObserver
@@ -286,7 +286,7 @@ def test_add(self):
         metric.add(2, labels)
         self.assertEqual(bound_mock.view_datas.pop().aggregator.current, 5)
 
-    @mock.patch("opentelemetry.sdk.metrics.logger")
+    @patch("opentelemetry.sdk.metrics.logger")
     def test_add_non_decreasing_int_error(self, logger_mock):
         meter = metrics.MeterProvider().get_meter(__name__)
         metric = metrics.Counter("name", "desc", "unit", int, meter)
@@ -300,7 +300,7 @@ def test_add_non_decreasing_int_error(self, logger_mock):
         self.assertEqual(bound_counter.view_datas.pop().aggregator.current, 3)
         self.assertEqual(logger_mock.warning.call_count, 1)
 
-    @mock.patch("opentelemetry.sdk.metrics.logger")
+    @patch("opentelemetry.sdk.metrics.logger")
     def test_add_non_decreasing_float_error(self, logger_mock):
         meter = metrics.MeterProvider().get_meter(__name__)
         metric = metrics.Counter("name", "desc", "unit", float, meter)
@@ -351,7 +351,7 @@ def test_record(self):
 class TestSumObserver(unittest.TestCase):
     def test_observe(self):
         observer = metrics.SumObserver(
-            None, "name", "desc", "unit", int, ("key",), True
+            None, "name", "desc", "unit", int, Mock(), ("key",), True
         )
         labels = {"key": "value"}
         key_labels = metrics.get_dict_as_key(labels)
@@ -363,26 +363,26 @@ def test_observe(self):
 
     def test_observe_disabled(self):
         observer = metrics.SumObserver(
-            None, "name", "desc", "unit", int, ("key",), False
+            None, "name", "desc", "unit", int, Mock(), ("key",), False
         )
         labels = {"key": "value"}
         observer.observe(37, labels)
         self.assertEqual(len(observer.aggregators), 0)
 
-    @mock.patch("opentelemetry.sdk.metrics.logger")
+    @patch("opentelemetry.sdk.metrics.logger")
     def test_observe_incorrect_type(self, logger_mock):
         observer = metrics.SumObserver(
-            None, "name", "desc", "unit", int, ("key",), True
+            None, "name", "desc", "unit", int, Mock(), ("key",), True
         )
         labels = {"key": "value"}
         observer.observe(37.0, labels)
         self.assertEqual(len(observer.aggregators), 0)
         self.assertTrue(logger_mock.warning.called)
 
-    @mock.patch("opentelemetry.sdk.metrics.logger")
+    @patch("opentelemetry.sdk.metrics.logger")
     def test_observe_non_decreasing_error(self, logger_mock):
         observer = metrics.SumObserver(
-            None, "name", "desc", "unit", int, ("key",), True
+            None, "name", "desc", "unit", int, Mock(), ("key",), True
         )
         labels = {"key": "value"}
         observer.observe(37, labels)
@@ -391,21 +391,21 @@ def test_observe_non_decreasing_error(self, logger_mock):
         self.assertTrue(logger_mock.warning.called)
 
     def test_run(self):
-        callback = mock.Mock()
+        callback = Mock()
         observer = metrics.SumObserver(
-            callback, "name", "desc", "unit", int, (), True
+            callback, "name", "desc", "unit", int, Mock(), (), True
         )
 
         self.assertTrue(observer.run())
         callback.assert_called_once_with(observer)
 
-    @mock.patch("opentelemetry.sdk.metrics.logger")
+    @patch("opentelemetry.sdk.metrics.logger")
     def test_run_exception(self, logger_mock):
-        callback = mock.Mock()
+        callback = Mock()
         callback.side_effect = Exception("We have a problem!")
 
         observer = metrics.SumObserver(
-            callback, "name", "desc", "unit", int, (), True
+            callback, "name", "desc", "unit", int, Mock(), (), True
         )
 
         self.assertFalse(observer.run())
@@ -415,7 +415,7 @@ def test_run_exception(self, logger_mock):
 class TestUpDownSumObserver(unittest.TestCase):
     def test_observe(self):
         observer = metrics.UpDownSumObserver(
-            None, "name", "desc", "unit", int, ("key",), True
+            None, "name", "desc", "unit", int, Mock(), ("key",), True
         )
         labels = {"key": "value"}
         key_labels = metrics.get_dict_as_key(labels)
@@ -427,16 +427,16 @@ def test_observe(self):
 
     def test_observe_disabled(self):
         observer = metrics.UpDownSumObserver(
-            None, "name", "desc", "unit", int, ("key",), False
+            None, "name", "desc", "unit", int, Mock(), ("key",), False
         )
         labels = {"key": "value"}
         observer.observe(37, labels)
         self.assertEqual(len(observer.aggregators), 0)
 
-    @mock.patch("opentelemetry.sdk.metrics.logger")
+    @patch("opentelemetry.sdk.metrics.logger")
     def test_observe_incorrect_type(self, logger_mock):
         observer = metrics.UpDownSumObserver(
-            None, "name", "desc", "unit", int, ("key",), True
+            None, "name", "desc", "unit", int, Mock(), ("key",), True
         )
         labels = {"key": "value"}
         observer.observe(37.0, labels)
@@ -444,21 +444,21 @@ def test_observe_incorrect_type(self, logger_mock):
         self.assertTrue(logger_mock.warning.called)
 
     def test_run(self):
-        callback = mock.Mock()
+        callback = Mock()
         observer = metrics.UpDownSumObserver(
-            callback, "name", "desc", "unit", int, (), True
+            callback, "name", "desc", "unit", int, Mock(), (), True
         )
 
         self.assertTrue(observer.run())
         callback.assert_called_once_with(observer)
 
-    @mock.patch("opentelemetry.sdk.metrics.logger")
+    @patch("opentelemetry.sdk.metrics.logger")
     def test_run_exception(self, logger_mock):
-        callback = mock.Mock()
+        callback = Mock()
         callback.side_effect = Exception("We have a problem!")
 
         observer = metrics.UpDownSumObserver(
-            callback, "name", "desc", "unit", int, (), True
+            callback, "name", "desc", "unit", int, Mock(), (), True
         )
 
         self.assertFalse(observer.run())
@@ -468,7 +468,7 @@ def test_run_exception(self, logger_mock):
 class TestValueObserver(unittest.TestCase):
     def test_observe(self):
         observer = metrics.ValueObserver(
-            None, "name", "desc", "unit", int, ("key",), True
+            None, "name", "desc", "unit", int, Mock(), ("key",), True
         )
         labels = {"key": "value"}
         key_labels = metrics.get_dict_as_key(labels)
@@ -484,16 +484,16 @@ def test_observe(self):
 
     def test_observe_disabled(self):
         observer = metrics.ValueObserver(
-            None, "name", "desc", "unit", int, ("key",), False
+            None, "name", "desc", "unit", int, Mock(), ("key",), False
         )
         labels = {"key": "value"}
         observer.observe(37, labels)
         self.assertEqual(len(observer.aggregators), 0)
 
-    @mock.patch("opentelemetry.sdk.metrics.logger")
+    @patch("opentelemetry.sdk.metrics.logger")
     def test_observe_incorrect_type(self, logger_mock):
         observer = metrics.ValueObserver(
-            None, "name", "desc", "unit", int, ("key",), True
+            None, "name", "desc", "unit", int, Mock(), ("key",), True
         )
         labels = {"key": "value"}
         observer.observe(37.0, labels)
@@ -501,21 +501,21 @@ def test_observe_incorrect_type(self, logger_mock):
         self.assertTrue(logger_mock.warning.called)
 
     def test_run(self):
-        callback = mock.Mock()
+        callback = Mock()
         observer = metrics.ValueObserver(
-            callback, "name", "desc", "unit", int, (), True
+            callback, "name", "desc", "unit", int, Mock(), (), True
         )
 
         self.assertTrue(observer.run())
         callback.assert_called_once_with(observer)
 
-    @mock.patch("opentelemetry.sdk.metrics.logger")
+    @patch("opentelemetry.sdk.metrics.logger")
     def test_run_exception(self, logger_mock):
-        callback = mock.Mock()
+        callback = Mock()
         callback.side_effect = Exception("We have a problem!")
 
         observer = metrics.ValueObserver(
-            callback, "name", "desc", "unit", int, (), True
+            callback, "name", "desc", "unit", int, Mock(), (), True
         )
 
         self.assertFalse(observer.run())
@@ -525,40 +525,40 @@ def test_run_exception(self, logger_mock):
 # pylint: disable=no-self-use
 class TestBoundCounter(unittest.TestCase):
     def test_add(self):
-        meter_mock = mock.Mock()
-        metric_mock = mock.Mock()
+        meter_mock = Mock()
+        metric_mock = Mock()
         metric_mock.enabled = True
         metric_mock.value_type = int
         metric_mock.meter = meter_mock
         bound_metric = metrics.BoundCounter((), metric_mock)
-        view_datas_mock = mock.Mock()
+        view_datas_mock = Mock()
         bound_metric.view_datas = [view_datas_mock]
         bound_metric.add(3)
         view_datas_mock.record.assert_called_once_with(3)
 
     def test_add_disabled(self):
-        meter_mock = mock.Mock()
-        metric_mock = mock.Mock()
+        meter_mock = Mock()
+        metric_mock = Mock()
         metric_mock.enabled = False
         metric_mock.value_type = int
         metric_mock.meter = meter_mock
         bound_metric = metrics.BoundCounter((), metric_mock)
-        view_datas_mock = mock.Mock()
+        view_datas_mock = Mock()
         bound_metric.view_datas = [view_datas_mock]
         bound_metric.add(3)
         view_datas_mock.record.update_view.assert_not_called()
 
-    @mock.patch("opentelemetry.sdk.metrics.logger")
+    @patch("opentelemetry.sdk.metrics.logger")
     def test_add_incorrect_type(self, logger_mock):
-        meter_mock = mock.Mock()
-        viewm_mock = mock.Mock()
+        meter_mock = Mock()
+        viewm_mock = Mock()
         meter_mock.view_manager = viewm_mock
-        metric_mock = mock.Mock()
+        metric_mock = Mock()
         metric_mock.enabled = True
         metric_mock.value_type = float
         metric_mock.meter = meter_mock
         bound_metric = metrics.BoundCounter((), metric_mock)
-        view_datas_mock = mock.Mock()
+        view_datas_mock = Mock()
         bound_metric.view_datas = [view_datas_mock]
         bound_metric.add(3)
         view_datas_mock.record.update_view.assert_not_called()
@@ -567,38 +567,38 @@ def test_add_incorrect_type(self, logger_mock):
 
 class TestBoundValueRecorder(unittest.TestCase):
     def test_record(self):
-        meter_mock = mock.Mock()
-        metric_mock = mock.Mock()
+        meter_mock = Mock()
+        metric_mock = Mock()
         metric_mock.enabled = True
         metric_mock.value_type = int
         metric_mock.meter = meter_mock
         bound_valuerecorder = metrics.BoundValueRecorder((), metric_mock)
-        view_datas_mock = mock.Mock()
+        view_datas_mock = Mock()
         bound_valuerecorder.view_datas = [view_datas_mock]
         bound_valuerecorder.record(3)
         view_datas_mock.record.assert_called_once_with(3)
 
     def test_record_disabled(self):
-        meter_mock = mock.Mock()
-        metric_mock = mock.Mock()
+        meter_mock = Mock()
+        metric_mock = Mock()
         metric_mock.enabled = False
         metric_mock.value_type = int
         metric_mock.meter = meter_mock
         bound_valuerecorder = metrics.BoundValueRecorder((), metric_mock)
-        view_datas_mock = mock.Mock()
+        view_datas_mock = Mock()
         bound_valuerecorder.view_datas = [view_datas_mock]
         bound_valuerecorder.record(3)
         view_datas_mock.record.update_view.assert_not_called()
 
-    @mock.patch("opentelemetry.sdk.metrics.logger")
+    @patch("opentelemetry.sdk.metrics.logger")
     def test_record_incorrect_type(self, logger_mock):
-        meter_mock = mock.Mock()
-        metric_mock = mock.Mock()
+        meter_mock = Mock()
+        metric_mock = Mock()
         metric_mock.enabled = True
         metric_mock.value_type = float
         metric_mock.meter = meter_mock
         bound_valuerecorder = metrics.BoundValueRecorder((), metric_mock)
-        view_datas_mock = mock.Mock()
+        view_datas_mock = Mock()
         bound_valuerecorder.view_datas = [view_datas_mock]
         bound_valuerecorder.record(3)
         view_datas_mock.record.update_view.assert_not_called()
diff --git a/opentelemetry-sdk/tests/metrics/test_view.py b/opentelemetry-sdk/tests/metrics/test_view.py
--- a/opentelemetry-sdk/tests/metrics/test_view.py
+++ b/opentelemetry-sdk/tests/metrics/test_view.py
@@ -43,12 +43,14 @@ def test_default_aggregator(self, logger_mock):
         self.assertEqual(
             view.get_default_aggregator(ud_counter), aggregate.SumAggregator
         )
-        observer = metrics.SumObserver(lambda: None, "", "", "1", int)
+        observer = metrics.SumObserver(lambda: None, "", "", "1", int, meter)
         self.assertEqual(
             view.get_default_aggregator(observer),
             aggregate.LastValueAggregator,
         )
-        ud_observer = metrics.SumObserver(lambda: None, "", "", "1", int)
+        ud_observer = metrics.SumObserver(
+            lambda: None, "", "", "1", int, meter
+        )
         self.assertEqual(
             view.get_default_aggregator(ud_observer),
             aggregate.LastValueAggregator,
@@ -58,7 +60,9 @@ def test_default_aggregator(self, logger_mock):
             view.get_default_aggregator(recorder),
             aggregate.MinMaxSumCountAggregator,
         )
-        v_observer = metrics.ValueObserver(lambda: None, "", "", "1", int)
+        v_observer = metrics.ValueObserver(
+            lambda: None, "", "", "1", int, meter
+        )
         self.assertEqual(
             view.get_default_aggregator(v_observer),
             aggregate.ValueObserverAggregator,