You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Allow to add labels inside a context manager (prometheus#730)
* Allow to add labels inside a context manager
This way labels that depend on the result of the measured operation can
be added more conveniently, e.g. the status code of an http request:
from prometheus_client import Histogram
from requests import get
teapot = Histogram('teapot', 'A teapot', ['status'])
with teapot.time() as metric:
response = get('https://httpbin.org/status/418')
metric.labels(status=response.status_code)
Signed-off-by: Andreas Zeidler <andreas.zeidler@zeit.de>
* Also allow to add deferred labels for 'gauge' and 'summary' metrics
For this to work the 'observability' check needs to be deferred as
well, in case a label is added inside the context manager thereby
making the metric observable.
Signed-off-by: Andreas Zeidler <andreas.zeidler@zeit.de>
* Pass metric instance and callback name to `Timer`
This should make the code slightly more readable.
Signed-off-by: Andreas Zeidler <andreas.zeidler@zeit.de>
* Remove redundant check for observability
The callbacks are already taking care of this anyway.
Signed-off-by: Andreas Zeidler <andreas.zeidler@zeit.de>
0 commit comments