Python 函数应用程序中缺少应用程序洞察和监控

问题描述 投票:0回答:1

我有一个工作区,并使用我的应用程序见解对其进行配置。我在功能的配置中添加了app Insight的仪器密钥和连接字符串。当该功能公开时,应用程序洞察正在运行。但现在监控零件和应用程序洞察仪表板,故障不起作用。缺少什么?

python-3.x azure-functions azure-application-insights azure-monitor
1个回答
0
投票

我们可以通过将应用程序洞察配置为我们的功能来获取监控警报和应用程序洞察仪表板、故障,您可以按照以下步骤操作。

  • 这里我在 vs code 中创建了一个带有运行时 python 的普通函数应用程序/默认应用程序。

然后我在 local.setting.json 文件中使用我的函数配置了 azure 应用程序洞察。

{
  "IsEncrypted": false,
  "Values": {
    "AzureWebJobsStorage": "UseDevelopmentStorage=true",
    "FUNCTIONS_WORKER_RUNTIME": "python",
    "APPINSIGHTS_INSTRUMENTATIONKEY": "your_instrumentation_key_here"
  }
}
  • 为了检查它是否正常工作,我在本例中更改了代码,添加了一个假异常以从我的应用程序洞察中接收跟踪。
from applicationinsights import TelemetryClient
import time

# Simulate custom event
client.track_event("FakeEvent", properties={"key": "value"})

# Simulate custom metric
client.track_metric("FakeMetric", 42)

# Simulate exception
try:
    # Code that might raise an exception
    raise ValueError("Simulated exception")
except Exception as e:
    client.track_exception()

# Flush telemetry data
client.flush()

您可以看到运行函数应用程序时生成的异常,并且这些异常在我的应用程序洞察中被跟踪为失败。

enter image description here

仪表板:

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.