wolph/python-statsd

Timer context manager doesn't add ".total"

Closed this issue · 1 comments

https://github.com/WoLpH/python-statsd/blob/master/statsd/timer.py
Is there any purpose on and logic behind why Timer.time context manager does not add .total. into the metric name but Timer.stop() call adds it by default? It seems inconsistent.

wolph commented

There is some logic to it, when using the decorator you can't support intermediate times/results. With the normal start/stop you can do that.

For example:

timer = statsd.Timer('your_function')
timer.start()
# do something here
timer.intermediate('part 1')
# do some more
timer.intermediate('part 2')
# and the finishing bit
timer.stop()

It's just a slightly different pattern to work with.