.net core Application Insights SDK-仅收集特定依赖项?

.net core Application Insights SDK-仅收集特定依赖项?,.net-core,azure-application-insights,.net Core,Azure Application Insights,这显示了如何跟踪我的控制台应用程序上的依赖项。但是默认情况下,我只想收集Http依赖项。我想禁用SQL Server依赖项和其他依赖项的集合。我怎样才能做到这一点?可以过滤(并删除)您需要使用的内容 大概是这样的: using Microsoft.ApplicationInsights.Channel; using Microsoft.ApplicationInsights.Extensibility; public class DependencyFilter : ITelemetryPro

这显示了如何跟踪我的控制台应用程序上的依赖项。但是默认情况下,我只想收集Http依赖项。我想禁用SQL Server依赖项和其他依赖项的集合。我怎样才能做到这一点?

可以过滤(并删除)您需要使用的内容

大概是这样的:

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

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

    // next will point to the next TelemetryProcessor in the chain.
    public DependencyFilter(ITelemetryProcessor next)
    {
        this.Next = next;
    }

    public void Process(ITelemetry item)
    {
        // To filter out an item, return without calling the next processor.
        if (!OKtoSend(item)) { return; }

        this.Next.Process(item);
    }

    // Example: replace with your own criteria.
    private bool OKtoSend (ITelemetry item)
    {
        var dependency = item as DependencyTelemetry;
        if (dependency == null) return true;

        return dependency.Type.Contains("HTTP");
    }
}

可以过滤掉(并删除)您需要使用的内容

大概是这样的:

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

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

    // next will point to the next TelemetryProcessor in the chain.
    public DependencyFilter(ITelemetryProcessor next)
    {
        this.Next = next;
    }

    public void Process(ITelemetry item)
    {
        // To filter out an item, return without calling the next processor.
        if (!OKtoSend(item)) { return; }

        this.Next.Process(item);
    }

    // Example: replace with your own criteria.
    private bool OKtoSend (ITelemetry item)
    {
        var dependency = item as DependencyTelemetry;
        if (dependency == null) return true;

        return dependency.Type.Contains("HTTP");
    }
}