'Decorator for recording stats for amqp queue consumers/handlers.'

def amqp_processor(self, queue_name):

    def decorator(processor):
        def wrap_processor(msgs, *args):
            msg_tup = utils.tup(msgs)
            metrics_name = ('amqp.' + queue_name)
            start = time.time()
            try:
                with baseplate_integration.make_server_span(metrics_name):
                    return processor(msgs, *args)
            finally:
                service_time = ((time.time() - start) / len(msg_tup))
                for (n, msg) in enumerate(msg_tup):
                    fake_start = (start + (n * service_time))
                    fake_end = (fake_start + service_time)
                    self.transact(metrics_name, fake_start, fake_end)
                self.flush()
        return wrap_processor
    return decorator
