-
Notifications
You must be signed in to change notification settings - Fork 757
Description
This applies to all of the MetricsData data types Sum, Histogram and Gauge. The type annotation is Sequence:
opentelemetry-python/opentelemetry-sdk/src/opentelemetry/sdk/metrics/_internal/point.py
Line 68 in 778c4b1
| data_points: Sequence[NumberDataPoint] |
But the implementation assigns an Iterable (specifically a generator which is not a valid Sequence):
Line 160 in 778c4b1
| data_points=view_instrument_match.collect( |
What is the expected behavior?
Type annotated as Sequence should work with len(), subscription, etc.. A more subtle bug the generator causes is that data_points can only be iterated over once, which will consume the generator.
What is the actual behavior?
TypeError: object of type 'generator' has no len()
Additional context
Possible fixes
I'd recommend adding calls to list() or tuple() to convert the generator to a sequence or alter _ViewInstrumentMatch.collect() to return a sequence itself. I think this is appropriate as the generators are actually holding SDK locks which can remain locked if the generator is not consumed.