我正在尝试使用OpenCensus和Azure应用程序洞察发送Python中的度量。你知道吗
理想情况下,我希望发送一些具有任意结构的Python字典,但是OpenCensus似乎“自动侦听日志记录/打印语句”,但是当我搜索这些内容时,在Azure门户上没有看到这方面的证据。你知道吗
对OpenCensus来说print(...)
有什么特别之处吗?它如何捕获打印语句的内容?你知道吗
我尝试了两种不同的方法(代码见下文):
AFAIK原则:
我想了解:
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
感谢您将OpenCensus与Azure Monitor结合使用!你可以在网上找到我的答案。你知道吗
如何在OpenCensus中将任意字典作为“度量”发送?在使用应用程序进行应用程序洞察时,这将如何显示在Azure门户上?
你说的任意字典是什么意思?在您的代码片段中,似乎您希望将单个数据点作为度量数据发送到azuremonitor后端(applicationinsights)。有关如何开始使用OpenCensus的步骤,请查看Microsoft网站上的overview页。这将向您展示如何使用OpenCensus正确地测试应用程序,以及如何将遥测数据发送到azuremonitor。如果您仍然对如何对应用程序进行工具化处理以满足业务用例感到困惑,那么这里还有一些examples您可以看一下。你知道吗
印刷品有什么特别之处(…)(或日志记录.info(…)和OpenCensus中的HTTP请求?在应用程序的Azure门户上,这些信息应该如何对应用程序洞察有用?
print
命令在OpenCensus中没有特殊含义。对于日志,如果您使用OpenCensus Azure Monitor并使用logging exporter,则可以从Python标准日志库自动发送日志遥测。对于HTTP请求,您可以使用跟踪导出器和各种OpenCensus库集成来跟踪incoming requests和outgoing requests,具体取决于您要跟踪遥测的库。你知道吗以上内容对跟踪器/跨距来说是不可知的,还是需要发送度量时必须使用跨距?
跨度是一个仅用于跟踪的概念(使用AzureExporter)。您不需要创建范围来发送度量数据(度量导出器)。看看上面的链接,看看如何使用这些。你知道吗
相关问题 更多 >
编程相关推荐