跟踪遥测未显示在 Azure 门户上

Trace Telemetry not showing up on Azure Portal

我在本地 IIS 服务器上有一个 MVC 应用程序 运行。我在 Azure 上有一个现有的 App Insights 资源,我希望在其中显示我的应用程序的遥测。但是,跟踪消息未显示在 Azure 门户上。我已将 ApplicationInsights 添加到我的项目中,指定了 Telemetry 应该显示在 ApplicationInsights.config 中的资源,还编写了一个 TelemetryWrapper,我在我的代码中使用它来发送实际的 Telemetry 信息和错误消息。

我通过包装器初始化遥测服务:

  TelemetryWrapper.InitializeTelemetry("InstrumentationKey", "ApplicationName");

也从包装器发送消息

  TelemetryWrapper.TelemetryInfo(requestId, action, userId, ultimateId, systemId, payload);

TelemetryWrapper 概述:

  public static void InitializeTelemetry(string apiKey, string appId)
    {
       bool postBackground = true;
        _telemetry = new TelemetryHelper(apiKey, appId, false) { PostBackground = postBackground };
    }

  public static void TelemetryInfo(Guid requestId, string action, Guid userId, string ultimateId, string systemId,
        string payload)
    {
      var telem = CreateInstance(requestId, action, ultimateId, userId, systemId, payload);
      _telemetry.Info(telem);
    }

我可能做错了什么?

需要更多信息。您所显示的只是您的代码,此处没有可供查看的 AppInsights 代码。所以可能是您的 TelemetryHelper class 没有正确设置 ikey,ikey 可能无效。

但是: 让我印象深刻的一件事是您在代码中使用术语 apiKeyappId

这 2 件事在应用程序洞察中具有特定含义,但那是为了 从 AI API 服务 中读取数据(以及其中的 apiKey context 是你可以认为是秘密的东西,就好像有人拥有这些密钥,他们可以读取你的所有数据!) 我不确定你是否在不同的上下文中使用它们,但跳出来了我马上。

有一个不同的东西,"Instrumentation Key"或iKey,你用它来发送数据到应用洞察.您是否可以切换这些东西并尝试使用 AI appId 和 apiKey 代替 iKey?

一种检查方法是在本地使用 fiddler 或其他工具来观察出站 http 流量。将其配置为解密 https,并观察对 dc.services.visualstudio.com 的出站调用,这是您的遥测去向。如果您有呼出电话,那么它至少会尝试 发送 您的遥测数据。如果这些调用失败,响应 可能 告诉您您使用的 iKey 无效,如果是这种情况。

你不需要