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

时间:2016-07-12 05:47:08

标签: azure azure-sql-database azure-application-insights

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

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

由于

1 个答案:

答案 0 :(得分:26)

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

Sampling, filtering and preprocessing telemetry in the Application Insights SDK

Request filtering in Application Insights with Telemetry Processor

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

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;
    }
}