在基于Owin的项目中添加见解的问题 [英] Problems adding insights to Owin based project
问题描述
我一直在尝试将Azure应用程序见解添加到一些项目中.使用.net核心应用程序,整个体验是无缝的.但是,当我尝试更新Cloud角色名称属性时,对于基于OWIN的应用程序,我找不到太多的地方.我希望 Insights应用程序地图中的气泡名称显示我在此属性中设置的名称(例如,我的API),但它一直求助于我在Azure中为此资源拥有的资源名称(我的-azure-api).在搜寻了大多数在线资源之后,我能够执行以下不起作用的操作.
I have been trying to add Azure application insights to a few projects. The whole experience was seamless with a .net core app. However, when I tried to update the Cloud role name property, that is where I could not find a lot for an OWIN based app. I want the name of the bubble in Insights Application Map to appear what I set in this property (My API for example) but it keeps resorting to the resource name that I have for this resource in Azure (my-azure-api). After scouring through most online resources, I was able to do the following which does not work.
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中添加了以下内容
Also added the following in the applicationinsights.config
<Add Type="MyApp.Insights.RoleNameInitializer, MyApp"/>
也将以下内容添加到启动类中(出于预防目的)
Added the following to the startup class too (Just as a precaution)
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();
}
}
}
推荐答案
我只是设置了一个基于owin的简单asp.net项目(asp.net Web应用程序,然后在nuget中安装Microsoft.Owin.Host.SystemWeb
).
I just setup a simple owin based asp.net project(asp.net web application, then in nuget install Microsoft.Owin.Host.SystemWeb
).
设置后,在Visual Studio中->项目->添加Application Insights遥测:
After the setup, in visual studio -> Project -> Add Application Insights Telemetry:
我的自定义TelemetryInitializer如下:
My custom TelemetryInitializer as below:
然后只需将初始化程序添加到applicationinsights.config中:
Then just add the initializer to the applicationinsights.config:
执行后,角色名称就是我在初始化程序中设置的角色名称:
And after execution, the role name is the one which I set in the initializer:
如果可以,请尝试一下.为了确保您的RoleNameInitializer被调用,您可以在此处设置断点以查看是否调用了它.
Please have a try if it's ok at your side. And to make sure your RoleNameInitializer is called, you can set breakpoint there to see if it's called or not.
这篇关于在基于Owin的项目中添加见解的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!