mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-01 15:46:07 -05:00
Update statsd decorator so that it will log on error.
Added logging for the build_dvla_file task
This commit is contained in:
@@ -10,20 +10,30 @@ def statsd(namespace):
|
||||
@functools.wraps(func)
|
||||
def wrapper(*args, **kwargs):
|
||||
start_time = monotonic()
|
||||
res = func(*args, **kwargs)
|
||||
elapsed_time = monotonic() - start_time
|
||||
current_app.logger.info(
|
||||
"{namespace} call {func} took {time}".format(
|
||||
namespace=namespace, func=func.__name__, time="{0:.4f}".format(elapsed_time)
|
||||
try:
|
||||
res = func(*args, **kwargs)
|
||||
elapsed_time = monotonic() - start_time
|
||||
|
||||
except Exception as e:
|
||||
current_app.logger.error(
|
||||
"{namespace} call {func} failed".format(
|
||||
namespace=namespace, func=func.__name__
|
||||
)
|
||||
)
|
||||
)
|
||||
statsd_client.incr('{namespace}.{func}'.format(
|
||||
namespace=namespace, func=func.__name__)
|
||||
)
|
||||
statsd_client.timing('{namespace}.{func}'.format(
|
||||
namespace=namespace, func=func.__name__), elapsed_time
|
||||
)
|
||||
return res
|
||||
raise e
|
||||
else:
|
||||
current_app.logger.info(
|
||||
"{namespace} call {func} took {time}".format(
|
||||
namespace=namespace, func=func.__name__, time="{0:.4f}".format(elapsed_time)
|
||||
)
|
||||
)
|
||||
statsd_client.incr('{namespace}.{func}'.format(
|
||||
namespace=namespace, func=func.__name__)
|
||||
)
|
||||
statsd_client.timing('{namespace}.{func}'.format(
|
||||
namespace=namespace, func=func.__name__), elapsed_time
|
||||
)
|
||||
return res
|
||||
wrapper.__wrapped__.__name__ = func.__name__
|
||||
return wrapper
|
||||
|
||||
|
||||
Reference in New Issue
Block a user