You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

34 lines
843B

  1. from eventlet import greenthread
  2. from eventlet.zipkin import api
  3. __original_init__ = greenthread.GreenThread.__init__
  4. __original_main__ = greenthread.GreenThread.main
  5. def _patched__init(self, parent):
  6. # parent thread saves current TraceData from tls to self
  7. if api.is_tracing():
  8. self.trace_data = api.get_trace_data()
  9. __original_init__(self, parent)
  10. def _patched_main(self, function, args, kwargs):
  11. # child thread inherits TraceData
  12. if hasattr(self, 'trace_data'):
  13. api.set_trace_data(self.trace_data)
  14. __original_main__(self, function, args, kwargs)
  15. def patch():
  16. greenthread.GreenThread.__init__ = _patched__init
  17. greenthread.GreenThread.main = _patched_main
  18. def unpatch():
  19. greenthread.GreenThread.__init__ = __original_init__
  20. greenthread.GreenThread.main = __original_main__