{"id":38296,"date":"2025-04-23T20:18:41","date_gmt":"2025-04-23T12:18:41","guid":{"rendered":"https:\/\/www.yunshan.net\/blog\/?p=38296"},"modified":"2025-04-23T20:18:41","modified_gmt":"2025-04-23T12:18:41","slug":"opentelemetry%e7%9a%84%e6%8c%87%e6%a0%87%e6%98%af%e5%a6%82%e4%bd%95%e8%ae%a1%e7%ae%97%e9%a9%ac%e6%b0%8f%e7%9b%b8%e4%bc%bc%e7%b3%bb%e6%95%b0%e7%9a%84","status":"publish","type":"post","link":"https:\/\/www.yunshan.net\/blog\/archives\/38296.html","title":{"rendered":"OpenTelemetry\u7684\u6307\u6807\u662f\u5982\u4f55\u8ba1\u7b97\u9a6c\u6c0f\u76f8\u4f3c\u7cfb\u6570\u7684"},"content":{"rendered":"<p style=\"text-align: center;\">\n<p><img decoding=\"async\" src=\"https:\/\/pic.zadbj010.com\/2025\/223f75070980ee6.webp\" alt=\"OpenTelemetry\u7684\u6307\u6807\u662f\u5982\u4f55\u8ba1\u7b97\u9a6c\u6c0f\u76f8\u4f3c\u7cfb\u6570\u7684\" ><\/p>\n<\/p>\n<p>OpenTelemetry\u662f\u4e00\u4e2a\u5f00\u6e90\u7684\u53ef\u89c2\u6d4b\u6027\u6846\u67b6\uff0c\u7528\u4e8e\u6536\u96c6\u3001\u5904\u7406\u548c\u5bfc\u51fa\u9065\u6d4b\u6570\u636e\uff08\u5982\u6307\u6807\u3001\u65e5\u5fd7\u548c\u8ffd\u8e2a\uff09\u3002\u5b83\u63d0\u4f9b\u4e86\u4e00\u7ec4API\u3001SDK\u548c\u5de5\u5177\uff0c\u5e2e\u52a9\u5f00\u53d1\u4eba\u5458\u7406\u89e3\u7cfb\u7edf\u7684\u884c\u4e3a\u548c\u6027\u80fd\u3002<\/p>\n<h2>\u4e8c\u3001\u9a6c\u6c0f\u76f8\u4f3c\u7cfb\u6570\uff08Mahalanobis Similarity Coefficient\uff09<\/h2>\n<p>\u9a6c\u6c0f\u76f8\u4f3c\u7cfb\u6570\uff0c\u4e5f\u79f0\u4e3a\u9a6c\u6c0f\u8ddd\u79bb\uff08Mahalanobis Distance\uff09\uff0c\u662f\u4e00\u79cd\u8861\u91cf\u4e24\u4e2a\u6837\u672c\u96c6\u4e4b\u95f4\u76f8\u4f3c\u6027\u7684\u7edf\u8ba1\u91cf\u3002\u4e0e\u6b27\u51e0\u91cc\u5f97\u8ddd\u79bb\u4e0d\u540c\uff0c\u9a6c\u6c0f\u8ddd\u79bb\u8003\u8651\u4e86\u6570\u636e\u7684\u534f\u65b9\u5dee\u7ed3\u6784\uff0c\u53ef\u4ee5\u5904\u7406\u5177\u6709\u4e0d\u540c\u5c3a\u5ea6\u548c\u76f8\u5173\u6027\u7684\u6570\u636e\u3002<\/p>\n<h2>\u4e09\u3001\u8ba1\u7b97\u6b65\u9aa4<\/h2>\n<p>\u5728OpenTelemetry\u4e2d\uff0c\u8ba1\u7b97\u9a6c\u6c0f\u76f8\u4f3c\u7cfb\u6570\u6d89\u53ca\u4ee5\u4e0b\u51e0\u4e2a\u4e3b\u8981\u6b65\u9aa4\uff1a<\/p>\n<p>1. <strong>\u6570\u636e\u6536\u96c6<\/strong>\uff1a\u4f7f\u7528OpenTelemetry API\u6536\u96c6\u76f8\u5173\u7684\u6307\u6807\u6570\u636e\u3002\u8fd9\u4e9b\u6570\u636e\u53ef\u4ee5\u6765\u81ea\u5404\u79cd\u6765\u6e90\uff0c\u5982\u5e94\u7528\u7a0b\u5e8f\u4ee3\u7801\u3001\u7cfb\u7edf\u76d1\u63a7\u5de5\u5177\u7b49\u3002<\/p>\n<p>2. <strong>\u6570\u636e\u9884\u5904\u7406<\/strong>\uff1a\u5bf9\u6536\u96c6\u5230\u7684\u6570\u636e\u8fdb\u884c\u6e05\u6d17\u548c\u8f6c\u6362\uff0c\u4ee5\u786e\u4fdd\u5176\u9002\u5408\u8fdb\u884c\u9a6c\u6c0f\u8ddd\u79bb\u8ba1\u7b97\u3002\u8fd9\u53ef\u80fd\u5305\u62ec\u5904\u7406\u7f3a\u5931\u503c\u3001\u6807\u51c6\u5316\u6570\u636e\u7b49\u64cd\u4f5c\u3002<\/p>\n<p>3. <strong>\u8ba1\u7b97\u534f\u65b9\u5dee\u77e9\u9635<\/strong>\uff1a\u6839\u636e\u9884\u5904\u7406\u540e\u7684\u6570\u636e\u8ba1\u7b97\u534f\u65b9\u5dee\u77e9\u9635\u3002\u534f\u65b9\u5dee\u77e9\u9635\u63cf\u8ff0\u4e86\u6570\u636e\u96c6\u4e2d\u5404\u4e2a\u53d8\u91cf\u4e4b\u95f4\u7684\u5173\u7cfb\u3002<\/p>\n<p>4. <strong>\u8ba1\u7b97\u9a6c\u6c0f\u8ddd\u79bb<\/strong>\uff1a\u4f7f\u7528\u534f\u65b9\u5dee\u77e9\u9635\u7684\u9006\u77e9\u9635\uff0c\u8ba1\u7b97\u4e24\u4e2a\u6837\u672c\u4e4b\u95f4\u7684\u9a6c\u6c0f\u8ddd\u79bb\u3002\u516c\u5f0f\u5982\u4e0b\uff1a<\/p>\n<p>[d(mathbf{x}, mathbf{y}) = sqrt{ (mathbf{x}<\/p>\n<li>mathbf{y})^T mathbf{S}^{-1} (mathbf{x}\n<li>mathbf{y}) }]<\/li>\n<\/li>\n<p>\u5176\u4e2d\uff0c(mathbf{x}) \u548c (mathbf{y}) \u662f\u4e24\u4e2a\u6837\u672c\u5411\u91cf\uff0c(mathbf{S}) \u662f\u534f\u65b9\u5dee\u77e9\u9635\u3002<\/p>\n<p>5. <strong>\u89e3\u91ca\u7ed3\u679c<\/strong>\uff1a\u9a6c\u6c0f\u8ddd\u79bb\u7684\u503c\u8d8a\u5c0f\uff0c\u8868\u793a\u4e24\u4e2a\u6837\u672c\u8d8a\u76f8\u4f3c\u3002\u6839\u636e\u5177\u4f53\u7684\u5e94\u7528\u573a\u666f\uff0c\u53ef\u4ee5\u8bbe\u5b9a\u4e00\u4e2a\u9608\u503c\u6765\u5224\u65ad\u76f8\u4f3c\u6027\u662f\u5426\u8db3\u591f\u3002<\/p>\n<h2>\u56db\u3001\u793a\u4f8b\u4ee3\u7801<\/h2>\n<p>\u4ee5\u4e0b\u662f\u4e00\u4e2a\u7b80\u5355\u7684Python\u4ee3\u7801\u793a\u4f8b\uff0c\u5c55\u793a\u5982\u4f55\u4f7f\u7528OpenTelemetry\u548cNumPy\u5e93\u8ba1\u7b97\u9a6c\u6c0f\u8ddd\u79bb\uff1a<\/p>\n<p>python<\/p>\n<p>import numpy as np<\/p>\n<p>from opentelemetry import metrics<\/p>\n<p>\u521d\u59cb\u5316OpenTelemetry\u6307\u6807<\/p>\n<p>metrics.set_meter_provider(metrics.get_meter_provider)<\/p>\n<p>meter = metrics.get_meter(__name__)<\/p>\n<p>\u6a21\u62df\u6536\u96c6\u5230\u7684\u6307\u6807\u6570\u636e<\/p>\n<p>data = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]])<\/p>\n<p>\u6570\u636e\u9884\u5904\u7406\uff08\u8fd9\u91cc\u7b80\u5355\u6807\u51c6\u5316\u6570\u636e\uff09<\/p>\n<p>scaled_data = (data<\/p>\n<li>np.mean(data, axis=0)) \/ np.std(data, axis=0)<\/li>\n<p>\u8ba1\u7b97\u534f\u65b9\u5dee\u77e9\u9635<\/p>\n<p>cov_matrix = np.cov(scaled_data.T)<\/p>\n<p>\u8ba1\u7b97\u9a6c\u6c0f\u8ddd\u79bb<\/p>\n<p>def mahalanobis_distance(x, y):<\/p>\n<p>diff = x<\/p>\n<li>y<\/li>\n<p>inv_covmat = np.linalg.inv(cov_matrix)<\/p>\n<p>return np.sqrt(np.dot(np.dot(diff, inv_covmat), diff.T))<\/p>\n<p>\u8ba1\u7b97\u6240\u6709\u6837\u672c\u5bf9\u4e4b\u95f4\u7684\u9a6c\u6c0f\u8ddd\u79bb<\/p>\n<p>distances = []<\/p>\n<p>for i in range(len(scaled_data)):<\/p>\n<p>for j in range(i+1, len(scaled_data)):<\/p>\n<p>dist = mahalanobis_distance(scaled_data[i], scaled_data[j])<\/p>\n<p>distances.append(dist)<\/p>\n<p>print(&#8220;\u9a6c\u6c0f\u8ddd\u79bb:&#8221;, distances)<\/p>\n<p>\u901a\u8fc7\u7ed3\u5408OpenTelemetry\u7684\u5f3a\u5927\u6570\u636e\u6536\u96c6\u80fd\u529b\u548c\u9a6c\u6c0f\u8ddd\u79bb\u7684\u7edf\u8ba1\u65b9\u6cd5\uff0c\u53ef\u4ee5\u6709\u6548\u5730\u5206\u6790\u548c\u6bd4\u8f83\u590d\u6742\u7cfb\u7edf\u4e2d\u7684\u6570\u636e\u6a21\u5f0f\u3002\u8fd9\u79cd\u65b9\u6cd5\u5728\u6545\u969c\u68c0\u6d4b\u3001\u6027\u80fd\u4f18\u5316\u548c\u5f02\u5e38\u8bca\u65ad\u7b49\u65b9\u9762\u5177\u6709\u91cd\u8981\u4ef7\u503c\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>OpenTelemetry\u662f\u4e00\u4e2a\u5f00\u6e90\u7684\u53ef\u89c2\u6d4b\u6027\u6846\u67b6\uff0c\u7528\u4e8e\u6536\u96c6\u3001\u5904\u7406\u548c\u5bfc\u51fa\u9065\u6d4b\u6570\u636e\uff08\u5982\u6307\u6807\u3001\u65e5\u5fd7\u548c\u8ffd\u8e2a\uff09\u3002\u5b83\u63d0\u4f9b\u4e86\u4e00\u7ec4API\u3001SDK\u548c\u5de5\u5177\uff0c\u5e2e\u52a9\u5f00\u53d1\u4eba\u5458\u7406\u89e3\u7cfb\u7edf\u7684\u884c\u4e3a\u548c\u6027\u80fd\u3002 \u4e8c\u3001\u9a6c\u6c0f\u76f8\u4f3c\u7cfb\u6570\uff08Mahalanobis Similarity Coefficient\uff09 \u9a6c\u6c0f\u76f8\u4f3c\u7cfb\u6570\uff0c\u4e5f\u79f0\u4e3a\u9a6c\u6c0f\u8ddd\u79bb\uff08Mahalanobis Distance\uff09\uff0c\u662f\u4e00\u79cd\u8861\u91cf\u4e24\u4e2a\u6837\u672c\u96c6\u4e4b\u95f4\u76f8\u4f3c\u6027\u7684\u7edf\u8ba1\u91cf\u3002\u4e0e\u6b27\u51e0\u91cc\u5f97\u8ddd\u79bb\u4e0d\u540c\uff0c\u9a6c\u6c0f\u8ddd\u79bb\u8003\u8651\u4e86\u6570\u636e\u7684\u534f\u65b9\u5dee\u7ed3\u6784\uff0c\u53ef\u4ee5\u5904\u7406\u5177\u6709\u4e0d\u540c\u5c3a\u5ea6\u548c\u76f8\u5173\u6027\u7684\u6570\u636e\u3002 \u4e09\u3001\u8ba1\u7b97\u6b65\u9aa4 \u5728OpenTelemetry\u4e2d\uff0c\u8ba1\u7b97\u9a6c\u6c0f\u76f8\u4f3c\u7cfb\u6570\u6d89\u53ca\u4ee5\u4e0b\u51e0\u4e2a\u4e3b\u8981\u6b65\u9aa4\uff1a 1. \u6570\u636e\u6536\u96c6\uff1a\u4f7f\u7528OpenTelemetry API\u6536\u96c6\u76f8\u5173\u7684\u6307\u6807\u6570\u636e\u3002\u8fd9\u4e9b\u6570\u636e\u53ef\u4ee5\u6765\u81ea\u5404\u79cd\u6765\u6e90\uff0c\u5982\u5e94\u7528\u7a0b\u5e8f\u4ee3\u7801\u3001\u7cfb\u7edf\u76d1\u63a7\u5de5\u5177\u7b49\u3002 2. \u6570\u636e\u9884\u5904\u7406\uff1a\u5bf9\u6536\u96c6\u5230\u7684\u6570\u636e\u8fdb\u884c\u6e05\u6d17\u548c\u8f6c\u6362\uff0c\u4ee5\u786e\u4fdd\u5176\u9002\u5408\u8fdb\u884c\u9a6c\u6c0f\u8ddd\u79bb\u8ba1\u7b97\u3002\u8fd9\u53ef\u80fd\u5305\u62ec\u5904\u7406\u7f3a\u5931\u503c\u3001\u6807\u51c6\u5316\u6570\u636e\u7b49\u64cd\u4f5c\u3002 3. \u8ba1\u7b97\u534f\u65b9\u5dee\u77e9\u9635\uff1a\u6839\u636e\u9884\u5904\u7406\u540e\u7684\u6570\u636e\u8ba1\u7b97\u534f\u65b9\u5dee\u77e9\u9635\u3002\u534f\u65b9\u5dee\u77e9\u9635\u63cf\u8ff0\u4e86\u6570\u636e\u96c6\u4e2d\u5404\u4e2a\u53d8\u91cf\u4e4b\u95f4\u7684\u5173\u7cfb\u3002 4. \u8ba1\u7b97\u9a6c\u6c0f\u8ddd\u79bb\uff1a\u4f7f\u7528\u534f\u65b9\u5dee\u77e9\u9635\u7684\u9006\u77e9\u9635\uff0c\u8ba1\u7b97\u4e24\u4e2a\u6837\u672c\u4e4b\u95f4\u7684\u9a6c\u6c0f\u8ddd\u79bb\u3002\u516c\u5f0f\u5982\u4e0b\uff1a [d(mathbf{x}, mathbf{y}) = sqrt{ (mathbf{x} mathbf{y})^T mathbf{S}^{-1} (mathbf{x} mathbf{y}) }] \u5176\u4e2d\uff0c(mathbf{x}) \u548c (mathbf{y}) \u662f\u4e24\u4e2a\u6837\u672c\u5411\u91cf\uff0c(mathbf{S}) \u662f\u534f\u65b9\u5dee\u77e9\u9635\u3002 5. \u89e3\u91ca\u7ed3\u679c\uff1a\u9a6c\u6c0f\u8ddd\u79bb\u7684\u503c\u8d8a\u5c0f\uff0c\u8868\u793a\u4e24\u4e2a\u6837\u672c\u8d8a\u76f8\u4f3c\u3002\u6839\u636e\u5177\u4f53\u7684\u5e94\u7528\u573a\u666f\uff0c\u53ef\u4ee5\u8bbe\u5b9a\u4e00\u4e2a\u9608\u503c\u6765\u5224\u65ad\u76f8\u4f3c\u6027\u662f\u5426\u8db3\u591f\u3002 \u56db\u3001\u793a\u4f8b\u4ee3\u7801 \u4ee5\u4e0b\u662f\u4e00\u4e2a\u7b80\u5355\u7684Python\u4ee3\u7801\u793a\u4f8b\uff0c\u5c55\u793a\u5982\u4f55\u4f7f\u7528OpenTelemetry\u548cNumPy\u5e93\u8ba1\u7b97\u9a6c\u6c0f\u8ddd\u79bb\uff1a python import numpy as np from opentelemetry import metrics \u521d\u59cb\u5316OpenTelemetry\u6307\u6807 metrics.set_meter_provider(metrics.get_meter_provider) meter = metrics.get_meter(__name__) \u6a21\u62df\u6536\u96c6\u5230\u7684\u6307\u6807\u6570\u636e data = np.array([[1, 2, [&hellip;]<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[],"class_list":["post-38296","post","type-post","status-publish","format-standard","hentry","category-discussion"],"_links":{"self":[{"href":"https:\/\/www.yunshan.net\/blog\/wp-json\/wp\/v2\/posts\/38296","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=38296"}],"version-history":[{"count":1,"href":"https:\/\/www.yunshan.net\/blog\/wp-json\/wp\/v2\/posts\/38296\/revisions"}],"predecessor-version":[{"id":38297,"href":"https:\/\/www.yunshan.net\/blog\/wp-json\/wp\/v2\/posts\/38296\/revisions\/38297"}],"wp:attachment":[{"href":"https:\/\/www.yunshan.net\/blog\/wp-json\/wp\/v2\/media?parent=38296"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.yunshan.net\/blog\/wp-json\/wp\/v2\/categories?post=38296"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.yunshan.net\/blog\/wp-json\/wp\/v2\/tags?post=38296"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}