Skip to content

Commit 2be1687

Browse files
committed
Avoid generator in _ViewInstrumentMatch.collect()
- Fix #3021 - Remove metric branch reference from CONTRIBUTING.md
1 parent b02ff47 commit 2be1687

File tree

5 files changed

+11
-7
lines changed

5 files changed

+11
-7
lines changed

Diff for: .github/workflows/test.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ env:
1010
# Otherwise, set variable to the commit of your branch on
1111
# opentelemetry-python-contrib which is compatible with these Core repo
1212
# changes.
13-
CONTRIB_REPO_SHA: c6134843900e2eeb1b8b3383a897b38cc0905c38
13+
CONTRIB_REPO_SHA: main
1414
# This is needed because we do not clone the core repo in contrib builds anymore.
1515
# When running contrib builds as part of core builds, we use actions/checkout@v2 which
1616
# does not set an environment variable (simply just runs tox), which is different when

Diff for: CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1111
([#3026](https://github.com/open-telemetry/opentelemetry-python/pull/3026))
1212
- Add missing entry points for OTLP/HTTP exporter
1313
([#3027](https://github.com/open-telemetry/opentelemetry-python/pull/3027))
14+
- Fix: Avoid generator in metrics _ViewInstrumentMatch.collect()
15+
([#3035](https://github.com/open-telemetry/opentelemetry-python/pull/3035)
1416

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

Diff for: CONTRIBUTING.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ Please take a look at this list first, your contributions may belong in one of t
2525

2626
# Find the right branch
2727

28-
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.
28+
The default branch for this repo is `main`. All feature work is accomplished on branches from `main`.
2929

3030
## Find a Buddy and get Started Quickly!
3131

Diff for: opentelemetry-sdk/src/opentelemetry/sdk/metrics/_internal/_view_instrument_match.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
from logging import getLogger
1717
from threading import Lock
1818
from time import time_ns
19-
from typing import Dict, Iterable
19+
from typing import Dict, List, Sequence
2020

2121
from opentelemetry.metrics import Instrument
2222
from opentelemetry.sdk.metrics._internal.aggregation import (
@@ -126,12 +126,14 @@ def collect(
126126
self,
127127
aggregation_temporality: AggregationTemporality,
128128
collection_start_nanos: int,
129-
) -> Iterable[DataPointT]:
129+
) -> Sequence[DataPointT]:
130130

131+
data_points: List[DataPointT] = []
131132
with self._lock:
132133
for aggregation in self._attributes_aggregation.values():
133134
data_point = aggregation.collect(
134135
aggregation_temporality, collection_start_nanos
135136
)
136137
if data_point is not None:
137-
yield data_point
138+
data_points.append(data_point)
139+
return data_points

Diff for: opentelemetry-sdk/tests/metrics/test_metrics.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -514,11 +514,11 @@ def test_duplicate_instrument_aggregate_data(self):
514514
self.assertEqual(metric_0.name, "counter")
515515
self.assertEqual(metric_0.unit, "unit")
516516
self.assertEqual(metric_0.description, "description")
517-
self.assertEqual(next(metric_0.data.data_points).value, 3)
517+
self.assertEqual(next(iter(metric_0.data.data_points)).value, 3)
518518

519519
metric_1 = scope_metrics[1].metrics[0]
520520

521521
self.assertEqual(metric_1.name, "counter")
522522
self.assertEqual(metric_1.unit, "unit")
523523
self.assertEqual(metric_1.description, "description")
524-
self.assertEqual(next(metric_1.data.data_points).value, 7)
524+
self.assertEqual(next(iter(metric_1.data.data_points)).value, 7)

0 commit comments

Comments
 (0)