{"id":32141,"date":"2025-01-21T15:38:35","date_gmt":"2025-01-21T07:38:35","guid":{"rendered":"https:\/\/www.yunshan.net\/blog\/?p=25154"},"modified":"2025-01-21T15:38:35","modified_gmt":"2025-01-21T07:38:35","slug":"opentelemetry-%e7%9a%84%e9%85%8d%e7%bd%ae%e6%96%87%e4%bb%b6%e5%92%8c%e7%8e%af%e5%a2%83%e5%8f%98%e9%87%8f%e5%a6%82%e4%bd%95%e7%ae%a1%e7%90%86%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/www.yunshan.net\/blog\/archives\/32141.html","title":{"rendered":"OpenTelemetry \u7684\u914d\u7f6e\u6587\u4ef6\u548c\u73af\u5883\u53d8\u91cf\u5982\u4f55\u7ba1\u7406\uff1f"},"content":{"rendered":"<p>\t\t\t\t<![CDATA[\n                \n\n<p style=\"text-align: center;\">\n\n<p><img decoding=\"async\" src=\"https:\/\/pic.zadbj010.com\/2025\/12040b3394a4f45.jpg\" alt=\"OpenTelemetry \u7684\u914d\u7f6e\u6587\u4ef6\u548c\u73af\u5883\u53d8\u91cf\u5982\u4f55\u7ba1\u7406\uff1f\" ><\/p>\n\n<\/p>\n\n\n\n<p>\u5728\u73b0\u4ee3\u5206\u5e03\u5f0f\u7cfb\u7edf\u4e2d\uff0c<strong>OpenTelemetry<\/strong> \u4f5c\u4e3a\u4e00\u6b3e\u5f3a\u5927\u7684\u53ef\u89c2\u6d4b\u6027\u5de5\u5177\uff0c\u5df2\u7ecf\u6210\u4e3a\u4e86\u5f00\u53d1\u8005\u548c\u8fd0\u7ef4\u4eba\u5458\u7684\u9996\u9009\u3002\u7136\u800c\uff0c\u968f\u7740\u7cfb\u7edf\u590d\u6742\u6027\u7684\u589e\u52a0\uff0c\u5982\u4f55\u9ad8\u6548\u5730\u7ba1\u7406 OpenTelemetry \u7684\u914d\u7f6e\u6587\u4ef6\u548c\u73af\u5883\u53d8\u91cf\uff0c\u6210\u4e3a\u4e86\u4e00\u4e2a\u4e0d\u53ef\u5ffd\u89c6\u7684\u6311\u6218\u3002\u672c\u6587\u5c06\u6df1\u5165\u63a2\u8ba8 OpenTelemetry \u7684\u914d\u7f6e\u6587\u4ef6\u548c\u73af\u5883\u53d8\u91cf\u7684\u7ba1\u7406\u7b56\u7565\uff0c\u5e2e\u52a9\u4f60\u5728\u5b9e\u9645\u5e94\u7528\u4e2d\u66f4\u597d\u5730\u9a7e\u9a6d\u8fd9\u4e00\u5de5\u5177\u3002<\/p>\n\n\n\n\n<h3>1. OpenTelemetry \u914d\u7f6e\u6587\u4ef6\u7684\u57fa\u672c\u7ed3\u6784<\/h3>\n\n\n\n\n<p>OpenTelemetry \u7684\u914d\u7f6e\u6587\u4ef6\u901a\u5e38\u4ee5 YAML \u6216 JSON \u683c\u5f0f\u7f16\u5199\uff0c\u7528\u4e8e\u5b9a\u4e49\u6570\u636e\u6536\u96c6\u3001\u5904\u7406\u548c\u5bfc\u51fa\u7684\u89c4\u5219\u3002\u4e00\u4e2a\u5178\u578b\u7684\u914d\u7f6e\u6587\u4ef6\u53ef\u80fd\u5305\u542b\u4ee5\u4e0b\u51e0\u4e2a\u90e8\u5206\uff1a<\/p>\n\n\n\n\n<ul>\n\n\n<li><strong>Service Name<\/strong>: \u5b9a\u4e49\u670d\u52a1\u7684\u540d\u79f0\uff0c\u7528\u4e8e\u6807\u8bc6\u6570\u636e\u7684\u6765\u6e90\u3002<\/li>\n\n\n\n\n<li><strong>Exporters<\/strong>: \u914d\u7f6e\u6570\u636e\u5bfc\u51fa\u7684\u76ee\u6807\uff0c\u5982 Jaeger\u3001Prometheus \u6216 OpenTelemetry Collector\u3002<\/li>\n\n\n\n\n<li><strong>Samplers<\/strong>: \u5b9a\u4e49\u91c7\u6837\u7b56\u7565\uff0c\u63a7\u5236\u6570\u636e\u7684\u6536\u96c6\u9891\u7387\u3002<\/li>\n\n\n\n\n<li><strong>Processors<\/strong>: \u914d\u7f6e\u6570\u636e\u5904\u7406\u6d41\u7a0b\uff0c\u5982\u6279\u5904\u7406\u3001\u8fc7\u6ee4\u7b49\u3002<\/li>\n\n\n\n\n<li><strong>Extensions<\/strong>: \u5b9a\u4e49\u6269\u5c55\u529f\u80fd\uff0c\u5982\u5065\u5eb7\u68c0\u67e5\u3001\u6027\u80fd\u76d1\u63a7\u7b49\u3002<\/li>\n\n\n<\/ul>\n\n\n\n\n<p>\u4f8b\u5982\uff0c\u4e00\u4e2a\u7b80\u5355\u7684 YAML \u914d\u7f6e\u6587\u4ef6\u53ef\u80fd\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n\n\n\n\n<pre><code class=\"language-yaml\">service:<br \/>\n  name: my-service<br \/>\nexporters:<br \/>\n  jaeger:<br \/>\n    endpoint: &quot;http:\/\/localhost:14268\/api\/traces&quot;<br \/>\nsamplers:<br \/>\n  probability:<br \/>\n    sampling_percentage: 50<br \/>\nprocessors:<br \/>\n  batch:<br \/>\n    timeout: 5s<br \/>\n    send_batch_size: 100<br \/>\nextensions:<br \/>\n  health_check: {}<br \/>\n<\/code><\/pre>\n\n\n\n\n<h3>2. \u73af\u5883\u53d8\u91cf\u7684\u7075\u6d3b\u7ba1\u7406<\/h3>\n\n\n\n\n<p>\u9664\u4e86\u914d\u7f6e\u6587\u4ef6\uff0cOpenTelemetry \u8fd8\u652f\u6301\u901a\u8fc7\u73af\u5883\u53d8\u91cf\u6765\u52a8\u6001\u914d\u7f6e\u5404\u9879\u53c2\u6570\u3002\u8fd9\u79cd\u65b9\u5f0f\u5728\u5bb9\u5668\u5316\u90e8\u7f72\u548c\u4e91\u539f\u751f\u73af\u5883\u4e2d\u5c24\u4e3a\u5e38\u89c1\uff0c\u56e0\u4e3a\u5b83\u5141\u8bb8\u5728\u4e0d\u4fee\u6539\u4ee3\u7801\u6216\u914d\u7f6e\u6587\u4ef6\u7684\u60c5\u51b5\u4e0b\uff0c\u7075\u6d3b\u8c03\u6574\u914d\u7f6e\u3002<\/p>\n\n\n\n\n<p>\u5e38\u89c1\u7684\u73af\u5883\u53d8\u91cf\u5305\u62ec\uff1a<\/p>\n\n\n\n\n<ul>\n\n\n<li><strong>OTEL_SERVICE_NAME<\/strong>: \u5b9a\u4e49\u670d\u52a1\u540d\u79f0\u3002<\/li>\n\n\n\n\n<li><strong>OTEL_EXPORTER_JAEGER_ENDPOINT<\/strong>: \u914d\u7f6e Jaeger \u5bfc\u51fa\u5668\u7684\u7aef\u70b9\u3002<\/li>\n\n\n\n\n<li><strong>OTEL_SAMPLING_PROBABILITY<\/strong>: \u8bbe\u7f6e\u91c7\u6837\u6982\u7387\u3002<\/li>\n\n\n\n\n<li><strong>OTEL_BATCH_TIMEOUT<\/strong>: \u914d\u7f6e\u6279\u5904\u7406\u8d85\u65f6\u65f6\u95f4\u3002<\/li>\n\n\n<\/ul>\n\n\n\n\n<p>\u4f8b\u5982\uff0c\u901a\u8fc7\u8bbe\u7f6e\u4ee5\u4e0b\u73af\u5883\u53d8\u91cf\uff0c\u53ef\u4ee5\u5b9e\u73b0\u4e0e\u4e0a\u8ff0\u914d\u7f6e\u6587\u4ef6\u76f8\u540c\u7684\u6548\u679c\uff1a<\/p>\n\n\n\n\n<pre><code class=\"language-bash\">export OTEL_SERVICE_NAME=my-service<br \/>\nexport OTEL_EXPORTER_JAEGER_ENDPOINT=http:\/\/localhost:14268\/api\/traces<br \/>\nexport OTEL_SAMPLING_PROBABILITY=50<br \/>\nexport OTEL_BATCH_TIMEOUT=5s<br \/>\n<\/code><\/pre>\n\n\n\n\n<h3>3. \u914d\u7f6e\u6587\u4ef6\u4e0e\u73af\u5883\u53d8\u91cf\u7684\u4f18\u5148\u7ea7<\/h3>\n\n\n\n\n<p>\u5728\u5b9e\u9645\u5e94\u7528\u4e2d\uff0c\u914d\u7f6e\u6587\u4ef6\u548c\u73af\u5883\u53d8\u91cf\u53ef\u80fd\u4f1a\u540c\u65f6\u5b58\u5728\u3002OpenTelemetry \u9075\u5faa\u4e00\u5b9a\u7684\u4f18\u5148\u7ea7\u89c4\u5219\u6765\u5904\u7406\u8fd9\u4e9b\u914d\u7f6e\uff1a<\/p>\n\n\n\n\n<ul>\n\n\n<li><strong>\u73af\u5883\u53d8\u91cf\u4f18\u5148\u4e8e\u914d\u7f6e\u6587\u4ef6<\/strong>: \u5982\u679c\u67d0\u4e2a\u914d\u7f6e\u9879\u540c\u65f6\u5b58\u5728\u4e8e\u73af\u5883\u53d8\u91cf\u548c\u914d\u7f6e\u6587\u4ef6\u4e2d\uff0c\u73af\u5883\u53d8\u91cf\u7684\u503c\u5c06\u8986\u76d6\u914d\u7f6e\u6587\u4ef6\u4e2d\u7684\u503c\u3002<\/li>\n\n\n\n\n<li><strong>\u547d\u4ee4\u884c\u53c2\u6570\u4f18\u5148\u4e8e\u73af\u5883\u53d8\u91cf<\/strong>: \u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\uff0c\u547d\u4ee4\u884c\u53c2\u6570\u53ef\u4ee5\u8fdb\u4e00\u6b65\u8986\u76d6\u73af\u5883\u53d8\u91cf\u7684\u503c\u3002<\/li>\n\n\n<\/ul>\n\n\n\n\n<p>\u8fd9\u79cd\u4f18\u5148\u7ea7\u8bbe\u8ba1\u4f7f\u5f97 OpenTelemetry \u5728\u4e0d\u540c\u73af\u5883\u4e2d\u5177\u6709\u6781\u9ad8\u7684\u7075\u6d3b\u6027\uff0c\u80fd\u591f\u9002\u5e94\u5404\u79cd\u590d\u6742\u7684\u90e8\u7f72\u573a\u666f\u3002<\/p>\n\n\n\n\n<h3>4. \u52a8\u6001\u914d\u7f6e\u4e0e\u70ed\u66f4\u65b0<\/h3>\n\n\n\n\n<p>\u5728\u5fae\u670d\u52a1\u67b6\u6784\u4e2d\uff0c\u670d\u52a1\u7684\u914d\u7f6e\u53ef\u80fd\u9700\u8981\u52a8\u6001\u8c03\u6574\uff0c\u800c\u65e0\u9700\u91cd\u542f\u670d\u52a1\u3002OpenTelemetry \u63d0\u4f9b\u4e86\u591a\u79cd\u65b9\u5f0f\u6765\u5b9e\u73b0\u52a8\u6001\u914d\u7f6e\u548c\u70ed\u66f4\u65b0\uff1a<\/p>\n\n\n\n\n<ul>\n\n\n<li><strong>\u914d\u7f6e\u4e2d\u5fc3\u96c6\u6210<\/strong>: \u901a\u8fc7\u4e0e\u914d\u7f6e\u4e2d\u5fc3\uff08\u5982 Consul\u3001Etcd \u6216 ZooKeeper\uff09\u96c6\u6210\uff0cOpenTelemetry \u53ef\u4ee5\u5b9e\u65f6\u83b7\u53d6\u6700\u65b0\u7684\u914d\u7f6e\u4fe1\u606f\u3002<\/li>\n\n\n\n\n<li><strong>\u6587\u4ef6\u76d1\u542c<\/strong>: OpenTelemetry \u652f\u6301\u76d1\u542c\u914d\u7f6e\u6587\u4ef6\u7684\u53d8\u5316\uff0c\u5e76\u5728\u6587\u4ef6\u66f4\u65b0\u65f6\u81ea\u52a8\u91cd\u65b0\u52a0\u8f7d\u914d\u7f6e\u3002<\/li>\n\n\n\n\n<li><strong>API \u63a5\u53e3<\/strong>: \u901a\u8fc7 OpenTelemetry \u63d0\u4f9b\u7684 API \u63a5\u53e3\uff0c\u53ef\u4ee5\u5728\u8fd0\u884c\u65f6\u52a8\u6001\u4fee\u6539\u914d\u7f6e\u3002<\/li>\n\n\n<\/ul>\n\n\n\n\n<p>\u4f8b\u5982\uff0c\u4f7f\u7528\u6587\u4ef6\u76d1\u542c\u529f\u80fd\uff0c\u53ef\u4ee5\u5728\u914d\u7f6e\u6587\u4ef6\u53d1\u751f\u53d8\u5316\u65f6\u81ea\u52a8\u66f4\u65b0\u914d\u7f6e\uff1a<\/p>\n\n\n\n\n<pre><code class=\"language-yaml\">service:<br \/>\n  name: my-service<br \/>\nexporters:<br \/>\n  jaeger:<br \/>\n    endpoint: &quot;http:\/\/localhost:14268\/api\/traces&quot;<br \/>\nsamplers:<br \/>\n  probability:<br \/>\n    sampling_percentage: 50<br \/>\nprocessors:<br \/>\n  batch:<br \/>\n    timeout: 5s<br \/>\n    send_batch_size: 100<br \/>\nextensions:<br \/>\n  health_check: {}<br \/>\nfile_watcher:<br \/>\n  enabled: true<br \/>\n  path: \/path\/to\/config.yaml<br \/>\n<\/code><\/pre>\n\n\n\n\n<h3>5. \u6700\u4f73\u5b9e\u8df5\u4e0e\u6ce8\u610f\u4e8b\u9879<\/h3>\n\n\n\n\n<p>\u5728\u5b9e\u9645\u5e94\u7528\u4e2d\uff0c\u7ba1\u7406 OpenTelemetry \u7684\u914d\u7f6e\u6587\u4ef6\u548c\u73af\u5883\u53d8\u91cf\u65f6\uff0c\u9700\u8981\u6ce8\u610f\u4ee5\u4e0b\u51e0\u70b9\uff1a<\/p>\n\n\n\n\n<ul>\n\n\n<li><strong>\u7248\u672c\u63a7\u5236<\/strong>: \u5c06\u914d\u7f6e\u6587\u4ef6\u7eb3\u5165\u7248\u672c\u63a7\u5236\u7cfb\u7edf\uff08\u5982 Git\uff09\uff0c\u4ee5\u4fbf\u8ffd\u8e2a\u914d\u7f6e\u7684\u53d8\u5316\u5386\u53f2\u3002<\/li>\n\n\n\n\n<li><strong>\u73af\u5883\u9694\u79bb<\/strong>: \u4e3a\u4e0d\u540c\u7684\u73af\u5883\uff08\u5982\u5f00\u53d1\u3001\u6d4b\u8bd5\u3001\u751f\u4ea7\uff09\u521b\u5efa\u72ec\u7acb\u7684\u914d\u7f6e\u6587\u4ef6\uff0c\u907f\u514d\u914d\u7f6e\u51b2\u7a81\u3002<\/li>\n\n\n\n\n<li><strong>\u5b89\u5168\u6027<\/strong>: \u907f\u514d\u5728\u914d\u7f6e\u6587\u4ef6\u4e2d\u786c\u7f16\u7801\u654f\u611f\u4fe1\u606f\uff08\u5982 API \u5bc6\u94a5\uff09\uff0c\u4f7f\u7528\u73af\u5883\u53d8\u91cf\u6216\u5bc6\u94a5\u7ba1\u7406\u5de5\u5177\uff08\u5982 Vault\uff09\u6765\u7ba1\u7406\u8fd9\u4e9b\u4fe1\u606f\u3002<\/li>\n\n\n\n\n<li><strong>\u6027\u80fd\u4f18\u5316<\/strong>: \u6839\u636e\u5b9e\u9645\u9700\u6c42\u8c03\u6574\u91c7\u6837\u7387\u548c\u6279\u5904\u7406\u53c2\u6570\uff0c\u4ee5\u5e73\u8861\u6570\u636e\u6536\u96c6\u7684\u7cbe\u5ea6\u548c\u7cfb\u7edf\u6027\u80fd\u3002<\/li>\n\n\n<\/ul>\n\n\n\n\n<h3>6. \u5de5\u5177\u4e0e\u751f\u6001\u652f\u6301<\/h3>\n\n\n\n\n<p>OpenTelemetry \u751f\u6001\u7cfb\u7edf\u63d0\u4f9b\u4e86\u4e30\u5bcc\u7684\u5de5\u5177\u548c\u63d2\u4ef6\uff0c\u5e2e\u52a9\u7528\u6237\u66f4\u9ad8\u6548\u5730\u7ba1\u7406\u914d\u7f6e\u548c\u73af\u5883\u53d8\u91cf\u3002\u4f8b\u5982\uff1a<\/p>\n\n\n\n\n<ul>\n\n\n<li><strong>OpenTelemetry Operator<\/strong>: \u5728 Kubernetes \u73af\u5883\u4e2d\uff0cOpenTelemetry Operator \u53ef\u4ee5\u81ea\u52a8\u7ba1\u7406 OpenTelemetry \u7684\u914d\u7f6e\u548c\u90e8\u7f72\u3002<\/li>\n\n\n\n\n<li><strong>OpenTelemetry Collector<\/strong>: \u4f5c\u4e3a\u6570\u636e\u6536\u96c6\u548c\u5904\u7406\u7684\u4e2d\u5fc3\u8282\u70b9\uff0cOpenTelemetry Collector \u652f\u6301\u591a\u79cd\u914d\u7f6e\u65b9\u5f0f\uff0c\u5e76\u63d0\u4f9b\u4e86\u4e30\u5bcc\u7684\u63d2\u4ef6\u548c\u6269\u5c55\u529f\u80fd\u3002<\/li>\n\n\n\n\n<li><strong>\u7b2c\u4e09\u65b9\u96c6\u6210<\/strong>: \u8bb8\u591a\u7b2c\u4e09\u65b9\u5de5\u5177\uff08\u5982 Terraform\u3001Ansible\uff09\u4e5f\u63d0\u4f9b\u4e86\u5bf9 OpenTelemetry \u914d\u7f6e\u7684\u652f\u6301\uff0c\u4f7f\u5f97\u914d\u7f6e\u7ba1\u7406\u66f4\u52a0\u4fbf\u6377\u3002<\/li>\n\n\n<\/ul>\n\n\n\n\n<p>\u901a\u8fc7\u5408\u7406\u5229\u7528\u8fd9\u4e9b\u5de5\u5177\u548c\u751f\u6001\u652f\u6301\uff0c\u53ef\u4ee5\u663e\u8457\u63d0\u5347 OpenTelemetry \u914d\u7f6e\u7ba1\u7406\u7684\u6548\u7387\u548c\u53ef\u9760\u6027\u3002<\/p>\n\n\n\n\n<h3>7. \u7ed3\u8bed<\/h3>\n\n\n\n\n<p>\u7ba1\u7406 OpenTelemetry \u7684\u914d\u7f6e\u6587\u4ef6\u548c\u73af\u5883\u53d8\u91cf\u662f\u786e\u4fdd\u7cfb\u7edf\u53ef\u89c2\u6d4b\u6027\u7684\u5173\u952e\u6b65\u9aa4\u3002\u901a\u8fc7\u7406\u89e3\u914d\u7f6e\u6587\u4ef6\u7684\u57fa\u672c\u7ed3\u6784\u3001\u7075\u6d3b\u8fd0\u7528\u73af\u5883\u53d8\u91cf\u3001\u638c\u63e1\u4f18\u5148\u7ea7\u89c4\u5219\u3001\u5b9e\u73b0\u52a8\u6001\u914d\u7f6e\u4e0e\u70ed\u66f4\u65b0\uff0c\u5e76\u9075\u5faa\u6700\u4f73\u5b9e\u8df5\uff0c\u4f60\u53ef\u4ee5\u66f4\u597d\u5730\u9a7e\u9a6d OpenTelemetry\uff0c\u4e3a\u4f60\u7684\u5206\u5e03\u5f0f\u7cfb\u7edf\u63d0\u4f9b\u5f3a\u5927\u7684\u53ef\u89c2\u6d4b\u6027\u652f\u6301\u3002<\/p>\n\n\n                ]]>\t\t<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\t\t\t\t<![CDATA[]]>\t\t<\/p>\n","protected":false},"author":5,"featured_media":25155,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[],"class_list":["post-32141","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-discussion"],"_links":{"self":[{"href":"https:\/\/www.yunshan.net\/blog\/wp-json\/wp\/v2\/posts\/32141","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.yunshan.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.yunshan.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.yunshan.net\/blog\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/www.yunshan.net\/blog\/wp-json\/wp\/v2\/comments?post=32141"}],"version-history":[{"count":0,"href":"https:\/\/www.yunshan.net\/blog\/wp-json\/wp\/v2\/posts\/32141\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.yunshan.net\/blog\/wp-json\/wp\/v2\/media\/25155"}],"wp:attachment":[{"href":"https:\/\/www.yunshan.net\/blog\/wp-json\/wp\/v2\/media?parent=32141"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.yunshan.net\/blog\/wp-json\/wp\/v2\/categories?post=32141"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.yunshan.net\/blog\/wp-json\/wp\/v2\/tags?post=32141"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}