如何为 Asp.Net Core 5.0 配置 Azure Application Insights 以仅发送 4% 的请求和 100% 的异常?
How to configure Azure Application Insights for Asp.Net Core 5.0 to send only 4% of Requests and 100% of Exceptions?
当我在 Azure 门户上使用数据采样设置时 — 它确实有效:减少了数据摄取量。
它只记录了 4% 的成功请求,这很好。
然而它只记录了所有异常的 4%。这很糟糕。因为怀念那孤单难得的例外。
如何为 Asp.Net Core 5.0 配置 Azure Application Insights 以仅发送 4% 的请求和 100% 的异常?
可以在Asp.Net核心Startup.ConfigureServices方法中完成吗?
我想你可以参考一下this chapter
提到在asp.net core中,我们可以通过builder.UseSampling(fixedSamplingPercentage);
禁用默认自适应采样,设置固定速率采样,根据sdk,我们还可以设置include和exclude选项
public static TelemetryProcessorChainBuilder UseSampling(this TelemetryProcessorChainBuilder builder, double samplingPercentage, string excludedTypes = null, string includedTypes = null);
我的代码在这里:
var configuration = app.ApplicationServices.GetService<TelemetryConfiguration>();
var builder = configuration.DefaultTelemetrySink.TelemetryProcessorChainBuilder;
// For older versions of the Application Insights SDK, use the following line instead:
// var builder = configuration.TelemetryProcessorChainBuilder;
// Using fixed rate sampling
double fixedSamplingPercentage = 10;
string excludedTypes = "Exception";
string includedTypes = "Request";
builder.UseSampling(fixedSamplingPercentage, excludedTypes, includedTypes);
builder.Build();
这里的每个请求都会导致我的测试出现异常,这里是应用程序洞察详细信息:
当我在 Azure 门户上使用数据采样设置时 — 它确实有效:减少了数据摄取量。
它只记录了 4% 的成功请求,这很好。
然而它只记录了所有异常的 4%。这很糟糕。因为怀念那孤单难得的例外。
如何为 Asp.Net Core 5.0 配置 Azure Application Insights 以仅发送 4% 的请求和 100% 的异常?
可以在Asp.Net核心Startup.ConfigureServices方法中完成吗?
我想你可以参考一下this chapter
提到在asp.net core中,我们可以通过builder.UseSampling(fixedSamplingPercentage);
禁用默认自适应采样,设置固定速率采样,根据sdk,我们还可以设置include和exclude选项
public static TelemetryProcessorChainBuilder UseSampling(this TelemetryProcessorChainBuilder builder, double samplingPercentage, string excludedTypes = null, string includedTypes = null);
我的代码在这里:
var configuration = app.ApplicationServices.GetService<TelemetryConfiguration>();
var builder = configuration.DefaultTelemetrySink.TelemetryProcessorChainBuilder;
// For older versions of the Application Insights SDK, use the following line instead:
// var builder = configuration.TelemetryProcessorChainBuilder;
// Using fixed rate sampling
double fixedSamplingPercentage = 10;
string excludedTypes = "Exception";
string includedTypes = "Request";
builder.UseSampling(fixedSamplingPercentage, excludedTypes, includedTypes);
builder.Build();
这里的每个请求都会导致我的测试出现异常,这里是应用程序洞察详细信息: