{"id":9224,"date":"2023-02-02T12:42:11","date_gmt":"2023-02-02T04:42:11","guid":{"rendered":"http:\/\/123.57.164.21\/?p=9224"},"modified":"2023-02-02T12:42:11","modified_gmt":"2023-02-02T04:42:11","slug":"opentracing-java-library%e6%95%99%e7%a8%8b1-trace%e5%92%8cspan%e5%85%a5%e9%97%a8","status":"publish","type":"post","link":"https:\/\/92it.top\/?p=9224","title":{"rendered":"OpenTracing Java Library\u6559\u7a0b(1)\u2014\u2014trace\u548cspan\u5165\u95e8"},"content":{"rendered":"\n<p><strong>\u76ee\u6807<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<p>\u5b66\u4e60\u5982\u4f55\uff1a<\/p>\n\n\n\n<ul><li>\u5b9e\u4f8b\u5316\u4e00\u4e2aTracer<\/li><li>\u521b\u5efa\u4e00\u4e2a\u7b80\u5355\u7684\u94fe\u8def<\/li><li>\u7ed9\u94fe\u8def\u589e\u52a0\u4e00\u4e9b\u6ce8\u89e3\uff08annotation\uff09\uff1a\u5373\u589e\u52a0Tag\u548cLog\u3002<\/li><\/ul>\n\n\n\n<p><strong>\u5f00\u53d1\u6b65\u9aa4<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<p>\u521b\u5efa\u4e00\u4e2a\u7b80\u5355\u7684Hello-World\u7a0b\u5e8f<\/p>\n\n\n\n<p>\u521b\u5efa\u4e00\u4e2a\u7b80\u5355\u7684\u6253\u5370\u7a0b\u5e8f\uff1a\u63a5\u53d7\u4e00\u4e2a\u53c2\u6570\uff0c\u8f93\u51fa&#8221;Hello, {arg}!&#8221;\u3002\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">package lesson01.exercise;\n\npublic class Hello {\n\n    private void sayHello(String helloTo) {\n        String helloStr = String.format(\"Hello, %s!\", helloTo);\n        System.out.println(helloStr);\n    }\n\n    public static void main(String[] args) {\n        if (args.length != 1) {\n            throw new IllegalArgumentException(\"Expecting one argument\");\n        }\n        String helloTo = args[0];\n        new Hello().sayHello(helloTo);\n    }\n}<\/pre>\n\n\n\n<p>\u8fd0\u884c\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">$ .\/run.sh lesson01.exercise.Hello Bryan\nHello, Bryan!<\/pre>\n\n\n\n<p><strong>\u521b\u5efa\u4e00\u4e2atrace<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<p><strong>\u4e00\u4e2atrace\u662f\u7531\u82e5\u5e72span\u7ec4\u6210\u7684\u6709\u5411\u65e0\u73af\u56fe<\/strong>\u3002\u4e00\u4e2aspan\u4ee3\u8868\u5e94\u7528\u4e2d\u7684\u4e00\u4e2a\u903b\u8f91\u64cd\u4f5c\uff0c\u6bcf\u4e2aspan\u81f3\u5c11\u5305\u542b\u4e09\u4e2a\u5c5e\u6027\uff1a<strong>\u64cd\u4f5c\u540d(an operation time)\u3001\u5f00\u59cb\u65f6\u95f4(start time)\u3001\u7ed3\u675f\u65f6\u95f4(finish time)\u3002<\/strong><\/p>\n\n\n\n<p>\u4e0b\u9762\u6211\u4eec\u4f7f\u7528\u4e00\u4e2a<code>io.opentracing.Tracer<\/code>\u5b9e\u4f8b\u521b\u5efa\u7531\u4e00\u4e2aspan\u7ec4\u6210\u7684trace\uff0c\u53ef\u4ee5\u4f7f\u7528<code>io.opentracing.util.GlobalTracer.get()<\/code>\u521b\u5efa\u4e00\u4e2a\u5168\u5c40\u7684Tracer\u5b9e\u4f8b\u3002\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">import io.opentracing.Span;\nimport io.opentracing.Tracer;\nimport io.opentracing.util.GlobalTracer;\n\npublic class Hello {\n\n    private final Tracer tracer;\n\n    private Hello(Tracer tracer) {\n        this.tracer = tracer;\n    }\n\n    private void sayHello(String helloTo) {\n        Span span = tracer.buildSpan(\"say-hello\").start();\n\n        String helloStr = String.format(\"Hello, %s!\", helloTo);\n        System.out.println(helloStr);\n\n        span.finish();\n    }\n\n    public static void main(String[] args) {\n        if (args.length != 1) {\n            throw new IllegalArgumentException(\"Expecting one argument\");\n        }\n        String helloTo = args[0];\n        new Hello(GlobalTracer.get()).sayHello(helloTo);\n    }\n}<\/pre>\n\n\n\n<p>\u8fd9\u91cc\u6211\u4eec\u4f7f\u7528\u4e86OpenTracing API\u7684\u4e00\u4e9b\u57fa\u672c\u7279\u6027\uff1a<\/p>\n\n\n\n<ul><li>\u8c03\u7528<code>tracer<\/code>\u5b9e\u4f8b\u7684<code>buildSpan()<\/code>\u65b9\u6cd5\u521b\u5efa\u4e00\u4e2aspan<\/li><li><code>buildSpan()<\/code>\u65b9\u6cd5\u7684\u53c2\u6570\u5c31\u662fspan\u7684<strong>\u64cd\u4f5c\u540d<\/strong><\/li><li>\u8c03\u7528<code>start()<\/code>\u65b9\u6cd5\u771f\u6b63\u521b\u5efa\u51fa\u4e00\u4e2aspan<\/li><li>\u901a\u8fc7\u8c03\u7528<code>finish()<\/code>\u65b9\u6cd5\u7ed3\u675f\u4e00\u4e2aspan<\/li><li>span\u7684\u5f00\u59cb\u65f6\u95f4\u548c\u7ed3\u675f\u65f6\u95f4\u7531\u5177\u4f53\u7684tracer\u5b9e\u73b0\u81ea\u52a8\u751f\u6210\uff08\u83b7\u53d6\u521b\u5efa\u548c\u7ed3\u675fspan\u65f6\u7684\u7cfb\u7edf\u65f6\u95f4\u6233\uff09<\/li><\/ul>\n\n\n\n<p>\u6b64\u65f6\uff0c\u6211\u4eec\u8fd0\u884c\u7a0b\u5e8f\u5e76\u4e0d\u4f1a\u548c\u539f\u6765\u7684\u7a0b\u5e8f\u6709\u4ec0\u4e48\u533a\u522b\uff0c\u4e5f\u4e0d\u4f1a\u4ea7\u751f\u94fe\u8def\u6570\u636e\u3002\u56e0\u4e3aOpenTracing\u53ea\u63d0\u4f9b\u4e86SDK\uff0c\u5e76\u6ca1\u6709\u63d0\u4f9b\u5177\u4f53\u7684\u94fe\u8def\u5b9e\u73b0\uff0c\u6240\u4ee5\u8981\u4ea7\u751f\u771f\u6b63\u7684\u94fe\u8def\u6570\u636e\uff0c\u9700\u8981\u501f\u52a9\u5177\u4f53\u7684\u94fe\u8def\u5b9e\u73b0\u3002<\/p>\n\n\n\n<p><strong>\u90e8\u7f72Jaeger\uff08\u8865\u5145\u6bb5\u843d\uff0c\u539f\u6587\u6ca1\u6709\uff09<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<p>\u8fd9\u91cc\u6211\u4eec\u9009\u62e9Uber\u5f00\u6e90\u7684Jaeger\uff08\u53d1\u97f3\u4e3a\u02c8y\u0101-g\u0259r \uff09\uff0c\u56e0\u4e3a\u5b83\u5bf9OpenTracing\u652f\u6301\u7684\u6bd4\u8f83\u597d\uff0c\u800c\u4e14\u90e8\u7f72\u4f7f\u7528\u4e5f\u975e\u5e38\u7b80\u5355\u3002\u53e6\u5916Jaeger\u7684\u4f5c\u8005\u5c31\u662fYurishkuro\u3002\u8fd9\u91cc\u5c31\u4e0d\u4ecb\u7ecdJaeger\u7684\u7ec6\u8282\u4e86\uff0c\u6709\u5174\u8da3\u7684\u53ef\u4ee5\u53bb\u5b98\u7f51\u4e86\u89e3\uff1a<a href=\"https:\/\/www.jaegertracing.io\/\">Jaeger\u5b98\u7f51<\/a>\u3002<\/p>\n\n\n\n<p>Jaeger\u90e8\u7f72\u975e\u5e38\u7b80\u5355\uff0c\u4ece\u8fd9\u91cc<a href=\"https:\/\/www.jaegertracing.io\/download\/\">\u4e0b\u8f7d<\/a>\u5b89\u88c5\u5305\u6216\u8005\u4e0b\u8f7ddocker\u955c\u50cf\u3002\u8fd9\u91cc\u6211\u4e0b\u8f7d\u7684macOS\u7684\u5b89\u88c5\u5305\uff0c\u89e3\u538b\u540e\u53ef\u4ee5\u770b\u5230\u5982\u4e0b\u6587\u4ef6\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">example-hotrod\njaeger-agent      \njaeger-all-in-one \njaeger-collector  \njaeger-ingester   \njaeger-queryexample-hotrod<\/pre>\n\n\n\n<p>\u76f4\u63a5\u8fd0\u884c<code>.\/jaeger-all-in-one<\/code>\u4fbf\u53ef\u4ee5\u542f\u52a8\u4e00\u4e2a\u5b8c\u6574\u7684Jaeger\u3002\u6b64\u65f6\u8bbf\u95ee<a href=\"http:\/\/localhost\">http:\/\/localhost<\/a>:16686\/\u5373\u53ef\u67e5\u770bJaeger\u7684UI\uff1a<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/123.57.164.21\/wp-content\/uploads\/2023\/02\/image-21-1024x546.png\" alt=\"\" class=\"wp-image-9225\" width=\"577\" height=\"307\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2023\/02\/image-21-1024x546.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2023\/02\/image-21-300x160.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2023\/02\/image-21-768x409.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2023\/02\/image-21-830x442.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2023\/02\/image-21-230x123.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2023\/02\/image-21-350x187.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2023\/02\/image-21-480x256.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2023\/02\/image-21.png 1242w\" sizes=\"(max-width: 577px) 100vw, 577px\" \/><\/figure><\/div>\n\n\n\n<p>\u8fd9\u6837\uff0c\u4e00\u4e2aOpenTracing\u7684\u5b9e\u73b0\uff08Jaeger\uff09\u5c31\u6709\u4e86\u3002\u63a5\u4e0b\u6765\u6211\u4eec\u770b\u5982\u4f55\u5728\u4ee3\u7801\u4e2d\u96c6\u6210\u3002<\/p>\n\n\n\n<p id=\"d13\"><strong>\u96c6\u6210Jaeger<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<p>\u5728pom.xml\u4e2d\u5f15\u5165Jaeger\u7684\u4f9d\u8d56\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;dependency>\n    &lt;groupId>io.jaegertracing&lt;\/groupId>\n    &lt;artifactId>jaeger-client&lt;\/artifactId>\n    &lt;version>0.32.0&lt;\/version>\n&lt;\/dependency><\/pre>\n\n\n\n<p>\u7136\u540e\u5199\u4e00\u4e2a\u521b\u5efatracer\u7684\u51fd\u6570\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">import io.jaegertracing.Configuration;\nimport io.jaegertracing.Configuration.ReporterConfiguration;\nimport io.jaegertracing.Configuration.SamplerConfiguration;\nimport io.jaegertracing.internal.JaegerTracer;\n\npublic static JaegerTracer initTracer(String service) {\n    SamplerConfiguration samplerConfig = SamplerConfiguration.fromEnv().withType(\"const\").withParam(1);\n    ReporterConfiguration reporterConfig = ReporterConfiguration.fromEnv().withLogSpans(true);\n    Configuration config = new Configuration(service).withSampler(samplerConfig).withReporter(reporterConfig);\n    return config.getTracer();\n}<\/pre>\n\n\n\n<p>\u6700\u540e\uff0c\u4fee\u6539\u539f\u6765\u4ee3\u7801\u4e2d\u7684main\u51fd\u6570\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">Tracer tracer = initTracer(\"hello-world\");\nnew Hello(tracer).sayHello(helloTo);<\/pre>\n\n\n\n<p>\u6ce8\u610f\u6211\u4eec\u7ed9<code>initTracer()<\/code>\u65b9\u6cd5\u4f20\u5165\u4e86\u4e00\u4e2a\u53c2\u6570hello-world\uff0c\u8fd9\u4e2a\u662f\u670d\u52a1\u540d\u3002\u8be5\u670d\u52a1\u91cc\u9762\u4ea7\u751f\u7684\u6240\u6709span\u516c\u7528\u8fd9\u4e2a\u670d\u52a1\u540d\uff0c\u4e00\u822c\u670d\u52a1\u540d\u4f1a\u7528\u6765\u505a\u8fc7\u6ee4\u548c\u805a\u5408\u3002<\/p>\n\n\n\n<p>\u73b0\u5728\u8fd0\u884c\u4ee3\u7801\uff0c\u53ef\u4ee5\u770b\u5230\u65e5\u5fd7\u4e2d\u6709\u8f93\u51fa\u4ea7\u751f\u7684span\u4fe1\u606f\uff0c\u800c\u4e14\u4e5f\u80fd\u770b\u5230Tracer\u5b9e\u4f8b\u7684\u4e00\u4e9b\u4fe1\u606f\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">19:07:10.645 [main] DEBUG io.jaegertracing.thrift.internal.senders.ThriftSenderFactory - Using the UDP Sender to send spans to the agent.\n19:07:10.729 [main] DEBUG io.jaegertracing.internal.senders.SenderResolver - Using sender UdpSender()\n# tracer\u5b9e\u4f8b\u4fe1\u606f\n19:07:10.776 [main] INFO io.jaegertracing.Configuration - Initialized tracer=JaegerTracer(version=Java-1.1.0, serviceName=hello-world, reporter=CompositeReporter(reporters=[RemoteReporter(sender=UdpSender(), closeEnqueueTimeout=1000), LoggingReporter(logger=Logger[io.jaegertracing.internal.reporters.LoggingReporter])]), sampler=ConstSampler(decision=true, tags={sampler.type=const, sampler.param=true}), tags={hostname=NYC-MacBook, jaeger.version=Java-1.1.0, ip=192.168.0.109}, zipkinSharedRpcSpan=false, expandExceptionLogs=false, useTraceId128Bit=false)\nHello, Bryan!\n# span\u4fe1\u606f\n19:07:10.805 [main] INFO io.jaegertracing.internal.reporters.LoggingReporter - Span reported: a86d76defe28d413:a86d76defe28d413:0:1 - say-hello<\/pre>\n\n\n\n<p>\u5f53\u7136\u4e5f\u53ef\u4ee5\u4ee5\u8c03\u8bd5\u6a21\u5f0f\u542f\u52a8\uff0c\u89c2\u5bdf\u66f4\u591a\u7ec6\u8282\u3002<\/p>\n\n\n\n<p>\u8fd9\u4e2a\u65f6\u5019\uff0c\u6211\u4eec\u6253\u5f00Jaeger\u7684UI\uff0c\u5de6\u4fa7\u7684Service\u9009\u62e9\u201chello-world\u201d\uff0c\u7136\u540e\u70b9\u51fb\u6700\u4e0b\u9762\u7684\u201cFind Traces\u201d\uff0c\u5c31\u53ef\u4ee5\u67e5\u5230\u521a\u624d\u8fd9\u6b21\u7a0b\u5e8f\u8fd0\u884c\u4ea7\u751f\u7684Trace\u4fe1\u606f\u4e86\uff1a<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/123.57.164.21\/wp-content\/uploads\/2023\/02\/image-22-1024x555.png\" alt=\"\" class=\"wp-image-9226\" width=\"566\" height=\"307\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2023\/02\/image-22-1024x555.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2023\/02\/image-22-300x163.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2023\/02\/image-22-768x416.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2023\/02\/image-22-830x450.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2023\/02\/image-22-230x125.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2023\/02\/image-22-350x190.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2023\/02\/image-22-480x260.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2023\/02\/image-22.png 1258w\" sizes=\"(max-width: 566px) 100vw, 566px\" \/><\/figure><\/div>\n\n\n\n<p>\u70b9\u51fb\u94fe\u8def\u8be6\u60c5\u8fdb\u53bb\u540e\uff0c\u518d\u6b21\u70b9\u51fb\u64cd\u4f5c\u540d\uff0c\u53ef\u4ee5\u67e5\u770b\u4e00\u4e9b\u57fa\u672c\u4fe1\u606f\uff0cJaeger\u9ed8\u8ba4\u5df2\u7ecf\u52a0\u4e86\u4e00\u4e9b\u57fa\u672c\u7684\u4fe1\u606f\u3002<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/123.57.164.21\/wp-content\/uploads\/2023\/02\/image-23-1024x500.png\" alt=\"\" class=\"wp-image-9227\" width=\"567\" height=\"277\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2023\/02\/image-23-1024x500.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2023\/02\/image-23-300x146.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2023\/02\/image-23-768x375.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2023\/02\/image-23-830x405.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2023\/02\/image-23-230x112.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2023\/02\/image-23-350x171.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2023\/02\/image-23-480x234.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2023\/02\/image-23.png 1238w\" sizes=\"(max-width: 567px) 100vw, 567px\" \/><\/figure><\/div>\n\n\n\n<p>\u4e0b\u9762\u6211\u4eec\u6765\u770b\u5982\u4f55\u52a0\u4e00\u4e9b\u81ea\u5b9a\u4e49\u7684\u4fe1\u606f\u3002<\/p>\n\n\n\n<p><strong>\u589e\u52a0Tags\u548cLogs<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<p>OpenTracing\u89c4\u5b9a\u4e86\u53ef\u4ee5\u7ed9Span\u589e\u52a0\u4e09\u79cd\u7c7b\u578b\u7684\u6ce8\u89e3\u4fe1\u606f\uff1a<\/p>\n\n\n\n<ul><li><strong>Tags<\/strong>\uff1akey-value\u683c\u5f0f\u7684\u6570\u636e\uff0ckey\u548cvalue\u5b8c\u5168\u7531\u7528\u6237\u81ea\u5b9a\u4e49\u3002\u9700\u8981\u6ce8\u610f\u7684\u662fTags\u589e\u52a0\u7684\u4fe1\u606f\u5e94\u8be5\u662f\u5c5e\u4e8e\u63cf\u8ff0\u6574\u4e2aspan\u7684\uff0c\u4e5f\u5c31\u662f\u5b83\u662fspan\u7684\u4e00\u4e2a\u9759\u6001\u5c5e\u6027\uff0c\u8bb0\u5f55\u7684\u4fe1\u606f\u9002\u7528\u4e8espan\u4ece\u521b\u5efa\u5230\u5b8c\u6210\u7684\u4efb\u4f55\u65f6\u523b\u3002\u518d\u8bf4\u76f4\u767d\u70b9\u5c31\u662f\u8bb0\u5f55\u548c\u65f6\u95f4\u70b9\u65e0\u5173\u7684\u4fe1\u606f\uff0c\u8fd9\u4e2a\u4e3b\u8981\u662f\u548c\u4e0b\u9762\u7684Logs\u4f5c\u533a\u5206\u3002<\/li><li><strong>Logs<\/strong>\uff1a\u548cTags\u7c7b\u4f3c\uff0c\u4e5f\u662fkey-value\u683c\u5f0f\u7684\u6570\u636e\uff0c\u533a\u522b\u5728\u4e8eLogs\u7684\u4fe1\u606f\u90fd\u4f1a\u5e26\u4e00\u4e2a\u65f6\u95f4\u6233\u5c5e\u6027\uff0c\u8bb0\u5f55\u8fd9\u6761\u5c5e\u6027\u4ea7\u751f\u7684\u65f6\u95f4\u6233\uff0c\u6240\u4ee5\u6bd4\u8f83\u9002\u5408\u8bb0\u5f55\u65e5\u5fd7\u3001\u5f02\u5e38\u6808\u7b49\u4e00\u4e9b\u548c\u65f6\u95f4\u76f8\u5173\u7684\u4fe1\u606f\u3002<\/li><li><strong>Baggage Items<\/strong>\uff1a\u8fd9\u4e2a\u4e3b\u8981\u662f\u7528\u4e8e\u8de8\u8fdb\u7a0b\u5168\u5c40\u4f20\u8f93\u6570\u636e\uff0c\u540e\u9762\u7684lesson04\u4e13\u95e8\u6f14\u793a\u8fd9\u4e2a\u7279\u6027\uff0c\u8fd9\u91cc\u5148\u4e0d\u5c55\u5f00\u4ecb\u7ecd\u4e86\u3002<\/li><\/ul>\n\n\n\n<p>Tags\u548cLogs\u7684\u8bb0\u5f55\u975e\u5e38\u7684\u7b80\u5355\u548c\u65b9\u4fbf\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">private void sayHello(String helloTo) {\n    Span span = tracer.buildSpan(\"say-hello\").start();\n    \/\/ \u589e\u52a0Tags\u4fe1\u606f\n    span.setTag(\"hello-to\", helloTo);\n\n    String helloStr = String.format(\"Hello, %s!\", helloTo);\n    \/\/ \u589e\u52a0Logs\u4fe1\u606f\n    span.log(ImmutableMap.of(\"event\", \"string-format\", \"value\", helloStr));\n\n    System.out.println(helloStr);\n    \/\/ \u589e\u52a0Logs\u4fe1\u606f\n    span.log(ImmutableMap.of(\"event\", \"println\"));\n\n    span.finish();\n}<\/pre>\n\n\n\n<p>\u6ce8\u610f\u8fd9\u91cc\u4f7f\u7528\u4e86Guava&#8217;s <code>ImmutableMap.of()<\/code>\u6765\u6784\u9020\u4e00\u4e2aMap\u3002<\/p>\n\n\n\n<p>\u518d\u6b21\u8fd0\u884c\u7a0b\u5e8f\uff0c\u540c\u6837\u4f1a\u4ea7\u751f\u4e00\u4e2aspan\uff0c\u4f46\u8fd9\u6b21span\u4f1a\u591a\u4e86\u4e00\u4e2aTag\u548cLog\u4fe1\u606f\uff08Jaeger\u9ed8\u8ba4\u5df2\u7ecf\u52a0\u4e86\u4e00\u4e9b\u5185\u90e8\u7684tag\u6570\u636e\uff09\uff1a<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/123.57.164.21\/wp-content\/uploads\/2023\/02\/image-24-1024x576.png\" alt=\"\" class=\"wp-image-9228\" width=\"566\" height=\"317\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2023\/02\/image-24-1024x576.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2023\/02\/image-24-300x169.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2023\/02\/image-24-768x432.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2023\/02\/image-24-1536x864.png 1536w, https:\/\/92it.top\/wp-content\/uploads\/2023\/02\/image-24-2048x1152.png 2048w, https:\/\/92it.top\/wp-content\/uploads\/2023\/02\/image-24-830x467.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2023\/02\/image-24-230x129.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2023\/02\/image-24-350x197.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2023\/02\/image-24-480x270.png 480w\" sizes=\"(max-width: 566px) 100vw, 566px\" \/><\/figure><\/div>\n\n\n\n<p>\u4ece\u56fe\u4e2d\u53ef\u4ee5\u770b\u5230\u4ee3\u7801\u4e2d\u52a0\u7684Tags\u4fe1\u606f\u548cLogs\u4fe1\u606f\uff0c\u800c\u4e14Logs\u4fe1\u606f\u662f\u5e26\u4e86\u65f6\u95f4\u4e86\uff08\u8fd9\u91cc\u5c55\u793a\u7684\u662f\u4ecespan\u5f00\u59cb\u65f6\u95f4\u7ecf\u8fc7\u7684\u6beb\u79d2\u6570\uff09\u3002\u5173\u4e8eTags\u548cLogs\u7684\u89c4\u8303\uff0cOpenTracing\u505a\u4e86\u4e00\u4e9b\u5f15\u5bfc\u89c4\u8303\uff0c\u53ef\u4ee5\u53c2\u8003\uff1a<a href=\"https:\/\/github.com\/opentracing\/specification\/blob\/master\/semantic_conventions.md\">semantic_conventions<\/a>.<\/p>\n\n\n\n<p><strong>\u603b\u7ed3<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<p>\u672c\u6587\u4e3b\u8981\u5c55\u793a\u4e86\u5982\u4f55\u521b\u5efa\u4e00\u4e2aspan\uff0c\u4e0b\u7bc7\u6587\u7ae0\u6f14\u793a\u5982\u4f55\u5982\u679c\u521b\u5efa\u4e00\u4e2a\u5305\u542b\u591a\u4e2aspan\u7684trace\uff0c\u4ee5\u53ca\u5982\u4f55\u5728\u8fdb\u7a0b\u5185\u90e8\uff08\u4e0d\u540c\u65b9\u6cd5\u95f4\uff09\u4f20\u9012span\u4fe1\u606f\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u76ee\u6807 \u5b66\u4e60\u5982\u4f55\uff1a \u5b9e\u4f8b\u5316\u4e00\u4e2aTracer \u521b\u5efa\u4e00\u4e2a\u7b80\u5355\u7684\u94fe\u8def \u7ed9\u94fe\u8def\u589e\u52a0\u4e00\u4e9b\u6ce8\u89e3\uff08annotation\uff09\uff1a\u5373\u589e [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[26],"tags":[],"_links":{"self":[{"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/9224"}],"collection":[{"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=9224"}],"version-history":[{"count":1,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/9224\/revisions"}],"predecessor-version":[{"id":9229,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/9224\/revisions\/9229"}],"wp:attachment":[{"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=9224"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=9224"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=9224"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}