Repository: open-telemetry/opentelemetry-python

Issue:
View aggregation logs warning when no measurements are available
I configured a MeterProvider with a View and a `PeriodicExportingMetricReader` to report every 5 seconds, and ran the code for 10 seconds. This resulted in an unexpected warning being logged about a mismatched point type. This behaviour seems incorrect as there are no errors unless I specify an `aggregation` on the View

**Steps to reproduce**

```
from opentelemetry.sdk._metrics import MeterProvider
from opentelemetry.sdk.resources import Resource
from opentelemetry.sdk._metrics.export import (
    ConsoleMetricExporter,
    PeriodicExportingMetricReader,
)
import time
from opentelemetry.sdk._metrics.view import View
from opentelemetry._metrics.instrument import Counter
from opentelemetry.sdk._metrics.aggregation import LastValueAggregation

exporter = ConsoleMetricExporter()
reader = PeriodicExportingMetricReader(exporter, export_interval_millis=5000)
view = View(
    instrument_type=Counter,
    attribute_keys=[],
    aggregation=LastValueAggregation(),
)
provider = MeterProvider(
    metric_readers=[reader],
    resource=Resource.create(),
    views=[view],
    enable_default_view=False,
)

meter = provider.get_meter(
    name="metric-example",
    version="0.1.2",
    schema_url=" https://opentelemetry.io/schemas/1.9.0",
)
counter = meter.create_counter("counter-a", unit="1", description="")
counter.add(6, {})
counter.add(1, {})
time.sleep(10)
```

**What is the expected behavior?**
I expected to see the same last value reported for 2 different intervals.

**What is the actual behavior?**
`convert_aggregation_temporality called with mismatched point types: <class 'opentelemetry.sdk._metrics.point.Gauge'> and <class 'NoneType'>`

@ocelotl @aabmass @lzchen can you confirm whether this is expected behaviour?


Discussion:
Your config looks right to me, I think this is a bug.

Resolving patch:
diff --git a/opentelemetry-sdk/src/opentelemetry/sdk/_metrics/aggregation.py b/opentelemetry-sdk/src/opentelemetry/sdk/_metrics/aggregation.py
--- a/opentelemetry-sdk/src/opentelemetry/sdk/_metrics/aggregation.py
+++ b/opentelemetry-sdk/src/opentelemetry/sdk/_metrics/aggregation.py
@@ -303,8 +303,10 @@ def _convert_aggregation_temporality(
     if current_point_type is Gauge:
         return current_point
 
-    if previous_point is not None and type(previous_point) is not type(
-        current_point
+    if (
+        previous_point is not None
+        and current_point is not None
+        and type(previous_point) is not type(current_point)
     ):
         _logger.warning(
             "convert_aggregation_temporality called with mismatched "


Test patch:
diff --git a/opentelemetry-sdk/tests/metrics/test_aggregation.py b/opentelemetry-sdk/tests/metrics/test_aggregation.py
--- a/opentelemetry-sdk/tests/metrics/test_aggregation.py
+++ b/opentelemetry-sdk/tests/metrics/test_aggregation.py
@@ -360,6 +360,17 @@ def test_mismatched_point_types(self):
                 current_point,
             )
 
+        with self.assertRaises(AssertionError):
+            with self.assertLogs(level=WARNING):
+                self.assertIs(
+                    _convert_aggregation_temporality(
+                        Gauge(time_unix_nano=0, value=0),
+                        None,
+                        AggregationTemporality.DELTA,
+                    ),
+                    current_point,
+                )
+
     def test_current_point_sum_previous_point_none(self):
 
         current_point = Sum(