Skip to content

Commit

Permalink
Avoid generator in _ViewInstrumentMatch.collect()
Browse files Browse the repository at this point in the history
- Fix #3021
- Remove metric branch reference from CONTRIBUTING.md
  • Loading branch information
lancetarn committed Nov 22, 2022
1 parent b02ff47 commit 1e49add
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 6 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
([#3026](https://github.com/open-telemetry/opentelemetry-python/pull/3026))
- Add missing entry points for OTLP/HTTP exporter
([#3027](https://github.com/open-telemetry/opentelemetry-python/pull/3027))
- Fix: Avoid generator in metrics _ViewInstrumentMatch.collect()
([#3035](https://github.com/open-telemetry/opentelemetry-python/pull/3035)

## Version 1.14.0/0.35b0 (2022-11-04)

Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Please take a look at this list first, your contributions may belong in one of t

# Find the right branch

The default branch for this repo is `main`. Changes that pertain to `metrics` go into the `metrics` branch. Any changes that pertain to components marked as `stable` in the [specifications](https://github.com/open-telemetry/opentelemetry-specification) or anything that is not `metrics` related go into this branch.
The default branch for this repo is `main`. All feature work is accomplished on branches from `main`.

## Find a Buddy and get Started Quickly!

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from logging import getLogger
from threading import Lock
from time import time_ns
from typing import Dict, Iterable
from typing import Dict, List, Sequence

from opentelemetry.metrics import Instrument
from opentelemetry.sdk.metrics._internal.aggregation import (
Expand Down Expand Up @@ -126,12 +126,14 @@ def collect(
self,
aggregation_temporality: AggregationTemporality,
collection_start_nanos: int,
) -> Iterable[DataPointT]:
) -> Sequence[DataPointT]:

data_points: List[DataPointT] = []
with self._lock:
for aggregation in self._attributes_aggregation.values():
data_point = aggregation.collect(
aggregation_temporality, collection_start_nanos
)
if data_point is not None:
yield data_point
data_points.append(data_point)
return data_points
4 changes: 2 additions & 2 deletions opentelemetry-sdk/tests/metrics/test_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -514,11 +514,11 @@ def test_duplicate_instrument_aggregate_data(self):
self.assertEqual(metric_0.name, "counter")
self.assertEqual(metric_0.unit, "unit")
self.assertEqual(metric_0.description, "description")
self.assertEqual(next(metric_0.data.data_points).value, 3)
self.assertEqual(next(iter(metric_0.data.data_points)).value, 3)

metric_1 = scope_metrics[1].metrics[0]

self.assertEqual(metric_1.name, "counter")
self.assertEqual(metric_1.unit, "unit")
self.assertEqual(metric_1.description, "description")
self.assertEqual(next(metric_1.data.data_points).value, 7)
self.assertEqual(next(iter(metric_1.data.data_points)).value, 7)

0 comments on commit 1e49add

Please sign in to comment.