Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

42 řádky
1.4KB

  1. from eventlet.zipkin import http
  2. from eventlet.zipkin import wsgi
  3. from eventlet.zipkin import greenthread
  4. from eventlet.zipkin import log
  5. from eventlet.zipkin import api
  6. from eventlet.zipkin.client import ZipkinClient
  7. def enable_trace_patch(host='127.0.0.1', port=9410,
  8. trace_app_log=False, sampling_rate=1.0):
  9. """ Apply monkey patch to trace your WSGI application.
  10. :param host: Scribe daemon IP address (default: '127.0.0.1')
  11. :param port: Scribe daemon port (default: 9410)
  12. :param trace_app_log: A Boolean indicating if the tracer will trace
  13. application log together or not. This facility assume that
  14. your application uses python standard logging library.
  15. (default: False)
  16. :param sampling_rate: A Float value (0.0~1.0) that indicates
  17. the tracing frequency. If you specify 1.0, all request
  18. are traced (and sent to Zipkin collecotr).
  19. If you specify 0.1, only 1/10 requests are traced. (default: 1.0)
  20. """
  21. api.client = ZipkinClient(host, port)
  22. # monkey patch for adding tracing facility
  23. wsgi.patch(sampling_rate)
  24. http.patch()
  25. greenthread.patch()
  26. # monkey patch for capturing application log
  27. if trace_app_log:
  28. log.patch()
  29. def disable_trace_patch():
  30. http.unpatch()
  31. wsgi.unpatch()
  32. greenthread.unpatch()
  33. log.unpatch()
  34. api.client.close()