in jbi/common/instrument.py [0:0]
def instrument(prefix: str, exceptions: Sequence[Type[Exception]], **backoff_params):
"""This decorator wraps a function such that it increments a counter every
time it is called and times its execution. It retries the function if the
specified exceptions are raised.
"""
def decorator(func):
@backoff.on_exception(
backoff.expo,
exceptions,
max_tries=settings.max_retries + 1,
**backoff_params,
)
@wraps(func)
def wrapper(*args, **kwargs):
# Increment the call counter.
statsd.incr(f"jbi.{prefix}.methods.{func.__name__}.count")
# Time its execution.
with statsd.timer(f"jbi.{prefix}.methods.{func.__name__}.timer"):
return func(*args, **kwargs)
return wrapper
return decorator