Should the SDK API constrain the Readers that can be used? #3085
Labels
area:metrics
Part of OpenTelemetry Metrics
enhancement
New feature or request
pkg:SDK
Related to an SDK package
Milestone
Background
Currently, we require that the Readers provided to the
WithReader
Option be comparable. We check that the two readers we create are comparable, but if a user embeds a Reader in a non-comparable struct WithReader will panic. An example of how to trigger this can be found here.This type of embedding will probably be used in the prometheus exporter.
Problem Statement
Should we further constrain our option to prevent users from supplying a non-comparable reader? This would likely be run into by exporter developers and hopefully caught by a working example.
Proposed Solution
We could create a ComparableReader interface that we constrain the WithReader with. Here is an example branch.
This would in effect turn the runtime panic into a compile-time error. You wouldn't be able to use a non-comparable Reader with the only option we have.
This would have two drawbacks:
Reader
->ComparableReader
the output of New*Reader would have to change from Reader.*manualReader
, which has usability concerns,*ManualReader
, note this is exporting ManualReader, which means we need to guard aginst users using a&ManualReader{}
Alternatives
The text was updated successfully, but these errors were encountered: