【问题标题】:Problems adding insights to Owin based project向基于 Owin 的项目添加见解的问题
【发布时间】:2018-10-08 00:31:16
【问题描述】:

我一直在尝试将 Azure 应用程序洞察添加到一些项目中。整个体验与 .net 核心应用程序无缝衔接。但是,当我尝试更新 Cloud 角色名称属性时,我找不到很多基于 OWIN 的应用程序。我希望 Insights Application Map 中的气泡名称显示我在此属性中设置的内容(例如我的 API),但它一直使用我在 Azure 中为该资源拥有的资源名称(我的-azure-api)。在浏览了大多数在线资源之后,我能够执行以下不起作用的操作。

using Microsoft.ApplicationInsights.Channel;
using Microsoft.ApplicationInsights.Extensibility;

namespace MyApp.Insights
{
    public class RoleNameInitializer : ITelemetryInitializer
    {
        public void Initialize(ITelemetry telemetry)
        {
            // set role name correctly here.
            telemetry.Context.Cloud.RoleName = "My API";            
        }
    }
}

还在 applicationinsights.config 中添加了以下内容

<Add Type="MyApp.Insights.RoleNameInitializer, MyApp"/>

在启动类中也添加了以下内容(以防万一)

using IntegratedTeleHealthPlatformApi.Insights;
using Microsoft.ApplicationInsights.Extensibility;
using Owin;

namespace MyApp
{
    public partial class Startup
    {

        public void Configuration(IAppBuilder app)
            {

            TelemetryConfiguration
                .Active
                .TelemetryInitializers
                .Add(new RoleNameInitializer());



                ConfigureAuth(app);
                ApplyDatabaseMigrations();       

            }
    }

}

【问题讨论】:

  • 你的意思是telemetry.Context.Cloud.RoleName = "My API";不生效?
  • 是的,没错。

标签: c# azure owin azure-application-insights


【解决方案1】:

我只是设置了一个简单的基于 owin 的 asp.net 项目(asp.net web 应用程序,然后在 nuget 中安装 Microsoft.Owin.Host.SystemWeb)。

设置完成后,在visual studio -> Project -> Add Application Insights Telemetry:

我的自定义 TelemetryInitializer 如下:

然后只需将初始化程序添加到 applicationinsights.config:

执行后,角色名称是我在初始化程序中设置的:

如果您身边没问题,请试一试。为了确保调用了 RoleNameInitializer,您可以在此处设置断点以查看它是否被调用。

【讨论】:

  • 通过菜单选项配置见解添加了一些我没有手动添加的 DLL。这解决了问题。
  • 是的,建议从菜单选项中添加,可以在后台做更多的事情。
猜你喜欢
  • 1970-01-01
  • 2022-01-15
  • 2021-10-17
  • 1970-01-01
  • 1970-01-01
  • 2011-08-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多