App Insights:禁用SQL依赖关系遥测

Sam*_*am7 16 azure azure-application-insights azure-sql-database

我正在将Azure Application Insights用于网站(Azure应用服务).在那,我正在使用集群Umbraco设置和hangfire.这两个人每分钟都在不断地访问数据库,并充斥着我的"App Insights".

所以我的问题是,如何禁用Sql Dependency Tracker?我看过ApplicationInsights.config并找不到任何明显的东西.我可以看到Microsoft.ApplicationInsights.DependencyCollector哪个可能是负责任的,但我不想删除所有类型的依赖遥测,只有 sql.

谢谢

Jam*_*SFT 26

这里最好的选择是使用遥测处理器来过滤掉某些类型的依赖请求.请查看以下这些资源以获取信息.

Application Insights SDK中的采样,过滤和预处理遥测

使用遥测处理器在Application Insights中请求过滤

示例处理器可能如下所示.

using Microsoft.ApplicationInsights.Channel;
using Microsoft.ApplicationInsights.Extensibility;
using Microsoft.ApplicationInsights.DataContracts;

public class NoSQLDependencies : ITelemetryProcessor
{
    private ITelemetryProcessor Next { get; set; }

    // Link processors to each other in a chain.
    public NoSQLDependencies(ITelemetryProcessor next)
    {
        this.Next = next;
    }
    public void Process(ITelemetry item)
    {
        if (IsSQLDependency(item)) { return; }
        this.Next.Process(item);
    }

    private bool IsSQLDependency(ITelemetry item)
    {
        var dependency = item as DependencyTelemetry;
        if (dependency?.DependencyTypeName == "SQL")
        {
            return true;
        }
        return false;
    }
}
Run Code Online (Sandbox Code Playgroud)

  • 在https://github.com/Microsoft/ApplicationInsights-dotnet-server/blob/386470e973698327e0873ba8b58f35878f6f0bc1/Src/DependencyCollector/Shared/Implementation/RemoteDependencyConstants.cs找到源代码公共const字符串SQL ="SQL"; public const string HTTP ="Http"; public const string AzureBlob ="Azure blob"; public const string AzureTable ="Azure table"; public const string AzureQueue ="Azure queue"; (6认同)
  • 可以只禁用hangfire sql.我还想看标准的SQL查询? (3认同)
  • "DependencyTypeName"和"DependencyKind"现在都已过时了.使用'Type` (3认同)