prometheus / client_python

Prometheus instrumentation library for Python applications
Apache License 2.0
3.96k stars 798 forks source link

Publically expose immutable attributes on MetricWrapperBase #844

Open nmichlo opened 2 years ago

nmichlo commented 2 years ago

things like MetricWrapperBase._labelnames are immutable, but are passed in as parameters when instantiating MetricWrapperBase objects. These would be useful if they were exposed?

@property
def labelnames(self) -> Tuple[str, ...]:
    return self._labelnames
csmarchbanks commented 2 years ago

Hello, do you have a concrete use case where you would like to use the the labelnames specified on a metric? If it is helpful I can see exposing it, but I don't know of a required use case today.

nmichlo commented 2 years ago

(Admittedly this is from legacy code that I have not written myself, so I am not entirely sure about the original intention) But what I can see is that we current have to keep track of these label names externally and compare them against inputs accepted by a function just to make sure that what the metric is going to receive is correct. Its just not very clean this way if we don't access the property. I know we can access the private variable as a workaround, but that isn't ideal.

csmarchbanks commented 2 years ago

Hmm, for that use case could you use the kwargs that can be passed to .labels() to ensure safety?