我试图使用OpenCensus和Azure应用程序Insight在Python中发送度量标准。
理想情况下,我希望发送一些具有任意结构的Python字典,然而,OpenCensus似乎“自动侦听日志记录/打印语句”,但是当我搜索这些东西时,我在Azure门户上没有看到这方面的证据。
print(...)对OpenCensus有什么特别之处吗?如何捕捉打印语句的内容?
我尝试了两种不同的方法(代码见下文):
AFAIK原则:
我想了解:
print(...) (或logging.info(...))和HTTP请求在OpenCensus中有什么特殊之处?在应用程序应用程序中的Azure门户上,这些信息应该如何有用?import json
import psutil
from opencensus.trace.samplers import AlwaysOnSampler
from opencensus.trace.tracer import Tracer
from opencensus.ext.azure import metrics_exporter
from opencensus.ext.azure.trace_exporter import AzureExporter
if __name__ == "__main__":
# loading the instrumentation key (for the Azure Application Insights app) from a JSON file
azure_conf = json.loads(open("tf/ai_details.json", 'r').read())
ai_instrumentation_key = azure_conf['instrumentation_key']['value']
# print(ai_instrumentation_key)
# test 1: trying to "send a metric", does that mean that the metric exporter listens to "print(...)"?
_me = metrics_exporter.new_metrics_exporter(connection_string='InstrumentationKey={}'.format(ai_instrumentation_key))
print(psutil.virtual_memory())
print("Done recording metrics")
# test 2: trying to "send a metric", how can I make the "span" to send a dictionary?
azure_exporter = AzureExporter(connection_string='InstrumentationKey={}'.format(ai_instrumentation_key))
# https://opencensus.io/api/python/trace/api/tracer.html
tracer = Tracer(exporter=azure_exporter, sampler=AlwaysOnSampler())
# https://opencensus.io/api/python/trace/api/span.html#opencensus.trace.span.Span
with tracer.span(name='TestSpan') as span:
print('Hello, World!') # is the span only listening to "print(...)"?
span.add_attribute("foo-span-key", "foo-span-value") # this does not seem to do anything发布于 2019-12-12 21:38:33
感谢您使用OpenCensus与Azure监视器!你可以在网上找到我的答案。
如何在OpenCensus中将任意的字典作为“度量”发送?当使用应用程序进行应用程序洞察时,这将如何在Azure门户上显示?
武断的字典是什么意思?在您的代码片段中,您似乎希望将单个数据点作为度量数据发送到Azure Monitor后端(Application )。有关如何开始使用OpenCensus的步骤,请查看微软网站上的概述页面。这将向您展示如何使用OpenCensus正确地测试您的应用程序,以及如何将您的遥测发送到Azure监视器。如果您仍然对如何测试您的应用程序以满足您的业务用例感到困惑,下面是一些您可以查看的更多示例。
打印有什么特别之处(.)(或logging.info(.))OpenCensus中的HTTP请求?在应用程序中的Azure门户上,这些信息应该如何有用呢?
print命令在OpenCensus中没有特殊含义。对于日志,如果使用OpenCensus Azure监视器进行仪器测试并利用伐木出口商,则可以从库自动发送日志遥测。对于HTTP请求,您可以通过跟踪导出程序和各种OpenCensus库集成跟踪发出请求和发出请求,这取决于您希望跟踪遥测的库。
在某种程度上,对跟踪器/跨是不可知的,或者,当需要发送度量?时,必须使用跨范围。
Spans是一个仅用于跟踪(使用AzureExporter)的概念。您不需要创建spans来发送度量数据(度量输出程序)。看看上面的链接,看看如何使用这些链接。
https://stackoverflow.com/questions/59290214
复制相似问题