gpt4 book ai didi

python - 使用 opencensus-python 时从 Application Insights 中删除 customDimensions 项目

转载 作者:行者123 更新时间:2023-12-03 00:58:06 24 4
gpt4 key购买 nike

the documentation关于如何使用 opencensus-python 将跟踪提交到 Azure Application Insights,详细说明了如何向 customDimensions 字段添加其他信息。也就是说,

import logging

from opencensus.ext.azure.log_exporter import AzureLogHandler

logger = logging.getLogger(__name__)
logger.addHandler(AzureLogHandler(
connection_string='InstrumentationKey=00000000-0000-0000-0000-000000000000')
)

logger.error('blooh')
logger.error('blooh2', extra={'custom_dimensions': {'woot': 42}})

变成了

enter image description here

在 Application Insights UI 中。

这一切都很好,但是从默认包含的 customDimensions 中删除项目的预期方法是什么?即像 fileNameprocess 这样的东西?

最佳答案

作者:inspection of the source code ,这些属性似乎很难避免创建,但可以通过对信封进行后处理来删除它们:

import logging

from opencensus.ext.azure.log_exporter import AzureLogHandler

custom_dimensions = {'foo': 'bar'}

def remove_items(envelope):
envelope.data.baseData.properties = custom_dimensions
return True

logger = logging.getLogger(__name__)
handler = AzureLogHandler(connection_string='InstrumentationKey=00000000-0000-0000-0000-000000000000')
handler.add_telemetry_processor(remove_items)
logger.addHandler(handler)
logger.error('blooh')

这已经过测试并可在 opencensus-ext-azure 版本 1.0.5 中运行。

enter image description here

另请注意,使用此方法,在记录时不再需要指定额外

关于python - 使用 opencensus-python 时从 Application Insights 中删除 customDimensions 项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64576336/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com