如何在使用OWIN的WebApi项目上启用Application Insights服务器遥测? [英] How do I enable Application Insights server telemetry on WebApi project that uses OWIN?

查看:76
本文介绍了如何在使用OWIN的WebApi项目上启用Application Insights服务器遥测?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们在生产中的几个项目遇到很多问题(读取响应时间长),因此想确切地了解服务器上正在发生的事情.然后,我通过遵循

We are having a bunch of problems (read long response times) with a couple of projects in production and wanted to see exactly what was happening on the server. I then proceeded to add Application Insights to all of our projects by following this article. The problem is that both of our WebAPI projects are not sending server data to the Azure portal, while all other projects (MVC 5) are.

这是我在Azure上访问相应的Application Insights刀片时显示的内容:

This is what is shown when I access the corresponding Application Insights blade on Azure:

我试图在Azure VM的Application Insights状态监视器中禁用和重新启用数据收集,在向API发出请求的同时重新启动IIS几次,都无济于事.在MVC项目上启用它后,当我在网站上打开页面时,几乎可以立即在Azure门户上看到数据.

I tried to disable and re-enable data collection in the Application Insights Status Monitor in our Azure VMs, restarted IIS a few times all while making requests to the API, to no avail. When I enable it on a MVC project, I can see the data almost instantly on the Azure portal when I open pages on the site.

当我看到没有从Azure虚拟机发送这些特定项目的数据时,我尝试在我们的开发环境中设置相同的集合,该环境托管在我们自己的基础结构中,并且重复同样的情况,裁定排除了这与Azure VM中托管的项目有关的可能性.

When I saw that data was not being sent from our Azure VMs for these specific projects, I tried to setup the same collections in our dev environment, which is hosted in our own infrastructure, and the exact same situation repeated itself, ruling out the possibility that this is related to projects being hosted in Azure VMs.

我不确定是什么原因阻止了这些项目向Azure发送数据,但是通过查看工作项目与非工作项目之间的关系,我认为这可能与我们的WebAPI项目使用新的OWIN管道,而MVC是标准的MVC项目.我检查了两个项目类型的web.config文件和bin文件夹,它们似乎已由Insights Monitor正确修改(我可以看到将相同的新dll添加到bin文件夹中,并将相同的http模块添加到Web中.配置).

I'm not exactly sure what is preventing these projects from sending data to Azure, but by taking a look at the working projects vs the non working ones, I think it might be somehow related to the fact that our WebAPI projects use the new OWIN pipeline while the MVC ones are standard MVC projects. I checked both the web.config file and the bin folder for both project types and they seem to be modified correctly by the Insights Monitor (I can see the same new dlls added to the bin folder and the same http module added to the web.config).

考虑到这一点,如何使用Application Insights为依赖OWIN/Katana管道的WebAPI项目启用服务器端遥测?在这种情况下,我该怎么做才能找出导致项目无法发送数据到Azure的确切原因?

With that in mind, how do I enable server side telemetry using Application Insights for WebAPI projects that rely on the OWIN/Katana pipeline? What could I do to find out what exactly is causing the project to not send data to Azure in this case?

推荐答案

AI使用httpmodule收集关于开始请求的信息,并在结束请求时发送信息.如此处所述,Owin/Katana使用中间件在不同阶段执行逻辑.由于大多数AI自动收集逻辑是内部的,因此您无法在中间件中重用它.但是您可以自己检测代码. 从代码中创建TelemetryClient,然后开始发送请求,跟踪和异常(如此处所述)

AI uses httpmodule to collect information on begin request and send it on end request. As described here Owin/Katana uses middelwares to execute logic on a different stages. As most of AI auto collection logic is internal you cannot reuse it in your middleware. But you can instrument your code yourself. Create TelemetryClient from your code and start sending Request, Traces and Exceptions (like described here)

这篇关于如何在使用OWIN的WebApi项目上启用Application Insights服务器遥测?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆