代码之家  ›  专栏  ›  技术社区  ›  David Klempfner

如何在Application Insights中获得完整的SQL查询

  •  0
  • David Klempfner  · 技术社区  · 3 年前

    我刚刚看了视频 https://www.youtube.com/watch?v=TV1u6UoBRwk 并看到了关于端到端交易的部分。 我用它来追踪一个耗时1.8分钟的SQL查询。

    查询被截断(可能是因为EF正在生成超长查询)。

    有什么方法可以从Application Insights获得完整的查询吗? enter image description here

    0 回复  |  直到 3 年前
        1
  •  0
  •   Harshitha    3 年前
    • 默认情况下,SQL集合设置为关闭。我们需要在Azure门户中启用它。
    • 要获得完整的SQL查询,我们需要启用 SQL Commands 在我们部署的 App Service => Application Insights

    enter image description here

    • 在中添加以下代码行 Program.cs 文件,如果是 .NET Core 应用程序。
    builder.Services.ConfigureTelemetryModule<DependencyTrackingTelemetryModule>((module, o) => { module.EnableSqlCommandTextInstrumentation = true; });
    
    • 如果是的话 .NET Framework 应用程序,在中添加以下行 TelemetryModules 中的部分 ApplicationInsights.config 文件(当我们在Visual Studio中添加Application Insights时生成。
    <Add Type="Microsoft.ApplicationInsights.DependencyCollector.DependencyTrackingTelemetryModule, Microsoft.AI.DependencyCollector">, 
    <EnableSqlCommandTextInstrumentation>true</EnableSqlCommandTextInstrumentation>
    </Add>
    

    参考文献取自 MSDoc GitHub