def test1(): import time cat.init("kd.test") a = cat.Transaction('c', 'b') time.sleep(2) a.complete() b = cat.Transaction('c', 'c') time.sleep(2) b.complete()
def test2(): ''' Use with context manager ''' with cat.Transaction("Transaction", "test2") as trans: trans.set_status(cat.CAT_ERROR) cat.log_event("h", "v") trans.add_data("a=1") trans.add_data("b=2")
def test3(): try: trans = cat.Transaction("Trans", "T3") trans.add_data("content") trans.add_data("key", "val") trans.set_status("error") trans.set_duration(500) trans.set_duration_start(time.time() * 1000 - 30 * 1000) trans.set_timestamp(time.time() * 1000 - 30 * 1000) finally: # NOTE don't forget to complete the transaction! trans.complete()
def serve(method, args): cat.log_event("hook", "receive") with cat.Transaction("serve", method) as t: try: t.add_data(json.dumps(args)) cat.log_event("hook", "before1") cat.log_event("hook", "before2") cat.log_event("hook", "before3") res = func(method, args) finally: cat.metric("rpc-count").count() cat.metric("rpc-duration").duration(100) cat.log_event("hook", "after") return res
def test2(): ''' Use via context manager ''' def do_something(): import random if random.random() < 0.1: raise Exception("error occured!") with cat.Transaction("Trans", "T2") as t: cat.log_event("Event", "E2") try: do_something() except Exception: t.set_status(cat.CAT_ERROR) t.add_data("context-manager") t.add_data("foo", "bar")
import cat import time #cat.init("cat.mysql") cat.init("kd.hbase") t = cat.Transaction("Trans", "t3") #cat.log_event("Event", "E1") time.sleep(0.3) t.complete()
def stage_begin(self, space, name): key = (space, name) name = '%s/%s' % (space, name) tran = cat.Transaction(space, name) self.__stage_list.append(tran)
def stage_begin(self, space, name): key = (space, name) name = '%s/%s' % (space, name) self.__stage_map[key] = cat.Transaction(space, name)