
Zipkin is a trend distributed tracing framewrok developed at Twitter. Such tracing is useful for both developers and operatos to understand the behavior of complex distributed systems and find performance bottlenecks. This patch provides a WSGI application using eventlet with tracing facility that complies with Zipkin. Signed-off-by: Yuichi Bando <bando.yuichi@lab.ntt.co.jp> Original commit modified for PEP-8 fixes. https://github.com/eventlet/eventlet/pull/218
34 lines
843 B
Python
34 lines
843 B
Python
from eventlet import greenthread
|
|
|
|
from eventlet.zipkin import api
|
|
|
|
|
|
__original_init__ = greenthread.GreenThread.__init__
|
|
__original_main__ = greenthread.GreenThread.main
|
|
|
|
|
|
def _patched__init(self, parent):
|
|
# parent thread saves current TraceData from tls to self
|
|
if api.is_tracing():
|
|
self.trace_data = api.get_trace_data()
|
|
|
|
__original_init__(self, parent)
|
|
|
|
|
|
def _patched_main(self, function, args, kwargs):
|
|
# child thread inherits TraceData
|
|
if hasattr(self, 'trace_data'):
|
|
api.set_trace_data(self.trace_data)
|
|
|
|
__original_main__(self, function, args, kwargs)
|
|
|
|
|
|
def patch():
|
|
greenthread.GreenThread.__init__ = _patched__init
|
|
greenthread.GreenThread.main = _patched_main
|
|
|
|
|
|
def unpatch():
|
|
greenthread.GreenThread.__init__ = __original_init__
|
|
greenthread.GreenThread.main = __original_main__
|