importuuidimportosimporttime
l=[]classRecorder(object):def __init__(self,servername,root_span =None):if root_span ==None:
self.__span =Span(servername)else:
self.__span =Span(servername,root_span)#上下文管理器
def __enter__(self):return self.__span
#退出方法中,用来实现善后处理工作
def __exit__(self, exc_type, exc_val, exc_tb):
self.__span.record()
self.__span.record_save(self.__span.span)classSpan(object):def __init__(self,servername,root_span =None):
self.servername=servername
self.span=self.newspan()if root_span !=None:
root_span.dic['child_span'].append(self.span)
self.span["root_span_flag"] =Falsedefnewspan(self):
self.dic={"spanid": uuid.uuid4().int,"servername": self.servername,"location": "","ip": "","durationtime": 0,"st