【发布时间】:2020-02-19 06:51:32
【问题描述】:
我正在使用 ApplicationInsights.WorkerService nuget 包构建 .Net Core 后台服务。关于采样配置的文档说要参考这个: https://docs.microsoft.com/en-us/azure/azure-monitor/app/sampling#configure-sampling-settings
它显示了这一点:
public void Configure(IApplicationBuilder app, IHostingEnvironment env, TelemetryConfiguration configuration)
{
var builder = configuration.DefaultTelemetrySink.TelemetryProcessorChainBuilder;
// For older versions of the Application Insights SDK, use the following line instead:
// var builder = configuration.TelemetryProcessorChainBuilder;
// Using adaptive sampling
builder.UseAdaptiveSampling(maxTelemetryItemsPerSecond:5);
// Alternately, the following configures adaptive sampling with 5 items per second, and also excludes DependencyTelemetry from being subject to sampling.
// builder.UseAdaptiveSampling(maxTelemetryItemsPerSecond:5, excludedTypes: "Dependency");
// If you have other telemetry processors:
builder.Use((next) => new AnotherProcessor(next));
builder.Build();
// ...
}
现在在 HostBuilder 上,我看不到任何可以为我提供 TelemetryConfiguration 的扩展方法,nuget 的源代码也没有它: https://github.com/microsoft/ApplicationInsights-aspnetcore/blob/develop/NETCORE/src/Microsoft.ApplicationInsights.WorkerService/ApplicationInsightsExtensions.cs
那么如何在 HostBuilder 上获取 TelemetryConfiguration 或 TelemetryProcessorChainBuilder?目前它看起来像这样:
Host.CreateDefaultBuilder(args)
.ConfigureServices((hostContext, services) =>
{
services.AddHostedService<Worker>();
services.AddApplicationInsightsTelemetryWorkerService();
});
【问题讨论】:
标签: azure .net-core azure-application-insights