def metrics_wrapper(*args, **kwargs): start_time = time() error = 0 try: return function(*args, **kwargs) except Exception as e: LOG.error("Exception while executing " + function.__name__) error = 1 raise e finally: end_time = time() try: metrics = ThreadLocalMetrics.get() metric_time = self.__metric_name + "_time" metrics.add_time(metric_time, int((end_time - start_time)*1000), Unit.MILLIS) if self.__report_error == True: metric_error = self.__metric_name + "_error" metrics.add_count(metric_error, error) except AttributeError as e: LOG.exception("No threadlocal metrics object: %s", e)
def fetch_thread_local_metrics(self): return ThreadLocalMetrics.get()