gpt4 book ai didi

azure - 如何禁用 Azure Application Insights .NetCore SDK 自动收集服务总线依赖项调用

转载 作者:行者123 更新时间:2023-12-02 07:02:11 25 4
gpt4 key购买 nike

我开发了.NetCore Web Job 并启用了应用程序洞察。但目前 Web 作业正在持续运行,并会生成过多的对 Azure Application Insights 的服务总线依赖项调用。因此,我想禁用服务总线依赖项调用以发送到应用程序见解。

函数.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 作业自动收集服务总线依赖项调用。

最佳答案

如果您使用 Application Insights for Worker Service package这可以使用以下代码来实现

services.AddApplicationInsightsTelemetryWorkerService(
new ApplicationInsightsServiceOptions
{
EnableDependencyTrackingTelemetryModule = false
});

关于azure - 如何禁用 Azure Application Insights .NetCore SDK 自动收集服务总线依赖项调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61953877/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com