Tag: azure application insight

Application Insights不记录自定义事件

我在C#Controller中的ASP.NET核心应用程序中设置了Application Insights,它正在记录基本数据,如页面视图,响应时间等。但我想创建一些自定义事件并记录这些事件,但我无法获得任何他的自定义事件将显示在Azure门户中。 目前我正在使用Application Insights的免费版本。 非常直截了当 var appInsights = new TelemetryClient(); appInsights.TrackEvent(eventName, properties); eventName是一个字符串,包含我想要跟踪的自定义事件,属性是一个字典来跟踪一些其他属性。 在我运行应用程序并点击这些行几次后,我可以转到azure门户网站查看基本信息,但是当我进行搜索时,它说有0个自定义事件并通过以下方式搜索任何自定义事件name不返回任何结果。 我有一个类,下面有遥测的东西 public class ApplicationInsightsTracker : IApplicationTracker { private readonly TelemetryClient AppInsights = new TelemetryClient(); public void TrackEvent(string eventName, string userName, Dictionary properties = null) { AppInsights.Context.User.AccountId = userName; TrackEvent(eventName, properties); } public void TrackRequest(string eventName, string userName, TimeSpan elapsed, Dictionary properties […]

如何在Azure应用程序洞察中忽略localhost

我最近开始主持我的第一个生产应用程序 我继续并激活应用程序见解,我认为这些有很多价值。 但是,我得到了来自开发人员方面的统计信息,例如日志记录来自localhost:xxxx的条目。 我确定有办法解决这个问题。 谁能给我一些指示吗?

如何从控制台应用程序跟踪MongoDB请求

我有一个用C#编写的Console Application项目,我已经使用以下NuGet包添加了Application Insights。 Microsoft.ApplicationInsights Microsoft.ApplicationInsights.Agent.Intercept Microsoft.ApplicationInsights.DependencyCollector Microsoft.ApplicationInsights.NLogTarget Microsoft.ApplicationInsights.PerfCounterCollector Microsoft.ApplicationInsights.Web Microsoft.ApplicationInsights.WindowsServer Microsoft.ApplicationInsights.WindowsServer.TelemetryChannel 我已经在配置文件中配置了InstrumentationKey,并且我在启动时使用以下代码启动了TelemetryClient: var telemetryClient = new TelemetryClient(); telemetryClient.Context.User.Id = Environment.UserName; telemetryClient.Context.Session.Id = Guid.NewGuid().ToString(); telemetryClient.Context.Device.OperatingSystem = Environment.OSVersion.ToString(); 一切都运行良好,除了AI没有捕获任何发送到Mongo的请求,我可以看到请求在“应用程序映射”中发送到SQL服务器,但没有任何其他外部请求的迹象。 有什么方法可以看到对Mongo的请求的遥测? 编辑 – 感谢Peter Bons,我最终得到了以下几个像魅力一样的东西,让我能够区分成功和失败: var telemetryClient = new TelemetryClient(); var connectionString = connectionStringSettings.ConnectionString; var mongoUrl = new MongoUrl(connectionString); var mongoClientSettings = MongoClientSettings.FromUrl(mongoUrl); mongoClientSettings.ClusterConfigurator = clusterConfigurator => { […]

Windows 10 Universal App(UAP)中的FileNotFoundException

我开发并发布了Windows通用应用程序。 要跟踪exception和应用程序使用情况,我启用了Application Insights,我可以使用以下调用堆栈找到FileNotFoundException: at Mindapp!+0x6e58d1 at Mindapp!+0x6ee2a4 at Mindapp!+0x86bd63 — End of stack trace from previous location where exception was thrown — at Mindapp!+0x6e58d1 at Mindapp!+0x6ee2a4 at Mindapp!+0x86d250 — End of stack trace from previous location where exception was thrown — at Mindapp!+0x6e58d1 at Mindapp!+0x6ee2a4 at Mindapp!+0x880c5e — End of stack trace from previous location […]

使用Application Insights时,AreaRegistration.RegisterAllAreas()永远不会完成

我使用Visual Studio 2013 Update 4创建了一个新的ASP.net MVC应用程序,并选中该框以使用Application Insights。 当我尝试运行应用程序(有或没有调试)时,网站永远不会加载。 当我调试它时,我注意到它在线路上遇到了Global.asax.cs: AreaRegistration.RegisterAllAreas(); 我已经看了几个问题的答案,包括这个问题: AreaRegistration.RegisterAllAreas()不是注册区域规则 这并没有解决我的问题。 我删除了这个答案中的文件夹中的所有内容,并重新启动了visual studio,重新启动了我的电脑,无论我做什么,这种方法都会永远挂起。 它似乎并不慢,因为我已经等了5分多钟而且还没有完成。 有没有其他人遇到这种情况,除了删除此调用之外我该如何解决? 如果我注释掉了Application Insights的Http Module注册,那么这个方法会立即完成,但是一旦我添加它们,该方法就会再次挂起。 AreaRegistration.RegisterAllAreas()调用和Application Insights似乎存在一些问题。 <!– –> <!– –>

将Application Insights与unit testing结合使用?

我有一个MVC网络应用程序,我正在使用Simple Injector进行DI。 我的几乎所有代码都包含在unit testing中。 但是,现在我在某些控制器中添加了一些遥测调用,我在设置依赖项时遇到了麻烦。 遥测调用用于将指标发送到Microsoft Azure托管的Application Insights服务。 该应用程序未在Azure中运行,只是一个带有ISS的服务器。 AI门户网站会告诉您有关应用程序的各种信息,包括您使用遥测库发送的任何自定义事件。 因此,控制器需要一个Microsoft.ApplicationInsights.TelemetryClient实例,该实例没有接口,并且是一个带有2个构造函数的密封类。 我试着像这样注册它(混合生活方式与这个问题无关,我只是为了完整性而把它包括在内): // hybrid lifestyle that gives precedence to web api request scope var requestOrTransientLifestyle = Lifestyle.CreateHybrid( () => HttpContext.Current != null, new WebRequestLifestyle(), Lifestyle.Transient); container.Register(requestOrTransientLifestyle); 问题是,由于TelemetryClient有2个构造函数,SI抱怨并且validation失败。 我找到了一篇文章,展示了如何覆盖容器的构造函数解析行为,但这似乎相当复杂。 首先,我想备份并提出这个问题: 如果我没有让TelemetryClient成为一个注入的依赖项(只是在类中创建一个新的),那么在每次运行unit testing时是否会将遥测发送到Azure,从而产生大量错误数据? 或者,Application Insights足够聪明,知道它是在unit testing中运行,而不是发送数据? 对此问题的任何“见解”将不胜感激! 谢谢

将Application Insights与ILoggerFactory一起使用

我正在尝试将exception记录到Application Insights。 我通过直接调用TelemetryClient.TrackException成功完成了这项工作。 但是,我想在我的代码中抽象出来,以防我将来想要登录其他平台,所以我想只关注ILogger接口。 我发现你可以使用ILoggerFactory.AddApplicationInsights ( 这里实现),但不管我做了什么,我都没有看到日志在ApplicationInsights中出现。 以下是我的代码: Startup.cs IConfigurationRoot Configuration { get; set; } ILoggerFactory LoggerFactory { get; set; } IServiceProvider ServiceProvider { get; set; } public Startup( IHostingEnvironment hostingEnvironment, ILoggerFactory loggerFactory ) { this.LoggerFactory = loggerFactory; string configurationFilePath = “abc.json”; this.Configuration = new ConfigurationBuilder() .SetBasePath( hostingEnvironment.ContentRootPath ) .AddJsonFile( configurationFilePath, optional: true, reloadOnChange: true […]

如何在Azure上的Application Insights中将exception链接到请求?

我们在Azure上使用Owin来提供REST服务,并且必须直接向Application Insights报告。 我们想记录exception和请求。 现在我们有这个: using AppFunc = Func<IDictionary, Task>; public class InsightsReportMiddleware { readonly AppFunc next; readonly TelemetryClient telemetryClient; public InsightsReportMiddleware(AppFunc next, TelemetryClient telemetryClient) { if (next == null) { throw new ArgumentNullException(“next”); } this.telemetryClient = telemetryClient; this.next = next; } public async Task Invoke(IDictionary environment) { var sw = new Stopwatch(); sw.Start(); await next(environment); […]

在Application Insights指标中为每个请求添加自定义属性

我喜欢将自定义属性添加到Application Insights 为我的应用程序的每个请求采取的指标。 例如,我想添加用户登录和租户代码,例如我可以在Azure门户中对指标进行分段/分组。 相关的doc页面似乎是这样的: 设置默认属性值 但是示例是针对事件(即gameTelemetry.TrackEvent(“WinGame”); ),而不是针对HTTP请求: var context = new TelemetryContext(); context.Properties[“Game”] = currentGame.Name; var gameTelemetry = new TelemetryClient(context); gameTelemetry.TrackEvent(“WinGame”); 我的问题: 什么是请求的相关代码,因为我目前没有特定的代码(它似乎由App Insights SDK自动管理):只是创建一个TelemetryContext足够吗? 我是否应该创建TelemetryClient ,如果是,我应该将其链接到当前请求吗? 怎么样 ? 我应该把这段代码放在哪里? 在global.asax的Application_BeginRequest方法中可以吗?

在Application Insights中查看POST请求正文

是否可以在Application Insights中查看POST请求正文? 我可以看到请求详细信息,但不能查看应用程序洞察中发布的有效负载。 我是否需要通过编码来跟踪这个问题? 我正在构建一个MVC核心1.1 Web Api。