Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid generator in _ViewInstrumentMatch.collect() #3035

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ env:
# Otherwise, set variable to the commit of your branch on
# opentelemetry-python-contrib which is compatible with these Core repo
# changes.
CONTRIB_REPO_SHA: c6134843900e2eeb1b8b3383a897b38cc0905c38
CONTRIB_REPO_SHA: main
# This is needed because we do not clone the core repo in contrib builds anymore.
# When running contrib builds as part of core builds, we use actions/checkout@v2 which
# does not set an environment variable (simply just runs tox), which is different when
Expand Down
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)