Skip to content

Does it make sense for metric constructors to return pointers to structs instead of interfaces? #891

@miroswan

Description

@miroswan

The Counter and Histogram constructors return interfaces instead of pointers to structs. Now the constructor for Counter returns a Counter interface whose underlying type implements both Counter and ExemplarAdder and the constructor for Histogram returns a Histogram interface whose underlying type implements both Histogram and ExemplarObserver. The users of these clients now need to do type casting just to get the type they want, which I would argue is not ideal. Generally, I believe it makes sense for constructors to return pointers to types instead of interfaces since interfaces are satisfied implicitly and this approach gives the caller more options out of the box.

Would there be any consideration for having these constructors return pointers to exported structs? Alternatively, we could create a new set of constructors that do this so the API can remain stable for existing users.

Fruit for thought.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions