如何禁用由Azure Application Insights .NetCore SDK自动收集服务总线依赖关系的调用

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

我已经开发了.NetCore Web Job并启用了应用程序见解。但是当前,Web作业正在连续运行,并生成了对Azure Application Insights的过多服务总线依赖项调用。因此,我想禁用为总线依赖性调用提供服务以发送给应用程序见解。

Functions.cs

        [NoAutomaticTrigger]
    public async Task ProcessMessagesFromServiceBusQueue()
    {
        QueueRuntimeInfo queueInfo = null;
        while (true)
        {
            try
            {
                queueInfo = await _serviceBusManagementClient.GetQueueRuntimeInfoAsync(queueName);
                var count= queueInfo.MessageCountDetails.ActiveMessageCount > 0;
            }
            catch (ServiceBusTimeoutException)
            {
            }
        }
    }

我已经尝试通过使用以下代码来启用自适应采样。但是仍然会产生过多的依赖关系调用。

     s.Configure<TelemetryConfiguration>((o) =>
            {
                o.TelemetryInitializers.Add(new OperationCorrelationTelemetryInitializer());
                // Alternately, the following configures adaptive sampling with 2 items per second, and also excludes DependencyTelemetry from being subject to sampling.
                o.TelemetryProcessorChainBuilder.UseAdaptiveSampling(maxTelemetryItemsPerSecond: 1, excludedTypes: "Trace;Exception");
            });

此外,尝试使用此代码删除所有依赖项调用。但是它没有按预期工作。

private static IConfiguration GetConfiguration(ServiceCollection services)
    {
        var environment = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT");
        // build config
        var configuration = new ConfigurationBuilder()
           .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
           .AddJsonFile($"appsettings.{environment}.json", optional: true, reloadOnChange: true)
           .AddEnvironmentVariables()
           .Build();
        services.AddApplicationInsightsTelemetry(configuration);
        var dependencyTrackingService = services.FirstOrDefault<ServiceDescriptor>(t => t.ImplementationType == typeof(DependencyTrackingTelemetryModule));
        if (dependencyTrackingService != null)
        {
            services.Remove(dependencyTrackingService);
        }
        return configuration;
    }

所以,任何人都可以建议如何禁用从.NetCore Web Job自动收集服务总线依赖项调用的方法。

azure .net-core azure-application-insights azure-webjobs
1个回答
0
投票

[请让我们知道您使用的是3.x还是2.x版本的webjobs SDK?

对于过滤掉服务总线依赖项调用,您可以尝试实现应用程序见解的自定义telemetry processor。在自定义函数中,编写代码以确定遥测数据是否与服务总线相关,然后确定将其保留或过滤掉。

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