From a5537318dbf7b7fbb45383a0ffde1969490793c0 Mon Sep 17 00:00:00 2001 From: Alex Boten Date: Mon, 5 Oct 2020 16:17:25 -0700 Subject: [PATCH 1/7] Adding Resource to MetricRecord --- .../opencensus/metrics_exporter/__init__.py | 2 +- .../exporter/otlp/metrics_exporter/__init__.py | 6 +++--- .../tests/test_otlp_metric_exporter.py | 7 +++---- .../src/opentelemetry/sdk/metrics/__init__.py | 2 +- .../sdk/metrics/export/__init__.py | 3 +++ .../opentelemetry/sdk/metrics/export/batcher.py | 8 ++++++-- .../tests/metrics/export/test_export.py | 17 +++++++++-------- 7 files changed, 26 insertions(+), 19 deletions(-) diff --git a/exporter/opentelemetry-exporter-opencensus/src/opentelemetry/exporter/opencensus/metrics_exporter/__init__.py b/exporter/opentelemetry-exporter-opencensus/src/opentelemetry/exporter/opencensus/metrics_exporter/__init__.py index 204a7c5476d..5113958c548 100644 --- a/exporter/opentelemetry-exporter-opencensus/src/opentelemetry/exporter/opencensus/metrics_exporter/__init__.py +++ b/exporter/opentelemetry-exporter-opencensus/src/opentelemetry/exporter/opencensus/metrics_exporter/__init__.py @@ -191,7 +191,7 @@ def get_collector_point(metric_record: MetricRecord) -> metrics_pb2.Point: def get_resource(metric_record: MetricRecord) -> resource_pb2.Resource: - resource_attributes = metric_record.instrument.meter.resource.attributes + resource_attributes = metric_record.resource.attributes return resource_pb2.Resource( type=infer_oc_resource_type(resource_attributes), labels={k: str(v) for k, v in resource_attributes.items()}, diff --git a/exporter/opentelemetry-exporter-otlp/src/opentelemetry/exporter/otlp/metrics_exporter/__init__.py b/exporter/opentelemetry-exporter-otlp/src/opentelemetry/exporter/otlp/metrics_exporter/__init__.py index 08a47c601e2..1fa1bf24f11 100644 --- a/exporter/opentelemetry-exporter-otlp/src/opentelemetry/exporter/otlp/metrics_exporter/__init__.py +++ b/exporter/opentelemetry-exporter-otlp/src/opentelemetry/exporter/otlp/metrics_exporter/__init__.py @@ -137,11 +137,11 @@ def _translate_data( # ValueObserver Gauge() for sdk_metric in data: - if sdk_metric.instrument.meter.resource not in ( + if sdk_metric.resource not in ( sdk_resource_instrumentation_library_metrics.keys() ): sdk_resource_instrumentation_library_metrics[ - sdk_metric.instrument.meter.resource + sdk_metric.resource ] = InstrumentationLibraryMetrics() type_class = { @@ -217,7 +217,7 @@ def _translate_data( argument = type_class[value_type]["gauge"]["argument"] sdk_resource_instrumentation_library_metrics[ - sdk_metric.instrument.meter.resource + sdk_metric.resource ].metrics.append( OTLPMetric( **{ diff --git a/exporter/opentelemetry-exporter-otlp/tests/test_otlp_metric_exporter.py b/exporter/opentelemetry-exporter-otlp/tests/test_otlp_metric_exporter.py index 1218fbbb330..1eba2bef66d 100644 --- a/exporter/opentelemetry-exporter-otlp/tests/test_otlp_metric_exporter.py +++ b/exporter/opentelemetry-exporter-otlp/tests/test_otlp_metric_exporter.py @@ -44,20 +44,19 @@ class TestOTLPMetricExporter(TestCase): def setUp(self): self.exporter = OTLPMetricsExporter() - + resource = SDKResource(OrderedDict([("a", 1), ("b", False)])) self.counter_metric_record = MetricRecord( Counter( "a", "b", "c", int, - MeterProvider( - resource=SDKResource(OrderedDict([("a", 1), ("b", False)])) - ).get_meter(__name__), + MeterProvider(resource=resource,).get_meter(__name__), ("d",), ), OrderedDict([("e", "f")]), SumAggregator(), + resource, ) def test_translate_metrics(self): diff --git a/opentelemetry-sdk/src/opentelemetry/sdk/metrics/__init__.py b/opentelemetry-sdk/src/opentelemetry/sdk/metrics/__init__.py index 092f456fafe..230384ca607 100644 --- a/opentelemetry-sdk/src/opentelemetry/sdk/metrics/__init__.py +++ b/opentelemetry-sdk/src/opentelemetry/sdk/metrics/__init__.py @@ -352,7 +352,7 @@ def __init__( instrumentation_info: "InstrumentationInfo", ): self.instrumentation_info = instrumentation_info - self.batcher = Batcher(source.stateful) + self.batcher = Batcher(source.stateful, source.resource) self.resource = source.resource self.metrics = set() self.observers = set() diff --git a/opentelemetry-sdk/src/opentelemetry/sdk/metrics/export/__init__.py b/opentelemetry-sdk/src/opentelemetry/sdk/metrics/export/__init__.py index 16911f94efb..ad57880df4d 100644 --- a/opentelemetry-sdk/src/opentelemetry/sdk/metrics/export/__init__.py +++ b/opentelemetry-sdk/src/opentelemetry/sdk/metrics/export/__init__.py @@ -17,6 +17,7 @@ from opentelemetry import metrics as metrics_api from opentelemetry.sdk.metrics.export.aggregate import Aggregator +from opentelemetry.sdk.resources import Resource class MetricsExportResult(Enum): @@ -30,10 +31,12 @@ def __init__( instrument: metrics_api.InstrumentT, labels: Tuple[Tuple[str, str]], aggregator: Aggregator, + resource: Resource, ): self.instrument = instrument self.labels = labels self.aggregator = aggregator + self.resource = resource class MetricsExporter: diff --git a/opentelemetry-sdk/src/opentelemetry/sdk/metrics/export/batcher.py b/opentelemetry-sdk/src/opentelemetry/sdk/metrics/export/batcher.py index 1c1858ebbae..5e7c55adc71 100644 --- a/opentelemetry-sdk/src/opentelemetry/sdk/metrics/export/batcher.py +++ b/opentelemetry-sdk/src/opentelemetry/sdk/metrics/export/batcher.py @@ -15,6 +15,7 @@ from typing import Sequence from opentelemetry.sdk.metrics.export import MetricRecord +from opentelemetry.sdk.resources import Resource from opentelemetry.sdk.util import get_dict_as_key @@ -26,13 +27,14 @@ class Batcher: will be sent to an exporter for exporting. """ - def __init__(self, stateful: bool): + def __init__(self, stateful: bool, resource: Resource): self._batch_map = {} # stateful=True indicates the batcher computes checkpoints from over # the process lifetime. False indicates the batcher computes # checkpoints which describe the updates of a single collection period # (deltas) self.stateful = stateful + self._resource = resource def checkpoint_set(self) -> Sequence[MetricRecord]: """Returns a list of MetricRecords used for exporting. @@ -46,7 +48,9 @@ def checkpoint_set(self) -> Sequence[MetricRecord]: (instrument, aggregator_type, _, labels), aggregator, ) in self._batch_map.items(): - metric_records.append(MetricRecord(instrument, labels, aggregator)) + metric_records.append( + MetricRecord(instrument, labels, aggregator, self._resource) + ) return metric_records def finished_collection(self): diff --git a/opentelemetry-sdk/tests/metrics/export/test_export.py b/opentelemetry-sdk/tests/metrics/export/test_export.py index 99aa9c4a629..4e073cbbfce 100644 --- a/opentelemetry-sdk/tests/metrics/export/test_export.py +++ b/opentelemetry-sdk/tests/metrics/export/test_export.py @@ -31,6 +31,7 @@ ) from opentelemetry.sdk.metrics.export.batcher import Batcher from opentelemetry.sdk.metrics.export.controller import PushController +from opentelemetry.sdk.resources import Resource # pylint: disable=protected-access @@ -49,7 +50,7 @@ def test_export(self): ) labels = {"environment": "staging"} aggregator = SumAggregator() - record = MetricRecord(metric, labels, aggregator) + record = MetricRecord(metric, labels, aggregator, meter.resource) result = '{}(data="{}", labels="{}", value={})'.format( ConsoleMetricsExporter.__name__, metric, @@ -64,7 +65,7 @@ def test_export(self): class TestBatcher(unittest.TestCase): def test_checkpoint_set(self): meter = metrics.MeterProvider().get_meter(__name__) - batcher = Batcher(True) + batcher = Batcher(True, meter.resource) aggregator = SumAggregator() metric = metrics.Counter( "available memory", "available memory", "bytes", int, meter @@ -81,13 +82,13 @@ def test_checkpoint_set(self): self.assertEqual(records[0].aggregator, aggregator) def test_checkpoint_set_empty(self): - batcher = Batcher(True) + batcher = Batcher(True, Resource.create_empty()) records = batcher.checkpoint_set() self.assertEqual(len(records), 0) def test_finished_collection_stateless(self): meter = metrics.MeterProvider().get_meter(__name__) - batcher = Batcher(False) + batcher = Batcher(True, meter.resource) aggregator = SumAggregator() metric = metrics.Counter( "available memory", "available memory", "bytes", int, meter @@ -102,7 +103,7 @@ def test_finished_collection_stateless(self): def test_finished_collection_stateful(self): meter = metrics.MeterProvider().get_meter(__name__) - batcher = Batcher(True) + batcher = Batcher(True, meter.resource) aggregator = SumAggregator() metric = metrics.Counter( "available memory", "available memory", "bytes", int, meter @@ -117,7 +118,7 @@ def test_finished_collection_stateful(self): def test_batcher_process_exists(self): meter = metrics.MeterProvider().get_meter(__name__) - batcher = Batcher(True) + batcher = Batcher(True, meter.resource) aggregator = SumAggregator() aggregator2 = SumAggregator() metric = metrics.Counter( @@ -138,7 +139,7 @@ def test_batcher_process_exists(self): def test_batcher_process_not_exists(self): meter = metrics.MeterProvider().get_meter(__name__) - batcher = Batcher(True) + batcher = Batcher(True, meter.resource) aggregator = SumAggregator() metric = metrics.Counter( "available memory", "available memory", "bytes", int, meter @@ -157,7 +158,7 @@ def test_batcher_process_not_exists(self): def test_batcher_process_not_stateful(self): meter = metrics.MeterProvider().get_meter(__name__) - batcher = Batcher(True) + batcher = Batcher(True, meter.resource) aggregator = SumAggregator() metric = metrics.Counter( "available memory", "available memory", "bytes", int, meter From 859b7fc5234abc40039930f42b89b6667c9e7ac0 Mon Sep 17 00:00:00 2001 From: Alex Boten Date: Mon, 5 Oct 2020 21:50:36 -0700 Subject: [PATCH 2/7] fix test --- opentelemetry-sdk/tests/metrics/export/test_export.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/opentelemetry-sdk/tests/metrics/export/test_export.py b/opentelemetry-sdk/tests/metrics/export/test_export.py index 4e073cbbfce..014bd0fb5a6 100644 --- a/opentelemetry-sdk/tests/metrics/export/test_export.py +++ b/opentelemetry-sdk/tests/metrics/export/test_export.py @@ -88,7 +88,7 @@ def test_checkpoint_set_empty(self): def test_finished_collection_stateless(self): meter = metrics.MeterProvider().get_meter(__name__) - batcher = Batcher(True, meter.resource) + batcher = Batcher(False, meter.resource) aggregator = SumAggregator() metric = metrics.Counter( "available memory", "available memory", "bytes", int, meter From b291bd261805627f4e8fa819b9afd6170190c108 Mon Sep 17 00:00:00 2001 From: Alex Boten Date: Mon, 5 Oct 2020 21:56:45 -0700 Subject: [PATCH 3/7] fix tests --- .../test_otcollector_metrics_exporter.py | 33 ++++++++++++++++--- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/exporter/opentelemetry-exporter-opencensus/tests/test_otcollector_metrics_exporter.py b/exporter/opentelemetry-exporter-opencensus/tests/test_otcollector_metrics_exporter.py index 1ec1a574487..4dd34bf1ba1 100644 --- a/exporter/opentelemetry-exporter-opencensus/tests/test_otcollector_metrics_exporter.py +++ b/exporter/opentelemetry-exporter-opencensus/tests/test_otcollector_metrics_exporter.py @@ -100,7 +100,12 @@ def test_get_collector_point(self): "testName", "testDescription", "unit", float, ValueRecorder ) result = metrics_exporter.get_collector_point( - MetricRecord(int_counter, self._key_labels, aggregator) + MetricRecord( + int_counter, + self._key_labels, + aggregator, + metrics.get_meter_provider().resource, + ) ) self.assertIsInstance(result, metrics_pb2.Point) self.assertIsInstance(result.timestamp, Timestamp) @@ -108,13 +113,23 @@ def test_get_collector_point(self): aggregator.update(123.5) aggregator.take_checkpoint() result = metrics_exporter.get_collector_point( - MetricRecord(float_counter, self._key_labels, aggregator) + MetricRecord( + float_counter, + self._key_labels, + aggregator, + metrics.get_meter_provider().resource, + ) ) self.assertEqual(result.double_value, 123.5) self.assertRaises( TypeError, metrics_exporter.get_collector_point( - MetricRecord(valuerecorder, self._key_labels, aggregator) + MetricRecord( + valuerecorder, + self._key_labels, + aggregator, + metrics.get_meter_provider().resource, + ) ), ) @@ -130,7 +145,10 @@ def test_export(self): "testname", "testdesc", "unit", int, Counter, self._labels.keys(), ) record = MetricRecord( - test_metric, self._key_labels, aggregate.SumAggregator(), + test_metric, + self._key_labels, + aggregate.SumAggregator(), + metrics.get_meter_provider().resource, ) result = collector_exporter.export([record]) @@ -155,7 +173,12 @@ def test_translate_to_collector(self): aggregator = aggregate.SumAggregator() aggregator.update(123) aggregator.take_checkpoint() - record = MetricRecord(test_metric, self._key_labels, aggregator,) + record = MetricRecord( + test_metric, + self._key_labels, + aggregator, + metrics.get_meter_provider().resource, + ) start_timestamp = Timestamp() output_metrics = metrics_exporter.translate_to_collector( [record], start_timestamp, From 91c860272712120a821e8ffcc5e6eaf67e6e90c2 Mon Sep 17 00:00:00 2001 From: Alex Boten Date: Mon, 5 Oct 2020 22:02:17 -0700 Subject: [PATCH 4/7] fix more tests --- .../tests/test_prometheus_exporter.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/exporter/opentelemetry-exporter-prometheus/tests/test_prometheus_exporter.py b/exporter/opentelemetry-exporter-prometheus/tests/test_prometheus_exporter.py index 936a6eb8221..4e2075b8b6a 100644 --- a/exporter/opentelemetry-exporter-prometheus/tests/test_prometheus_exporter.py +++ b/exporter/opentelemetry-exporter-prometheus/tests/test_prometheus_exporter.py @@ -67,7 +67,10 @@ def test_shutdown(self): def test_export(self): with self._registry_register_patch: record = MetricRecord( - self._test_metric, self._labels_key, SumAggregator(), + self._test_metric, + self._labels_key, + SumAggregator(), + get_meter_provider().resource, ) exporter = PrometheusMetricsExporter() result = exporter.export([record]) @@ -86,7 +89,9 @@ def test_min_max_sum_aggregator_to_prometheus(self): aggregator.update(123) aggregator.update(456) aggregator.take_checkpoint() - record = MetricRecord(metric, key_labels, aggregator) + record = MetricRecord( + metric, key_labels, aggregator, get_meter_provider().resource + ) collector = CustomCollector("testprefix") collector.add_metrics_data([record]) result_bytes = generate_latest(collector) @@ -104,7 +109,9 @@ def test_counter_to_prometheus(self): aggregator = SumAggregator() aggregator.update(123) aggregator.take_checkpoint() - record = MetricRecord(metric, key_labels, aggregator) + record = MetricRecord( + metric, key_labels, aggregator, get_meter_provider().resource + ) collector = CustomCollector("testprefix") collector.add_metrics_data([record]) @@ -132,7 +139,9 @@ def test_invalid_metric(self): ) labels = {"environment": "staging"} key_labels = get_dict_as_key(labels) - record = MetricRecord(metric, key_labels, None) + record = MetricRecord( + metric, key_labels, None, get_meter_provider().resource + ) collector = CustomCollector("testprefix") collector.add_metrics_data([record]) collector.collect() From 664931ae45fc7b42a4d7b6e302b990970b18ea15 Mon Sep 17 00:00:00 2001 From: Alex Boten Date: Tue, 6 Oct 2020 09:31:55 -0700 Subject: [PATCH 5/7] update changelog --- opentelemetry-sdk/CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/opentelemetry-sdk/CHANGELOG.md b/opentelemetry-sdk/CHANGELOG.md index d2834986122..28c0704f919 100644 --- a/opentelemetry-sdk/CHANGELOG.md +++ b/opentelemetry-sdk/CHANGELOG.md @@ -12,6 +12,8 @@ ([#1153](https://github.com/open-telemetry/opentelemetry-python/pull/1153)) - Renaming metrics Batcher to Processor ([#1203](https://github.com/open-telemetry/opentelemetry-python/pull/1203)) +- Adding Resource to MeterRecord + ([#1209](https://github.com/open-telemetry/opentelemetry-python/pull/1209)) ## Version 0.13b0 From e8251961748f5de057b6b8a349bbf5cbdd2f72c8 Mon Sep 17 00:00:00 2001 From: Alex Boten Date: Tue, 6 Oct 2020 09:39:01 -0700 Subject: [PATCH 6/7] adding output of resource to console metric exporter and test for it --- .../src/opentelemetry/sdk/metrics/export/__init__.py | 3 ++- opentelemetry-sdk/tests/metrics/export/test_export.py | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/opentelemetry-sdk/src/opentelemetry/sdk/metrics/export/__init__.py b/opentelemetry-sdk/src/opentelemetry/sdk/metrics/export/__init__.py index ad57880df4d..e7882217ec4 100644 --- a/opentelemetry-sdk/src/opentelemetry/sdk/metrics/export/__init__.py +++ b/opentelemetry-sdk/src/opentelemetry/sdk/metrics/export/__init__.py @@ -80,11 +80,12 @@ def export( ) -> "MetricsExportResult": for record in metric_records: print( - '{}(data="{}", labels="{}", value={})'.format( + '{}(data="{}", labels="{}", value={}, resource={})'.format( type(self).__name__, record.instrument, record.labels, record.aggregator.checkpoint, + record.resource.attributes, ) ) return MetricsExportResult.SUCCESS diff --git a/opentelemetry-sdk/tests/metrics/export/test_export.py b/opentelemetry-sdk/tests/metrics/export/test_export.py index 94e59e60a37..7c596ce9168 100644 --- a/opentelemetry-sdk/tests/metrics/export/test_export.py +++ b/opentelemetry-sdk/tests/metrics/export/test_export.py @@ -51,11 +51,12 @@ def test_export(self): labels = {"environment": "staging"} aggregator = SumAggregator() record = MetricRecord(metric, labels, aggregator, meter.resource) - result = '{}(data="{}", labels="{}", value={})'.format( + result = '{}(data="{}", labels="{}", value={}, resource={})'.format( ConsoleMetricsExporter.__name__, metric, labels, aggregator.checkpoint, + meter.resource.attributes, ) with mock.patch("sys.stdout") as mock_stdout: exporter.export([record]) From cde964271f2995a995d09c768d629cb8a7608aef Mon Sep 17 00:00:00 2001 From: Diego Hurtado Date: Tue, 6 Oct 2020 12:23:52 -0600 Subject: [PATCH 7/7] Remove resource attribute from Meter --- .../src/opentelemetry/sdk/metrics/__init__.py | 1 - .../tests/metrics/export/test_export.py | 44 ++++++++++++------- .../tests/metrics/test_metrics.py | 8 ++-- 3 files changed, 31 insertions(+), 22 deletions(-) diff --git a/opentelemetry-sdk/src/opentelemetry/sdk/metrics/__init__.py b/opentelemetry-sdk/src/opentelemetry/sdk/metrics/__init__.py index 516ff33ad6c..382dbeb9b9d 100644 --- a/opentelemetry-sdk/src/opentelemetry/sdk/metrics/__init__.py +++ b/opentelemetry-sdk/src/opentelemetry/sdk/metrics/__init__.py @@ -353,7 +353,6 @@ def __init__( ): self.instrumentation_info = instrumentation_info self.processor = Processor(source.stateful, source.resource) - self.resource = source.resource self.metrics = set() self.observers = set() self.metrics_lock = threading.Lock() diff --git a/opentelemetry-sdk/tests/metrics/export/test_export.py b/opentelemetry-sdk/tests/metrics/export/test_export.py index 7c596ce9168..b0c74e7093d 100644 --- a/opentelemetry-sdk/tests/metrics/export/test_export.py +++ b/opentelemetry-sdk/tests/metrics/export/test_export.py @@ -38,7 +38,8 @@ class TestConsoleMetricsExporter(unittest.TestCase): # pylint: disable=no-self-use def test_export(self): - meter = metrics.MeterProvider().get_meter(__name__) + meter_provider = metrics.MeterProvider() + meter = meter_provider.get_meter(__name__) exporter = ConsoleMetricsExporter() metric = metrics.Counter( "available memory", @@ -50,13 +51,15 @@ def test_export(self): ) labels = {"environment": "staging"} aggregator = SumAggregator() - record = MetricRecord(metric, labels, aggregator, meter.resource) + record = MetricRecord( + metric, labels, aggregator, meter_provider.resource + ) result = '{}(data="{}", labels="{}", value={}, resource={})'.format( ConsoleMetricsExporter.__name__, metric, labels, aggregator.checkpoint, - meter.resource.attributes, + meter_provider.resource.attributes, ) with mock.patch("sys.stdout") as mock_stdout: exporter.export([record]) @@ -65,8 +68,9 @@ def test_export(self): class TestProcessor(unittest.TestCase): def test_checkpoint_set(self): - meter = metrics.MeterProvider().get_meter(__name__) - processor = Processor(True, meter.resource) + meter_provider = metrics.MeterProvider() + meter = meter_provider.get_meter(__name__) + processor = Processor(True, meter_provider.resource) aggregator = SumAggregator() metric = metrics.Counter( "available memory", "available memory", "bytes", int, meter @@ -88,8 +92,9 @@ def test_checkpoint_set_empty(self): self.assertEqual(len(records), 0) def test_finished_collection_stateless(self): - meter = metrics.MeterProvider().get_meter(__name__) - processor = Processor(False, meter.resource) + meter_provider = metrics.MeterProvider() + meter = meter_provider.get_meter(__name__) + processor = Processor(False, meter_provider.resource) aggregator = SumAggregator() metric = metrics.Counter( "available memory", "available memory", "bytes", int, meter @@ -103,8 +108,9 @@ def test_finished_collection_stateless(self): self.assertEqual(len(processor._batch_map), 0) def test_finished_collection_stateful(self): - meter = metrics.MeterProvider().get_meter(__name__) - processor = Processor(True, meter.resource) + meter_provider = metrics.MeterProvider() + meter = meter_provider.get_meter(__name__) + processor = Processor(True, meter_provider.resource) aggregator = SumAggregator() metric = metrics.Counter( "available memory", "available memory", "bytes", int, meter @@ -118,8 +124,9 @@ def test_finished_collection_stateful(self): self.assertEqual(len(processor._batch_map), 1) def test_processor_process_exists(self): - meter = metrics.MeterProvider().get_meter(__name__) - processor = Processor(True, meter.resource) + meter_provider = metrics.MeterProvider() + meter = meter_provider.get_meter(__name__) + processor = Processor(True, meter_provider.resource) aggregator = SumAggregator() aggregator2 = SumAggregator() metric = metrics.Counter( @@ -139,8 +146,9 @@ def test_processor_process_exists(self): self.assertEqual(processor._batch_map.get(batch_key).checkpoint, 1.0) def test_processor_process_not_exists(self): - meter = metrics.MeterProvider().get_meter(__name__) - processor = Processor(True, meter.resource) + meter_provider = metrics.MeterProvider() + meter = meter_provider.get_meter(__name__) + processor = Processor(True, meter_provider.resource) aggregator = SumAggregator() metric = metrics.Counter( "available memory", "available memory", "bytes", int, meter @@ -158,11 +166,15 @@ def test_processor_process_not_exists(self): self.assertEqual(processor._batch_map.get(batch_key).checkpoint, 1.0) def test_processor_process_not_stateful(self): - meter = metrics.MeterProvider().get_meter(__name__) - processor = Processor(True, meter.resource) + meter_provider = metrics.MeterProvider() + processor = Processor(True, meter_provider.resource) aggregator = SumAggregator() metric = metrics.Counter( - "available memory", "available memory", "bytes", int, meter + "available memory", + "available memory", + "bytes", + int, + meter_provider.get_meter(__name__), ) labels = () _batch_map = {} diff --git a/opentelemetry-sdk/tests/metrics/test_metrics.py b/opentelemetry-sdk/tests/metrics/test_metrics.py index 2f833f47820..1fcb2bbda1b 100644 --- a/opentelemetry-sdk/tests/metrics/test_metrics.py +++ b/opentelemetry-sdk/tests/metrics/test_metrics.py @@ -33,14 +33,12 @@ def test_stateful(self): def test_resource(self): resource = resources.Resource.create({}) meter_provider = metrics.MeterProvider(resource=resource) - meter = meter_provider.get_meter(__name__) - self.assertIs(meter.resource, resource) + self.assertIs(meter_provider.resource, resource) def test_resource_empty(self): meter_provider = metrics.MeterProvider() - meter = meter_provider.get_meter(__name__) # pylint: disable=protected-access - self.assertEqual(meter.resource, resources._DEFAULT_RESOURCE) + self.assertEqual(meter_provider.resource, resources._DEFAULT_RESOURCE) def test_start_pipeline(self): exporter = mock.Mock() @@ -167,7 +165,7 @@ def test_create_metric(self): self.assertIsInstance(counter, metrics.Counter) self.assertEqual(counter.value_type, int) self.assertEqual(counter.name, "name") - self.assertIs(counter.meter.resource, resource) + self.assertIs(meter_provider.resource, resource) self.assertEqual(counter.meter, meter) def test_create_updowncounter(self):