{"id":153315,"date":"2019-08-23T09:01:46","date_gmt":"2019-08-23T01:01:46","guid":{"rendered":"https:\/\/lrxjmw.cn\/?p=153315"},"modified":"2019-08-12T17:05:09","modified_gmt":"2019-08-12T09:05:09","slug":"tracking-service-monitoring","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/tracking-service-monitoring.html","title":{"rendered":"\u670d\u52a1\u76d1\u63a7\u4e4b\u5206\u5e03\u5f0f\u8ffd\u8e2a\u4e00\u7bc7\u8bfb\u61c2"},"content":{"rendered":"\n\n\n
\u5bfc\u8bfb<\/td>\n\u73b0\u5728\u8d8a\u6765\u8d8a\u591a\u7684\u5e94\u7528\u8fc1\u79fb\u5230\u57fa\u4e8e\u5fae\u670d\u52a1\u7684\u4e91\u539f\u751f\u7684\u67b6\u6784\u4e4b\u4e0a\uff0c\u5fae\u670d\u52a1\u67b6\u6784\u5f88\u5f3a\u5927\uff0c\u4f46\u662f\u540c\u65f6\u4e5f\u5e26\u6765\u4e86\u5f88\u591a\u7684\u6311\u6218\uff0c\u5c24\u5176\u662f\u5982\u4f55\u5bf9\u5e94\u7528\u8fdb\u884c\u8c03\u8bd5\uff0c\u5982\u4f55\u76d1\u63a7\u591a\u4e2a\u670d\u52a1\u95f4\u7684\u8c03\u7528\u5173\u7cfb\u548c\u72b6\u6001\u3002\u5982\u4f55\u6709\u6548\u7684\u5bf9\u5fae\u670d\u52a1\u67b6\u6784\u8fdb\u884c\u6709\u6548\u7684\u76d1\u63a7\u6210\u4e3a\u5fae\u670d\u52a1\u67b6\u6784\u8fd0\u7ef4\u6210\u529f\u7684\u5173\u952e\u3002<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n

\u73b0\u5728\u8d8a\u6765\u8d8a\u591a\u7684\u5e94\u7528\u8fc1\u79fb\u5230\u57fa\u4e8e\u5fae\u670d\u52a1\u7684\u4e91\u539f\u751f\u7684\u67b6\u6784\u4e4b\u4e0a\uff0c\u5fae\u670d\u52a1\u67b6\u6784\u5f88\u5f3a\u5927\uff0c\u4f46\u662f\u540c\u65f6\u4e5f\u5e26\u6765\u4e86\u5f88\u591a\u7684\u6311\u6218\uff0c\u5c24\u5176\u662f\u5982\u4f55\u5bf9\u5e94\u7528\u8fdb\u884c\u8c03\u8bd5\uff0c\u5982\u4f55\u76d1\u63a7\u591a\u4e2a\u670d\u52a1\u95f4\u7684\u8c03\u7528\u5173\u7cfb\u548c\u72b6\u6001\u3002\u5982\u4f55\u6709\u6548\u7684\u5bf9\u5fae\u670d\u52a1\u67b6\u6784\u8fdb\u884c\u6709\u6548\u7684\u76d1\u63a7\u6210\u4e3a\u5fae\u670d\u52a1\u67b6\u6784\u8fd0\u7ef4\u6210\u529f\u7684\u5173\u952e\u3002\u7528\u8f6f\u4ef6\u67b6\u6784\u7684\u8bed\u8a00\u6765\u8bf4\u5c31\u662f\u8981\u589e\u5f3a\u5fae\u670d\u52a1\u67b6\u6784\u7684\u53ef\u89c2\u6d4b\u6027(Observability)\u3002<\/p>\n

\"\"<\/center>\u5fae\u670d\u52a1\u7684\u76d1\u63a7\u4e3b\u8981\u5305\u542b\u4e00\u4e0b\u4e09\u4e2a\u65b9\u9762\uff1a<\/p>\n
    \n
  • \u901a\u8fc7\u6536\u96c6\u65e5\u5fd7\uff0c\u5bf9\u7cfb\u7edf\u548c\u5404\u4e2a\u670d\u52a1\u7684\u8fd0\u884c\u72b6\u6001\u8fdb\u884c\u76d1\u63a7<\/li>\n
  • \u901a\u8fc7\u6536\u96c6\u91cf\u5ea6(Metrics)\uff0c\u5bf9\u7cfb\u7edf\u548c\u5404\u4e2a\u670d\u52a1\u7684\u6027\u80fd\u8fdb\u884c\u76d1\u63a7<\/li>\n
  • \u901a\u8fc7\u5206\u5e03\u5f0f\u8ffd\u8e2a\uff0c\u8ffd\u8e2a\u670d\u52a1\u8bf7\u6c42\u662f\u5982\u4f55\u5728\u5404\u4e2a\u5206\u5e03\u7684\u7ec4\u4ef6\u4e2d\u8fdb\u884c\u5904\u7406\u7684\u7ec6\u8282<\/li>\n<\/ul>\n

    \u5bf9\u4e8e\u662f\u65e5\u5fd7\u548c\u91cf\u5ea6\u7684\u6536\u96c6\u548c\u76d1\u63a7\uff0c\u5927\u5bb6\u4f1a\u6bd4\u8f83\u719f\u6089\u3002\u5e38\u89c1\u7684\u65e5\u5fd7\u6536\u96c6\u67b6\u6784\u5305\u542b\u5229\u7528Fluentd\u5bf9\u7cfb\u7edf\u65e5\u5fd7\u8fdb\u884c\u6536\u96c6\uff0c\u7136\u540e\u5229\u7528ELK\u6216\u8005Splunk\u8fdb\u884c\u65e5\u5fd7\u5206\u6790\u3002\u800c\u5bf9\u4e8e\u6027\u80fd\u76d1\u63a7\uff0cPrometheus\u662f\u5e38\u89c1\u7684\u6d41\u884c\u7684\u9009\u62e9\u3002<\/p>\n

    \u5206\u5e03\u5f0f\u8ffd\u8e2a\u6b63\u5728\u88ab\u8d8a\u6765\u8d8a\u591a\u7684\u5e94\u7528\u6240\u91c7\u7528\u3002\u5206\u5e03\u5f0f\u8ffd\u8e2a\u53ef\u4ee5\u901a\u8fc7\u5bf9\u5fae\u670d\u52a1\u8c03\u7528\u94fe\u7684\u8ddf\u8e2a\uff0c\u6784\u5efa\u4e00\u4e2a\u4ece\u670d\u52a1\u8bf7\u6c42\u5f00\u59cb\u5230\u5404\u4e2a\u5fae\u670d\u52a1\u4ea4\u4e92\u7684\u5168\u90e8\u8c03\u7528\u8fc7\u7a0b\u7684\u89c6\u56fe\u3002\u7528\u6237\u53ef\u4ee5\u4ece\u4e2d\u4e86\u89e3\u5230\u8bf8\u5982\u5e94\u7528\u8c03\u7528\u7684\u65f6\u5ef6\uff0c\u7f51\u7edc\u8c03\u7528(HTTP\uff0cRPC)\u7684\u751f\u547d\u5468\u671f\uff0c\u7cfb\u7edf\u7684\u6027\u80fd\u74f6\u9888\u7b49\u7b49\u4fe1\u606f\u3002\u90a3\u4e48\u5206\u5e03\u5f0f\u8ffd\u8e2a\u662f\u5982\u4f55\u5b9e\u73b0\u7684\u5462?<\/p>\n

    1.\u5206\u5e03\u5f0f\u8ffd\u8e2a\u7684\u6982\u5ff5<\/strong><\/strong><\/div>\n

    \u8c37\u6b4c\u57282010\u5e744\u6708\u53d1\u8868\u4e86\u4e00\u7bc7\u8bba\u6587\u300aDapper, a Large-Scale Distributed Systems Tracing Infrastructure\u300b(http:\/\/1t.click\/6EB)\uff0c\u4ecb\u7ecd\u4e86\u5206\u5e03\u5f0f\u8ffd\u8e2a\u7684\u6982\u5ff5\u3002<\/p>\n

    \"\"<\/center>\u5bf9\u4e8e\u5206\u5e03\u5f0f\u8ffd\u8e2a\uff0c\u4e3b\u8981\u6709\u4ee5\u4e0b\u7684\u51e0\u4e2a\u6982\u5ff5\uff1a<\/p>\n
      \n
    • \u8ffd\u8e2a Trace\uff1a\u5c31\u662f\u7531\u5206\u5e03\u7684\u5fae\u670d\u52a1\u534f\u4f5c\u6240\u652f\u6491\u7684\u4e00\u4e2a\u4e8b\u52a1\u3002\u4e00\u4e2a\u8ffd\u8e2a\uff0c\u5305\u542b\u4e3a\u8be5\u4e8b\u52a1\u63d0\u4f9b\u670d\u52a1\u7684\u5404\u4e2a\u670d\u52a1\u8bf7\u6c42\u3002<\/li>\n
    • \u8de8\u5ea6 Span\uff1aSpan\u662f\u4e8b\u52a1\u4e2d\u7684\u4e00\u4e2a\u5de5\u4f5c\u6d41\uff0c\u4e00\u4e2aSpan\u5305\u542b\u4e86\u65f6\u95f4\u6233\uff0c\u65e5\u5fd7\u548c\u6807\u7b7e\u4fe1\u606f\u3002Span\u4e4b\u95f4\u5305\u542b\u7236\u5b50\u5173\u7cfb\uff0c\u6216\u8005\u4e3b\u4ece(Followup)\u5173\u7cfb\u3002<\/li>\n
    • \u8de8\u5ea6\u4e0a\u4e0b\u6587 Span Context\uff1a\u8de8\u5ea6\u4e0a\u4e0b\u6587\u662f\u652f\u6491\u5206\u5e03\u5f0f\u8ffd\u8e2a\u7684\u5173\u952e\uff0c\u5b83\u53ef\u4ee5\u5728\u8c03\u7528\u7684\u670d\u52a1\u4e4b\u95f4\u4f20\u9012\uff0c\u4e0a\u4e0b\u6587\u7684\u5185\u5bb9\u5305\u62ec\u8bf8\u5982\uff1a\u4ece\u4e00\u4e2a\u670d\u52a1\u4f20\u9012\u5230\u53e6\u4e00\u4e2a\u670d\u52a1\u7684\u65f6\u95f4\uff0c\u8ffd\u8e2a\u7684ID\uff0cSpan\u7684ID\u8fd8\u6709\u5176\u5b83\u9700\u8981\u4ece\u4e0a\u6e38\u670d\u52a1\u4f20\u9012\u5230\u4e0b\u6e38\u670d\u52a1\u7684\u4fe1\u606f\u3002<\/li>\n<\/ul>\n
      2.OpenTracing \u6807\u51c6\u6982\u5ff5<\/strong><\/strong><\/div>\n

      \u57fa\u4e8e\u8c37\u6b4c\u63d0\u51fa\u7684\u6982\u5ff5OpenTracing(http:\/\/1t.click\/6tC)\u5b9a\u4e49\u4e86\u4e00\u4e2a\u5f00\u653e\u7684\u5206\u5e03\u5f0f\u8ffd\u8e2a\u7684\u6807\u51c6\u3002<\/p>\n

      Span\u662f\u5206\u5e03\u5f0f\u8ffd\u8e2a\u7684\u57fa\u672c\u7ec4\u6210\u5355\u5143\uff0c\u8868\u793a\u4e00\u4e2a\u5206\u5e03\u5f0f\u7cfb\u7edf\u4e2d\u7684\u5355\u72ec\u7684\u5de5\u4f5c\u5355\u5143\u3002\u6bcf\u4e00\u4e2aSpan\u53ef\u4ee5\u5305\u542b\u5176\u5b83Span\u7684\u5f15\u7528\u3002\u591a\u4e2aSpan\u5728\u4e00\u8d77\u6784\u6210\u4e86Trace\u3002<\/p>\n

      \"\"<\/center>OpenTracing\u7684\u89c4\u8303\u5b9a\u4e49\u6bcf\u4e00\u4e2aSpan\u90fd\u5305\u542b\u4e86\u4ee5\u4e0b\u5185\u5bb9\uff1a<\/p>\n
        \n
      • \u64cd\u4f5c\u540d(Operation Name)\uff0c\u6807\u5fd7\u8be5\u64cd\u4f5c\u662f\u4ec0\u4e48<\/li>\n
      • \u6807\u7b7e (Tag)\uff0c\u6807\u7b7e\u662f\u4e00\u4e2a\u540d\u503c\u5bf9\uff0c\u7528\u6237\u53ef\u4ee5\u52a0\u5165\u4efb\u4f55\u5bf9\u8ffd\u8e2a\u6709\u610f\u4e49\u7684\u4fe1\u606f<\/li>\n
      • \u65e5\u5fd7(Logs)\uff0c\u65e5\u5fd7\u4e5f\u5b9a\u4e49\u4e3a\u540d\u503c\u5bf9\u3002\u7528\u4e8e\u6355\u83b7\u8c03\u8bd5\u4fe1\u606f\uff0c\u6216\u8005\u76f8\u5173Span\u7684\u76f8\u5173\u4fe1\u606f<\/li>\n
      • \u8de8\u5ea6\u4e0a\u4e0b\u6587\u5462 (SpanContext)\uff0cSpanContext\u8d1f\u8d23\u5b50\u5fae\u670d\u52a1\u7cfb\u7edf\u8fb9\u754c\u4f20\u9012\u6570\u636e\u3002\u5b83\u4e3b\u8981\u5305\u542b\u4e24\u90e8\u5206\uff1a<\/li>\n<\/ul>\n
          \n
        1. \u548c\u5b9e\u73b0\u65e0\u5173\u7684\u72b6\u6001\u4fe1\u606f\uff0c\u4f8b\u5982Trace ID\uff0cSpan ID<\/li>\n
        2. \u884c\u674e\u9879 (Baggage Item)\u3002\u5982\u679c\u628a\u5fae\u670d\u52a1\u8c03\u7528\u6bd4\u505a\u4ece\u4e00\u4e2a\u57ce\u5e02\u5230\u53e6\u4e00\u4e2a\u57ce\u5e02\u7684\u98de\u884c, \u90a3\u4e48SpanContext\u5c31\u53ef\u4ee5\u770b\u6210\u662f\u98de\u673a\u8fd0\u8f7d\u7684\u5185\u5bb9\u3002Trace ID\u548cSpan ID\u5c31\u50cf\u662f\u822a\u73ed\u53f7\uff0c\u800c\u884c\u674e\u9879\u5c31\u50cf\u662f\u8fd0\u9001\u7684\u884c\u674e\u3002\u6bcf\u6b21\u670d\u52a1\u8c03\u7528\uff0c\u7528\u6237\u90fd\u53ef\u4ee5\u51b3\u5b9a\u53d1\u9001\u4e0d\u540c\u7684\u884c\u674e\u3002<\/li>\n<\/ol>\n

          \u8fd9\u91cc\u662f\u4e00\u4e2aSpan\u7684\u4f8b\u5b50\uff1a<\/p>\n

          t=0\u00a0operation\u00a0name<\/span>: db_query t=x\u00a0\r\n\u00a0+-----------------------------------------------------+<\/span> \r\n |\u00a0\u00b7\u00a0\u00b7\u00a0\u00b7\u00a0\u00b7\u00a0\u00b7\u00a0\u00b7\u00a0\u00b7\u00a0\u00b7\u00a0\u00b7\u00a0\u00b7\u00a0Span\u00a0\u00b7\u00a0\u00b7\u00a0\u00b7\u00a0\u00b7\u00a0\u00b7\u00a0\u00b7\u00a0\u00b7\u00a0\u00b7\u00a0\u00b7\u00a0\u00b7\u00a0|\u00a0\r\n\u00a0+-----------------------------------------------------+<\/span> \r\nTags: \r\n- db.instance:\"jdbc:mysql:\/\/127.0.0.1:3306\/customers\u00a0\r\n-\u00a0db.statement:\u00a0\"SELECT\u00a0*\u00a0FROM\u00a0mytable\u00a0WHERE\u00a0foo='bar';\"<\/span> \u200b\u00a0\r\nLogs: \r\n-\u00a0message:\"Can't\u00a0connect\u00a0to\u00a0mysql\u00a0server\u00a0on\u00a0'127.0.0.1'(10061)\"<\/span> \u200b\u00a0\r\nSpanContext: \r\n-\u00a0trace_id:\"abc123\"<\/span> \r\n-\u00a0span_id:\"xyz789\"<\/span> \r\n- Baggage Items:\u00a0\r\n- special_id:\"vsid1738\"<\/span><\/pre>\n

          \u8981\u5b9e\u73b0\u5206\u5e03\u5f0f\u8ffd\u8e2a\uff0c\u5982\u4f55\u4f20\u9012SpanContext\u662f\u5173\u952e\u3002OpenTracing\u5b9a\u4e49\u4e86\u4e24\u4e2a\u65b9\u6cd5Inject\u548cExtract\u7528\u4e8eSpanContext\u7684\u6ce8\u5165\u548c\u63d0\u53d6\u3002<\/p>\n

          \"\"<\/center>Inject \u4f2a\u4ee3\u7801<\/strong><\/p>\n
          span_context = ...\u00a0\r\noutbound_request = ... \u200b\u00a0\r\n# We'll use the (builtin) HTTP_HEADERS carrier format. We\u00a0\r\n#\u00a0start\u00a0by<\/span>\u00a0using\u00a0an\u00a0empty\u00a0map\u00a0as<\/span>\u00a0the\u00a0carrier\u00a0prior<\/span>\u00a0to<\/span> the\u00a0\r\n#\u00a0call\u00a0to<\/span> `tracer.inject`.\u00a0\r\ncarrier = {}\u00a0\r\ntracer.inject(span_context, opentracing.Format.HTTP_HEADERS, carrier) \u200b\u00a0\r\n#\u00a0`carrier`\u00a0now\u00a0contains<\/span>\u00a0(opaque)\u00a0key<\/span>:value pairs which we pass\u00a0\r\n# along over whatever wire protocol we already use.\u00a0\r\nfor<\/span>\u00a0key<\/span>,\u00a0value\u00a0in<\/span> carrier:\u00a0\r\noutbound_request.headers[key<\/span>]\u00a0=\u00a0escape<\/span>(value)<\/pre>\n

          \u8fd9\u91cc\u7684\u6ce8\u5165\u7684\u8fc7\u7a0b\u5c31\u662f\u628acontext\u7684\u6240\u6709\u4fe1\u606f\u5199\u5165\u5230\u4e00\u4e2a\u53ebCarrier\u7684\u5b57\u5178\u4e2d\uff0c\u7136\u540e\u628a\u5b57\u5178\u4e2d\u7684\u6240\u6709\u540d\u503c\u5bf9\u5199\u5165 HTTP Header\u3002<\/p>\n

          Extract \u4f2a\u4ee3\u7801<\/strong><\/strong><\/div>\n
          inbound_request = ... \u200b\u00a0\r\n# We'll again use the (builtin) HTTP_HEADERS carrier format. Per the\u00a0\r\n# HTTP_HEADERS documentation, we can use a map that has extraneous data\u00a0\r\n#\u00a0in<\/span>\u00a0it\u00a0and<\/span>\u00a0let\u00a0the\u00a0OpenTracing\u00a0implementation\u00a0look\u00a0for<\/span> the\u00a0subset\u00a0\r\n#\u00a0of<\/span>\u00a0key<\/span>:value pairs it needs.\u00a0\r\n# \r\n#\u00a0As<\/span>\u00a0such,\u00a0we\u00a0directly\u00a0use\u00a0the\u00a0key<\/span>:value `inbound_request.headers`\u00a0\r\n#\u00a0map\u00a0as<\/span> the\u00a0carrier.\u00a0\r\ncarrier = inbound_request.headers\u00a0\r\nspan_context = tracer.extract(opentracing.Format.HTTP_HEADERS, carrier)\u00a0\r\n#\u00a0Continue<\/span> the\u00a0trace\u00a0given\u00a0span_context.\u00a0E.g.,\u00a0\r\nspan\u00a0=\u00a0tracer.start_span(\"...\"<\/span>, child_of=span_context) \u200b\u00a0\r\n#\u00a0(If\u00a0`carrier`\u00a0held\u00a0trace\u00a0data,\u00a0`span`\u00a0will\u00a0now\u00a0be\u00a0ready\u00a0to<\/span>\u00a0use.)<\/pre>\n

          \u62bd\u53d6\u8fc7\u7a0b\u662f\u6ce8\u5165\u7684\u9006\u8fc7\u7a0b\uff0c\u4ececarrier\uff0c\u4e5f\u5c31\u662fHTTP Headers\uff0c\u6784\u5efaSpanContext\u3002<\/p>\n

          \u6574\u4e2a\u8fc7\u7a0b\u7c7b\u4f3c\u5ba2\u6237\u7aef\u548c\u670d\u52a1\u5668\u4f20\u9012\u6570\u636e\u7684\u5e8f\u5217\u5316\u548c\u53cd\u5e8f\u5217\u5316\u7684\u8fc7\u7a0b\u3002\u8fd9\u91cc\u7684Carrier\u5b57\u5178\u652f\u6301Key\u4e3astring\u7c7b\u578b\uff0cvalue\u4e3astring\u6216\u8005Binary\u683c\u5f0f(Bytes)\u3002<\/p>\n

          3.\u600e\u4e48\u7528\u80fd?<\/strong><\/strong><\/div>\n

          \u597d\u4e86\u8bb2\u4e86\u4e00\u5927\u5806\u7684\u6982\u5ff5\uff0c\u4f5c\u4e3a\u7a0b\u5e8f\u733f\u7684\u4f60\u65e9\u5df2\u7ecf\u4e0d\u8010\u70e6\u4e86\uff0c\u4e0d\u8981\u8bb2\u90a3\u4e9b\u6709\u7684\u6ca1\u7684\uff0c\u5feb\u4e0a\u4ee3\u7801\u3002\u4e0d\u6025\u6211\u4eec\u8fd9\u5c31\u770b\u770b\u5177\u4f53\u5982\u4f55\u4f7f\u7528Tracing\u3002<\/p>\n

          \u6211\u4eec\u7528\u4e00\u4e2a\u7a0b\u5e8f\u733f\u559c\u95fb\u4e50\u89c1\u7684\u6253\u5370\u2018hello world\u2019\u7684Python\u5e94\u7528\u6765\u8bf4\u660eOpenTracing\u662f\u5982\u4f55\u5de5\u4f5c\u7684\u3002<\/p>\n

          \u5ba2\u6237\u7aef\u4ee3\u7801<\/strong><\/strong><\/div>\n
          import requests\u00a0\r\nimport sys\u00a0\r\nimport\u00a0time<\/span> \r\nfrom<\/span> lib.tracing\u00a0import\u00a0init_tracer\u00a0\r\nfrom<\/span> opentracing.ext\u00a0import\u00a0tags\u00a0\r\nfrom<\/span> opentracing.propagation\u00a0import\u00a0Format\u00a0\u200b\u00a0\r\ndef say_hello(hello_to):\u00a0\r\nwith<\/span>\u00a0tracer.start_active_span('say-hello'<\/span>)\u00a0as<\/span> scope:\u00a0\r\nscope.span.set_tag('hello-to'<\/span>, hello_to)\u00a0\r\nhello_str = format_string(hello_to)\u00a0\r\nprint_hello(hello_str) \r\ndef format_string(hello_to):\u00a0\r\nwith<\/span>\u00a0tracer.start_active_span('format'<\/span>)\u00a0as<\/span> scope:\u00a0\r\nhello_str = http_get(8081,\u00a0'format'<\/span>,\u00a0'helloTo'<\/span>, hello_to)\u00a0\r\nscope.span.log_kv({'event'<\/span>:\u00a0'string-format'<\/span>,\u00a0'value'<\/span>: hello_str})\u00a0\r\nreturn<\/span> hello_str\u00a0\u200b\u00a0\r\ndef print_hello(hello_str):\u00a0\r\nwith<\/span>\u00a0tracer.start_active_span('println'<\/span>)\u00a0as<\/span> scope:\u00a0\r\nhttp_get(8082, 'publish'<\/span>,\u00a0'helloStr'<\/span>, hello_str)\u00a0\r\nscope.span.log_kv({'event'<\/span>:\u00a0'println'<\/span>}) \u200b\u00a0\r\ndef http_get(port, path, param, value):\u00a0\r\nurl =\u00a0'http:\/\/localhost:%s\/%s'<\/span> %\u00a0(port,\u00a0path)\u00a0\u200b\u00a0\r\nspan = tracer.active_span\u00a0\r\nspan.set_tag(tags.HTTP_METHOD, 'GET'<\/span>) \r\nspan.set_tag(tags.HTTP_URL, url)\u00a0\r\nspan.set_tag(tags.SPAN_KIND, tags.SPAN_KIND_RPC_CLIENT)\u00a0\r\nheaders = {}\u00a0\r\ntracer.inject(span, Format.HTTP_HEADERS, headers) \u200b\u00a0\r\nr = requests.get(url, params={param: value}, headers=headers)\u00a0\r\nassert r.status_code == 200\u00a0\r\nreturn<\/span> r.text\u00a0\r\n# main\u00a0\r\nassert len(sys.argv) == 2 \u200b\u00a0\r\ntracer\u00a0=\u00a0init_tracer('hello-world'<\/span>) \u200b\u00a0\r\nhello_to = sys.argv[1]\u00a0\r\nsay_hello(hello_to) \r\n#\u00a0yield\u00a0to<\/span>\u00a0IOLoop\u00a0to<\/span> flush\u00a0the\u00a0spans\u00a0\r\ntime<\/span>.sleep(2) \r\ntracer.close<\/span>()<\/pre>\n

          \u5ba2\u6237\u7aef\u5b8c\u6210\u4e86\u4ee5\u4e0b\u7684\u5de5\u4f5c\uff1a<\/p>\n

            \n
          • \u521d\u59cb\u5316Tracer\uff0ctrace\u7684\u540d\u5b57\u662f\u2018hello-world\u2019<\/li>\n
          • \u521b\u5efa\u4ee5\u4e2a\u5ba2\u6237\u7aef\u64cd\u4f5csay_hello\uff0c\u8be5\u64cd\u4f5c\u5173\u8054\u4e00\u4e2aSpan\uff0c\u53d6\u540d\u2018say-hello\u2019\uff0c\u5e76\u8c03\u7528span.set_tag\u52a0\u5165\u6807\u7b7e<\/li>\n
          • \u5728\u64cd\u4f5csay_hello\u4e2d\u8c03\u7528\u7b2c\u4e00\u4e2aHTTP \u670d\u52a1A\uff0cformat_string\uff0c \u8be5\u64cd\u4f5c\u5173\u8054\u53e6\u4e00\u4e2aSpan\u53d6\u540d\u2018format\u2019\uff0c\u5e76\u8c03\u7528span.log_kv\u52a0\u5165\u65e5\u5fd7<\/li>\n
          • \u4e4b\u540e\u8c03\u7528\u53e6\u4e00\u4e2aHTTP \u670d\u52a1B\uff0cprint_hello\uff0c \u8be5\u64cd\u4f5c\u5173\u8054\u53e6\u4e00\u4e2aSpan\u53d6\u540d\u2018println\u2019\uff0c\u5e76\u8c03\u7528span.log_kv\u52a0\u5165\u65e5\u5fd7<\/li>\n
          • \u5bf9\u4e8e\u6bcf\u4e00\u4e2aHTTP\u8bf7\u6c42\uff0c\u5728Span\u4e2d\u90fd\u52a0\u5165\u6807\u7b7e\uff0c\u6807\u5fd7http method\uff0chttp url\u548cspan kind\u3002\u5e76\u8c03\u7528tracer.inject\u628aSpanContext\u6ce8\u5165\u5230http header \u4e2d\u3002<\/li>\n<\/ul>\n
            \u670d\u52a1A\u4ee3\u7801<\/strong><\/strong><\/div>\n
            from<\/span> flask\u00a0import\u00a0Flask\u00a0\r\nfrom<\/span> flask\u00a0import\u00a0request\u00a0\r\nfrom<\/span> lib.tracing\u00a0import\u00a0init_tracer\u00a0\r\nfrom<\/span> opentracing.ext\u00a0import\u00a0tags\u00a0\r\nfrom<\/span> opentracing.propagation\u00a0import\u00a0Format\u00a0\u200b\u00a0\r\napp = Flask(__name__)\u00a0\r\ntracer\u00a0=\u00a0init_tracer('formatter'<\/span>)\u00a0\u00a0\u00a0 \r\n@app.route(\"\/format\"<\/span>) \r\ndef format():\u00a0\r\nspan_ctx = tracer.extract(Format.HTTP_HEADERS, request.headers)\u00a0\r\nspan_tags = {tags.SPAN_KIND: tags.SPAN_KIND_RPC_SERVER}\u00a0\r\nwith<\/span>\u00a0tracer.start_active_span('format'<\/span>, child_of=span_ctx, tags=span_tags):\u00a0\r\nhello_to = request.args.get('helloTo'<\/span>) \r\nreturn<\/span>\u00a0'Hello,\u00a0%s!'<\/span> %\u00a0hello_to\u00a0\r\nif\u00a0__name__\u00a0==\u00a0\"__main__\"<\/span>: \r\napp.run(port=8081)<\/pre>\n

            \u670d\u52a1A\u54cd\u5e94format\u8bf7\u6c42\uff0c\u8c03\u7528tracer.extract\u4ecehttp headers\u4e2d\u63d0\u53d6\u4fe1\u606f\uff0c\u6784\u5efaspanContext\u3002<\/p>\n

            \u670d\u52a1B\u4ee3\u7801<\/strong><\/strong><\/div>\n
            from<\/span> flask\u00a0import\u00a0Flask\u00a0\r\nfrom<\/span> flask\u00a0import\u00a0request\u00a0\r\nfrom<\/span> lib.tracing\u00a0import\u00a0init_tracer\u00a0\r\nfrom<\/span> opentracing.ext\u00a0import\u00a0tags\u00a0\r\nfrom<\/span> opentracing.propagation\u00a0import\u00a0Format\u00a0\u00a0\r\napp = Flask(__name__)\u00a0\r\ntracer\u00a0=\u00a0init_tracer('publisher'<\/span>) \r\n@app.route(\"\/publish\"<\/span>) \r\ndef publish():\u00a0\r\nspan_ctx = tracer.extract(Format.HTTP_HEADERS, request.headers)\u00a0\r\nspan_tags = {tags.SPAN_KIND: tags.SPAN_KIND_RPC_SERVER}\u00a0\r\nwith<\/span>\u00a0tracer.start_active_span('publish'<\/span>, child_of=span_ctx, tags=span_tags):\u00a0\r\nhello_str = request.args.get('helloStr'<\/span>) \r\nprint(hello_str) \r\nreturn<\/span>\u00a0'published'<\/span> \u200b\u00a0\r\nif\u00a0__name__\u00a0==\u00a0\"__main__\"<\/span>: \r\napp.run(port=8082)<\/pre>\n

            \u670d\u52a1B\u548cA\u7c7b\u4f3c\u3002<\/p>\n

            \u4e4b\u540e\u5728\u652f\u6301\u5206\u5e03\u5f0f\u8ffd\u8e2a\u7684\u8f6f\u4ef6UI\u4e0a(\u4e0b\u56fe\u662fJaeger UI)\uff0c\u5c31\u53ef\u4ee5\u770b\u5230\u7c7b\u4f3c\u4e0b\u56fe\u7684\u8ffd\u8e2a\u4fe1\u606f\u3002\u6211\u4eec\u53ef\u4ee5\u770b\u5230\u670d\u52a1hello-word\u548c\u4e09\u4e2a\u64cd\u4f5csay-hello\/format\/println\u7684\u8be6\u7ec6\u8ffd\u8e2a\u4fe1\u606f\u3002<\/p>\n

            \"\"<\/center>\u5f53\u524d\u6709\u5f88\u591a\u5206\u5e03\u5f0f\u8ffd\u8e2a\u8f6f\u4ef6\u90fd\u63d0\u4f9b\u4e86OpenTracing\u7684\u652f\u6301\uff0c\u5305\u62ec\uff1aJaeger\uff0cLightStep\uff0cInstanna\uff0cApache SkyWalking\uff0cinspectIT\uff0cstagemonitor\uff0cDatadog\uff0cWavefront\uff0cElastic APM\u7b49\u7b49\u3002\u5176\u4e2d\u4f5c\u4e3a\u5f00\u6e90\u8f6f\u4ef6\u7684Zipkin(http:\/\/1t.click\/6Ec)\u548cJaeger(http:\/\/1t.click\/6DY)\u6700\u4e3a\u6d41\u884c\u3002<\/p>\n

            Zipkin<\/strong><\/p>\n

            Zipkin(http:\/\/1t.click\/6Ec)\u662fTwitter\u57fa\u4e8eDapper\u5f00\u53d1\u7684\u5206\u5e03\u5f0f\u8ffd\u8e2a\u7cfb\u7edf\u3002\u5b83\u7684\u8bbe\u8ba1\u67b6\u6784\u5982\u4e0b\u56fe\uff1a<\/p>\n

            \"\"<\/center><\/p>\n
              \n
            • \u84dd\u8272\u5b9e\u4f53\u662fZipkin\u8981\u8ffd\u8e2a\u7684\u76ee\u6807\u7ec4\u4ef6\uff0cNon-Intrumented Server\u8868\u793a\u4e0d\u76f4\u63a5\u8c03\u7528Tracing API\u7684\u5fae\u670d\u52a1\u3002\u901a\u8fc7Intrumented Client\u4eceNon-Intrumented Server\u4e2d\u6536\u96c6\u4fe1\u606f\u5e76\u53d1\u9001\u7ed9Zipkin\u7684\u6536\u96c6\u5668Collector\u3002Intrumented Server \u76f4\u63a5\u8c03\u7528Tracing API\uff0c\u53d1\u9001\u6570\u636e\u5230Zipkin\u7684\u6536\u96c6\u5668\u3002<\/li>\n
            • Transport\u662f\u4f20\u8f93\u901a\u9053\uff0c\u53ef\u4ee5\u901a\u8fc7HTTP\u76f4\u63a5\u53d1\u9001\u5230Zipkin\u6216\u8005\u901a\u8fc7\u6d88\u606f\/\u4e8b\u4ef6\u961f\u5217\u7684\u65b9\u5f0f\u3002<\/li>\n
            • Zipkin\u672c\u8eab\u662f\u4e00\u4e2aJava\u5e94\u7528\uff0c\u5305\u542b\u4e86\uff1a\u6536\u96c6\u5668Collector\u8d1f\u8d23\u6570\u636e\u91c7\u96c6\uff0c\u5bf9\u5916\u63d0\u4f9b\u6570\u636e\u63a5\u53e3;\u5b58\u50a8;API\u548cUI\u3002<\/li>\n<\/ul>\n

              Zipkin\u7684\u7528\u6237\u754c\u9762\u50cf\u8fd9\u4e2a\u6837\u5b50\uff1a<\/p>\n

              \"\"\u00a0<\/center>Zipkin\u5b98\u65b9\u652f\u6301\u4ee5\u4e0b\u51e0\u79cd\u8bed\u8a00\u7684\u5ba2\u6237\u7aef\uff1aC#\uff0cGo\uff0cJava\uff0cJavaScript\uff0cRuby\uff0cScala\uff0cPHP\u3002\u5f00\u6e90\u793e\u533a\u4e5f\u6709\u5176\u5b83\u8bed\u8a00\u7684\u652f\u6301\u3002<\/p>\n

              Zipkin\u53d1\u5c55\u5230\u73b0\u5728\u6709\u5feb4\u5e74\u7684\u65f6\u95f4\uff0c\u662f\u4e00\u4e2a\u76f8\u5bf9\u6210\u719f\u7684\u9879\u76ee\u3002<\/p>\n

              Jaeger<\/strong><\/strong><\/div>\n

              Jaeger(http:\/\/1t.click\/6DY)\u6700\u65e9\u662f\u7531Uber\u5f00\u53d1\u7684\u5206\u5e03\u5f0f\u8ffd\u8e2a\u7cfb\u7edf\uff0c\u540c\u6837\u57fa\u4e8eDapper\u7684\u8bbe\u8ba1\u7406\u5ff5\u3002\u73b0\u5728Jaeger\u662fCNCF(Cloud Native Computing Foundation)\u7684\u4e00\u4e2a\u9879\u76ee\u3002\u5982\u679c\u4f60\u5bf9CNCF\u8fd9\u4e2a\u7ec4\u7ec7\u6709\u6240\u4e86\u89e3\uff0c\u90a3\u4e48\u4f60\u53ef\u4ee5\u63a8\u6d4b\u51fa\u8fd9\u4e2a\u9879\u76ee\u5e94\u8be5\u548cKubernetes\u6709\u975e\u5e38\u7d27\u5bc6\u7684\u96c6\u6210\u3002<\/p>\n

              Jaeger\u57fa\u4e8e\u5206\u5e03\u5f0f\u7684\u67b6\u6784\u8bbe\u8ba1\uff0c\u4e3b\u8981\u5305\u542b\u4ee5\u4e0b\u51e0\u4e2a\u7ec4\u4ef6\uff1a<\/p>\n

                \n
              1. Jaeger Client\uff0c\u8d1f\u8d23\u5728\u5ba2\u6237\u7aef\u6536\u96c6\u8ddf\u8e2a\u4fe1\u606f\u3002<\/li>\n
              2. Jaeger Agent\uff0c\u8d1f\u8d23\u548c\u5ba2\u6237\u7aef\u901a\u4fe1\uff0c\u628a\u6536\u96c6\u5230\u7684\u8ffd\u8e2a\u4fe1\u606f\u4e0a\u62a5\u4e2a\u6536\u96c6\u5668 Jaeger Collector<\/li>\n
              3. Jaeger Colletor\u628a\u6536\u96c6\u5230\u7684\u6570\u636e\u5b58\u5165\u6570\u636e\u5e93\u6216\u8005\u5176\u5b83\u5b58\u50a8\u5668<\/li>\n
              4. Jaeger Query \u8d1f\u8d23\u5bf9\u8ffd\u8e2a\u6570\u636e\u8fdb\u884c\u67e5\u8be2<\/li>\n
              5. Jaeger UI\u8d1f\u8d23\u7528\u6237\u4ea4\u4e92<\/li>\n<\/ol>\n

                \u8fd9\u4e2a\u67b6\u6784\u5f88\u50cfELK\uff0cCollector\u4e4b\u524d\u7c7b\u4f3cLogstash\u8d1f\u8d23\u91c7\u96c6\u6570\u636e\uff0cQuery\u7c7b\u4f3cElastic\u8d1f\u8d23\u641c\u7d22\uff0c\u800cUI\u7c7b\u4f3cKibana\u8d1f\u8d23\u7528\u6237\u754c\u9762\u548c\u4ea4\u4e92\u3002\u8fd9\u6837\u7684\u5206\u5e03\u5f0f\u67b6\u6784\u4f7f\u5f97Jaeger\u7684\u6269\u5c55\u6027\u66f4\u597d\uff0c\u53ef\u4ee5\u6839\u636e\u9700\u8981\uff0c\u6784\u5efa\u4e0d\u540c\u7684\u90e8\u7f72\u3002<\/p>\n

                Jaeger\u4f5c\u4e3a\u5206\u5e03\u5f0f\u8ffd\u8e2a\u7684\u540e\u8d77\u4e4b\u79c0\uff0c\u968f\u7740\u4e91\u539f\u751f\u548cK8s\u7684\u5e7f\u6cdb\u91c7\u7528\uff0c\u6b63\u53d8\u5f97\u8d8a\u6765\u8d8a\u6d41\u884c\u3002\u5229\u7528\u5b98\u65b9\u7ed9\u51fa\u7684K8s\u90e8\u7f72\u6a21\u7248(http:\/\/1t.click\/6DU)\uff0c\u7528\u6237\u53ef\u4ee5\u5feb\u901f\u7684\u5728\u81ea\u5df1\u7684k8s\u96c6\u7fa4\u4e0a\u90e8\u7f72Jaeger\u3002<\/p>\n

                4.\u5206\u5e03\u5f0f\u8ddf\u8e2a\u7cfb\u7edf\u2014\u2014\u4ea7\u54c1\u5bf9\u6bd4<\/strong><\/strong><\/div>\n

                \u5f53\u7136\u9664\u4e86\u652f\u6301OpenTracing\u6807\u51c6\u7684\u4ea7\u54c1\u4e4b\u5916\uff0c\u8fd8\u6709\u5176\u5b83\u7684\u4e00\u4e9b\u5206\u5e03\u5f0f\u8ffd\u8e2a\u4ea7\u54c1\u3002\u8fd9\u91cc\u5f15\u7528\u4e00\u4e9b\u5176\u5b83\u535a\u4e3b\u7684\u5206\u6790\uff0c\u7ed9\u5927\u5bb6\u4e00\u4e9b\u53c2\u8003\uff1a<\/p>\n

                  \n
                • \u8c03\u7528\u94fe\u9009\u578b\u4e4bZipkin\uff0cPinpoint\uff0cSkyWalking\uff0cCAT(http:\/\/1t.click\/6tY)<\/li>\n
                • \u5206\u5e03\u5f0f\u8c03\u7528\u94fe\u8c03\u7814(pinpoint,skywalking,jaeger,zipkin\u7b49\u5bf9\u6bd4)(http:\/\/1t.click\/6DK)<\/li>\n
                • \u5206\u5e03\u5f0f\u8ddf\u8e2a\u7cfb\u7edf\u2014\u2014\u4ea7\u54c1\u5bf9\u6bd4(http:\/\/1t.click\/6ug)<\/li>\n<\/ul>\n
                  5.\u603b\u7ed3<\/strong><\/strong><\/div>\n

                  \u5728\u5fae\u670d\u52a1\u5927\u884c\u5176\u9053\uff0c\u4e91\u539f\u751f\u6210\u4e3a\u67b6\u6784\u8bbe\u8ba1\u7684\u4e3b\u6d41\u7684\u60c5\u51b5\u4e0b\uff0c\u5fae\u670d\u52a1\u7cfb\u7edf\u76d1\u63a7\uff0c\u5305\u542b\u65e5\u5fd7\uff0c\u6307\u6807\u548c\u8ffd\u8e2a\u6210\u4e3a\u4e86\u7cfb\u7edf\u5de5\u7a0b\u7684\u91cd\u4e2d\u4e4b\u91cd\u3002OpenTracing\u57fa\u4e8eDapper\u7684\u5206\u5e03\u5f0f\u8ffd\u8e2a\u8bbe\u8ba1\u7406\u5ff5\uff0c\u5b9a\u4e49\u4e86\u5206\u5e03\u5f0f\u8ffd\u8e2a\u7684\u5b9e\u73b0\u6807\u51c6\u3002\u5728\u5f00\u6e90\u9879\u76ee\u4e2d\uff0cZipkin\u548cJaeger\u662f\u76f8\u5bf9\u4f18\u79c0\u7684\u9009\u62e9\u3002\u5c24\u5176\u662fJaeger\uff0c\u7531\u4e8e\u5bf9\u4e91\u539f\u751f\u6846\u67b6\u7684\u826f\u597d\u96c6\u6210\uff0c\u662f\u6784\u5efa\u5fae\u670d\u52a1\u8ffd\u8e2a\u7cfb\u7edf\u7684\u5fc5\u5907\u826f\u5668\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"

                  \u73b0\u5728\u8d8a\u6765\u8d8a\u591a\u7684\u5e94\u7528\u8fc1\u79fb\u5230\u57fa\u4e8e\u5fae\u670d\u52a1\u7684\u4e91\u539f\u751f\u7684\u67b6\u6784\u4e4b\u4e0a\uff0c\u5fae\u670d\u52a1\u67b6\u6784\u5f88\u5f3a\u5927\uff0c\u4f46\u662f\u540c\u65f6\u4e5f\u5e26\u6765\u4e86\u5f88\u591a\u7684\u6311\u6218\uff0c\u5c24\u5176\u662f\u5982\u4f55 […]<\/p>\n","protected":false},"author":1898,"featured_media":153368,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[427],"class_list":["post-153315","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-thread","tag-427"],"acf":[],"_links":{"self":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/153315","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/users\/1898"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=153315"}],"version-history":[{"count":6,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/153315\/revisions"}],"predecessor-version":[{"id":154386,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/153315\/revisions\/154386"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/153368"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=153315"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=153315"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=153315"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}