概述

opentracing_instrumentation 是 Uber 开源的一套分布式Tracer Lib库。
可以在 Python 中快速注入 requests 等相关的 Trace 追踪任务。

QuickStart

  1. from opentracing_instrumentation.client_hooks import requests as requests_hooks
  2. def request_hook(response, span):
  3. """
  4. # 注入 Response 信息
  5. """
  6. if response.status_code >= 300:
  7. span.log_kv({
  8. "event": "send requests response code abnormal",
  9. "response.status_code": str(response.status_code),
  10. "response.content": str(response.text),
  11. "request.headers": str(response.request.headers),
  12. "request.body": str(response.request.body)
  13. })
  14. request_patcher = requests_hooks.RequestsPatcher()
  15. request_patcher.set_response_handler_hook(response_handler_hook=request_hook)
  16. request_patcher.install_patches()