How can we display database query in azure application insights

不羁的心 提交于 2020-07-16 09:41:24

问题


Our application is using azure application insights. What I read is that, using application insights end to end tracking, we can even get the query which gets executed at database and how much time that query took.

But as shown in the screenshot, azure app insights shows me that there are 3 calls made to database but not the actual query that was executed against the database in those calls.

What I need to know is that what i need to do inorder to get the query that was executed against the database?


回答1:


Yes, the application insights can track sql query. But note that there are some changes in the latest version of application insights nuget package, which makes it does not automatically track sql query.

You can do it via the workaround below.

Assume you're using the .net core web project. Then you need to downgrade the Microsoft.ApplicationInsights.AspNetCore to version 2.12.0.

Here is my test result with version 2.12.0 of that package:

And also, you can use other workarounds, see here for more details.




回答2:


This is one of breaking changes as part of SDK 2.14.

You just need to simply modify ConfigureServices() with the line below for ASP.NET Core:

services.ConfigureTelemetryModule<DependencyTrackingTelemetryModule>((module, o) => { module.EnableSqlCommandTextInstrumentation = true; });

and for ASP.NET modify ApplicationInsights.config file:

<Add Type="Microsoft.ApplicationInsights.DependencyCollector.DependencyTrackingTelemetryModule, Microsoft.AI.DependencyCollector">, 
<EnableSqlCommandTextInstrumentation>true</EnableSqlCommandTextInstrumentation>
</Add>


来源:https://stackoverflow.com/questions/62588803/how-can-we-display-database-query-in-azure-application-insights

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!