Skip to content

Sum/Histogram/Gauge.data_points annotated as Sequence but actual type is generator #3021

@aabmass

Description

@aabmass

This applies to all of the MetricsData data types Sum, Histogram and Gauge. The type annotation is Sequence:

But the implementation assigns an Iterable (specifically a generator which is not a valid Sequence):

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.

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingmetricssdkAffects the SDK package.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions