App Insights不会为在Cloud Service

时间:2017-09-26 13:03:07

标签: azure azure-cloud-services azure-application-insights

关注standard installation guide from Microsoft

  • 选中角色属性中的“将诊断数据发送到Application Insights”并将应用程序发布到CS - 根本不收集任何请求数据。
  • 为项目添加了SDK并重新上传了应用程序 - 获取了请求数据,但所有SQL依赖项都收集了完全没用的“命令文本” - “服务器名称|数据库名称”。

但是,如果安装了Azure状态监视器,则会在本地IIS上跟踪同一应用程序的SQL命令。

我通过RDP连接到服务器,似乎Azure状态监视器由Azure PaaS Diagnostics插件成功安装,但未注册为W3SVC的COR_PROFILER,因此它实际上什么都不做。

是否存在任何特定的配置切换以启用云服务的完整SQL命令跟踪?

3 个答案:

答案 0 :(得分:1)

我获得命令文本的唯一方法(没有代码或任何更改)是使用状态监视器 v2,手动启用检测并添加 -connectionstring 而不是 -instrumentationkey 或 -instrumentationkeymap。

Install status monitor v2
Enable-ApplicationInsightsMonitoring (using -connectionstring, cannot get working using -instrumentationkey)
Enable-InstrumentationEngine
Restart iis (auto)

此外,如果重新部署网络服务器、服务器或应用程序,它将停止显示命令文本。

答案 1 :(得分:0)

this article中,我们可以发现,如果只将Application Insights SDK添加到Web应用程序项目中,则Dependencies诊断程序默认情况下不会收集SQL命令文本。

enter image description here

根据您的描述,installing Application Insights Status Monitor似乎无法帮助收集SQL命令文本。如果可能,您可以尝试使用TrackDependency write code to send dependency information,以下代码适合我,请参阅。

var startTime = DateTime.UtcNow;

var timer = System.Diagnostics.Stopwatch.StartNew();
try
{
    SqlConnection con = new SqlConnection("{connect_string}");

    commendtext = "SELECT COUNT(1) FROM dbo.AspNetUsers";

    SqlCommand com = new SqlCommand(commendtext, con);

    con.Open();

    int n = (int)com.ExecuteScalar();

    con.Close();

    success = n > 0 ? true : false;

}
finally
{
    timer.Stop();
    telemetry.TrackDependency("SQL", "SQL: tcp:{server_name}.database.windows.net,1433 | {database_name}", ":{server_name}.database.windows.net", commendtext, startTime, timer.Elapsed, "{result_code}", success);
}

详细说明Application Insights门户网站上的SQL命令文本

enter image description here

答案 2 :(得分:0)

似乎启用"将诊断数据发送到Application Insights"并将SDK添加到项目应该足以收集依赖数据。

但是,Azure Cloud Service PaaS诊断插件v1.10.1.1中包含的Status Monitor的当前安装程序已损坏。我尝试了以前版本的插件(v.1.10.0.0)中的安装程序 - 它完美无缺。

从最新版本的插件运行\ StatusMonitor \ ApplicationInsightsAgent.msi会记录以下异常:

Calling custom action CustomActions!CustomActions.CustomActions.SetEnvironmentVariables
Error: could not load custom action class CustomActions.CustomActions from assembly: CustomActions
System.IO.FileLoadException: Could not load file or assembly 'CustomActions, Version=2.4.0.18059, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. Strong name validation failed. (Exception from HRESULT: 0x8013141A)
File name: 'CustomActions, Version=2.4.0.18059, Culture=neutral, PublicKeyToken=31bf3856ad364e35' ---> System.Security.SecurityException: Strong name validation failed. (Exception from HRESULT: 0x8013141A)

我解压缩了CustomActions.dll,并通过sn。

检查了它的强名称
sn.exe -vf CustomActions.dll

CustomActions.dll is a delay-signed or test-signed assembly

同样检查v1.10.0.0中的CustomActions.dll显示

Assembly 'CustomActions.dll' is valid

显然,MS中有人忘记在发布之前签署该DLL,因此不再在CS VM上正确安装Status Monitor。据报道,对于MS支持,希望他们能尽快解决这个问题。

解决方法可能是在角色启动时手动添加缺少的注册表项,而W3SVC尚未启动:

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\W3SVC\@Environment 

类型为多字符串值的值

COR_ENABLE_PROFILING=1
COR_PROFILER={324F817A-7420-4E6D-B3C1-143FBED6D855}
MicrosoftInstrumentationEngine_Host={CA487940-57D2-10BF-11B2-A3AD5A13CBC0}

Raw reg文件是:

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\W3SVC]
"Environment"=hex(7):43,00,4f,00,52,00,5f,00,45,00,4e,00,41,00,42,00,4c,00,45,\
  00,5f,00,50,00,52,00,4f,00,46,00,49,00,4c,00,49,00,4e,00,47,00,3d,00,31,00,\
  00,00,43,00,4f,00,52,00,5f,00,50,00,52,00,4f,00,46,00,49,00,4c,00,45,00,52,\
  00,3d,00,7b,00,33,00,32,00,34,00,46,00,38,00,31,00,37,00,41,00,2d,00,37,00,\
  34,00,32,00,30,00,2d,00,34,00,45,00,36,00,44,00,2d,00,42,00,33,00,43,00,31,\
  00,2d,00,31,00,34,00,33,00,46,00,42,00,45,00,44,00,36,00,44,00,38,00,35,00,\
  35,00,7d,00,00,00,4d,00,69,00,63,00,72,00,6f,00,73,00,6f,00,66,00,74,00,49,\
  00,6e,00,73,00,74,00,72,00,75,00,6d,00,65,00,6e,00,74,00,61,00,74,00,69,00,\
  6f,00,6e,00,45,00,6e,00,67,00,69,00,6e,00,65,00,5f,00,48,00,6f,00,73,00,74,\
  00,3d,00,7b,00,43,00,41,00,34,00,38,00,37,00,39,00,34,00,30,00,2d,00,35,00,\
  37,00,44,00,32,00,2d,00,31,00,30,00,42,00,46,00,2d,00,31,00,31,00,42,00,32,\
  00,2d,00,41,00,33,00,41,00,44,00,35,00,41,00,31,00,33,00,43,00,42,00,43,00,\
  30,00,7d,00,00,00,00,00