class TThreadedServer(ThriftThreadedServer): def __init__(self, *args, **kwargs): ThriftThreadedServer.__init__(self, *args, **kwargs) self.debug = False self.service_name = self.getServiceName() self.scribe = ThriftClient(scribe, "localhost", 1463) self.scribe_category = "Milo-Trace" self.rlock = threading.RLock() self.server_ip = socket.gethostbyname(socket.gethostname()) def logSpans(self, trace_context): self.rlock.acquire() try: if not self.scribe.isOpen(): self.scribe.open() data = span_util.serializeSpans(trace_context.getSpans()) trace_context.clear() message = LogEntry(category=self.scribe_category, message=data) self.scribe.Log([message]) except Exception, e: logging.error("Scribe error: " + e.message) self.scribe.close() self.rlock.release()
def __init__(self, *args, **kwargs): ThriftThreadedServer.__init__(self, *args, **kwargs) self.debug = False self.service_name = self.getServiceName() self.scribe = ThriftClient(scribe, "localhost", 1463) self.scribe_category = "Milo-Trace" self.rlock = threading.RLock() self.server_ip = socket.gethostbyname(socket.gethostname())
root.client_host = "1.2.3.4" try: client.enableTrace(root) client.open() client.ping("Chris Goffinet") client.ping("Milo Hoffman") client.ping("Gary Winston") # print out spans spans = client.getTraceContext().getSpans() print spans """ Example of taking the span data from MiloThriftClient This type of logic should be moved into your own framework on the client and server side. """ scribe_client = ThriftClient(scribe, scribe_host, scribe_port) try: scribe_client.open() # Serialize spans and write them to scribe which forwards to collector message = LogEntry(category="Milo-Trace", message=serializeSpans(spans)) scribe_client.Log([message]) scribe_client.close() finally: scribe_client.close() finally: client.close()