Application Insights 未捕获 SQL 命令

问题描述 投票:0回答:1

希望有人能帮忙。

我在 Azure 中的 VM 上运行多个网站。它们都访问 Azure SQL 数据库。

我最近配置了 Application Insight,除了捕获 SQL 语句之外,所有事情都在正常工作。

我的网站是 ASP.NET Core 和 ASP.NET 的组合。

我已遵循文件

https://learn.microsoft.com/en-us/azure/azure-monitor/app/asp-net-dependency#advanced-sql-tracking-to-get-full-sql-query

https://learn.microsoft.com/en-us/azure/azure-monitor/app/application-insights-asp-net-agent?tabs=api-reference#enable-instrumentationengine

仪器似乎已正确安装并且似乎正在工作,但是当我收到依赖项事件时,我没有收到正在运行的 SQL 语句。

如果我用这个查询日志

dependencies | where success != "True" and type == "SQL" | take 10

我可以看到失败的事件,但没有失败的原因。

寻求任何帮助就是试图找出为什么 SQL 语句没有被捕获或修复它的某种方法。

谢谢

格雷格

azure azure-application-insights
1个回答
0
投票

我的网站是 ASP.NET Core 和 ASP.NET 的组合。

我尝试记录

ASP.Net
框架应用程序的 SQL 依赖关系。

检查以下步骤:

  • 我已参考此 MSDoc 并配置 Application Insights。

  • 从您共享的MSDoc中,我在

    ApplicationInsights.config
    文件中的
    <TelemetryModules>
    标签下添加了以下命令。

<EnableSqlCommandTextInstrumentation>true</EnableSqlCommandTextInstrumentation>
public TelemetryClient tl;
public ActionResult Index()
{
    tl = new TelemetryClient();
 
    var conn = ConfigurationManager.ConnectionStrings["AppInsightsConnection"].ConnectionString;
    var sql = new SqlConnection(conn);
    sql.Open();

    string cmdtxt = "Select * from TestData";
    var sqlCmd = new SqlCommand(cmdtxt, sql);

    string dependencyType = "My SQL Server";
    string dependencyName = "SQL Dependency from Framework App";
    var time = DateTimeOffset.Now;

    using (var depend = tl.StartOperation<DependencyTelemetry>(dependencyName))
    {
        depend.Telemetry.Type = dependencyType;
        depend.Telemetry.Data = cmdtxt;
        depend.Telemetry.Success = true;

        var er = sqlCmd.ExecuteReader();

        depend.Telemetry.Duration = DateTimeOffset.Now - time;
    }

    sql.Close();
    return View();
}

交易搜索:

enter image description here

  • 检查依赖项名称并单击它。

enter image description here

日志: enter image description here

  • 对于已部署的 Azure 应用服务,请确保启用
    SQL Commands
    =>
    App Service
    下的
    Application Insights

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.