django-redis-metrics icon indicating copy to clipboard operation
django-redis-metrics copied to clipboard

provide a decorator to count how often a function is called

Open bradmontgomery opened this issue 9 years ago • 2 comments

Here's the scenario: My metrics what to track the functions that get called in my code/framework. we could implement this as a decorator

from redis_metrics.decorators import count

@count
def my_func():
    ....

Then we'd get a key/value in Redis similar to:

my_func: 42

bradmontgomery avatar Feb 07 '15 19:02 bradmontgomery

Marking this as an enhancement but it's really more an idea... not sure if if a good one or not.

bradmontgomery avatar Mar 12 '15 02:03 bradmontgomery

It would be really cool if metric could act as a context manager:

with metric('important-code-block'):
    # do the important stuff

Implementing this as a ContextDecorator would also allow us to use it as a decorator

@metric()
def my_func():
   ...

bradmontgomery avatar Feb 15 '16 21:02 bradmontgomery