SQL Cloud Service 上的 Web 应用 运行 App Insights 未收集命令文本
SQL Command text is not collected by App Insights for web app running on Cloud Service
已关注 standard installation guide from Microsoft
- 检查 "Send diagnostics data to Application Insights" 角色属性并将应用程序发布到 CS - 根本没有收集请求数据。
- 将 SDK 添加到项目并重新上传应用程序 - 获得了请求数据,但是收集的所有 SQL 依赖项完全没用 "Command Text" - "server name | database name".
但是,SQL如果安装了 Azure Status Monitor,则会在我的本地 IIS 上跟踪同一应用程序的命令。
我通过 RDP 连接到服务器,似乎 AI Status Monitor 已通过 Azure PaaS 诊断插件成功安装,但没有为 W3SVC 注册为 COR_PROFILER,所以它实际上什么都不做。
是否存在任何特定的配置开关来为云服务启用完整的SQL命令跟踪?
在this article中,我们可以发现,如果只将Application Insights SDK 添加到Web 应用程序项目中,依赖项诊断默认不会收集SQL 命令文本。
并且根据您的描述,installing Application Insights Status Monitor seems not help collect SQL command text. If possible, you can try to write code to send dependency information使用TrackDependency
,以下代码对我有用,请参考。
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);
}
详细信息SQL Application Insights 门户上的命令文本
似乎启用"Send diagnostics data to Application Insights"并向项目添加SDK应该足以收集依赖数据。
但是,Azure 云服务 PaaS 诊断插件 v1.10.1.1 中包含的状态监视器的当前安装程序已损坏。我尝试了以前版本插件 (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 上。已将此问题报告给 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}
原始 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
我获取命令文本(无需代码或任何更改)的唯一方法是使用状态监视器 v2,手动启用检测并添加 -connectionstring 而不是 -instrumentationkey 或 -instrumentationkeymap。
Install status monitor v2
Enable-ApplicationInsightsMonitoring (using -connectionstring, cannot get working using -instrumentationkey)
Enable-InstrumentationEngine
Restart iis (auto)
此外,如果网络服务器、服务器或应用程序被重新部署,它将停止显示命令文本。
已关注 standard installation guide from Microsoft
- 检查 "Send diagnostics data to Application Insights" 角色属性并将应用程序发布到 CS - 根本没有收集请求数据。
- 将 SDK 添加到项目并重新上传应用程序 - 获得了请求数据,但是收集的所有 SQL 依赖项完全没用 "Command Text" - "server name | database name".
但是,SQL如果安装了 Azure Status Monitor,则会在我的本地 IIS 上跟踪同一应用程序的命令。
我通过 RDP 连接到服务器,似乎 AI Status Monitor 已通过 Azure PaaS 诊断插件成功安装,但没有为 W3SVC 注册为 COR_PROFILER,所以它实际上什么都不做。
是否存在任何特定的配置开关来为云服务启用完整的SQL命令跟踪?
在this article中,我们可以发现,如果只将Application Insights SDK 添加到Web 应用程序项目中,依赖项诊断默认不会收集SQL 命令文本。
并且根据您的描述,installing Application Insights Status Monitor seems not help collect SQL command text. If possible, you can try to write code to send dependency information使用TrackDependency
,以下代码对我有用,请参考。
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);
}
详细信息SQL Application Insights 门户上的命令文本
似乎启用"Send diagnostics data to Application Insights"并向项目添加SDK应该足以收集依赖数据。
但是,Azure 云服务 PaaS 诊断插件 v1.10.1.1 中包含的状态监视器的当前安装程序已损坏。我尝试了以前版本插件 (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 上。已将此问题报告给 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}
原始 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
我获取命令文本(无需代码或任何更改)的唯一方法是使用状态监视器 v2,手动启用检测并添加 -connectionstring 而不是 -instrumentationkey 或 -instrumentationkeymap。
Install status monitor v2
Enable-ApplicationInsightsMonitoring (using -connectionstring, cannot get working using -instrumentationkey)
Enable-InstrumentationEngine
Restart iis (auto)
此外,如果网络服务器、服务器或应用程序被重新部署,它将停止显示命令文本。