[英]How to configure Azure Application Insights for Asp.Net Core 5.0 to send only 4% of Requests and 100% of Exceptions?
When I use the Data sampling settings on Azure portal — it really works: reduces the amount of data ingestion.当我在 Azure 门户上使用数据采样设置时,它确实有效:减少了数据摄取量。
It logs only 4% of the successful requests and this is good.它只记录 4% 的成功请求,这很好。
However it logs only 4% of the all exceptions.然而,它只记录了所有异常的 4%。 And this is bad.
这很糟糕。 Because I miss the lonely and rare exceptions.
因为我想念孤独和罕见的例外。
How to configure Azure Application Insights for Asp.Net Core 5.0 to send only 4% of Requests and 100% of Exceptions?如何将 Azure Application Insights for Asp.Net Core 5.0 配置为仅发送 4% 的请求和 100% 的异常?
Can it be done in Asp.Net Core Startup.ConfigureServices method?可以在 Asp.Net Core Startup.ConfigureServices 方法中完成吗?
I think you can refer to this chapter我想你可以参考这一章
It mentioned that in asp.net core, we can disable the default adaptive sampling and set fixed-rate sampling by builder.UseSampling(fixedSamplingPercentage);
它提到在asp.net内核中,我们可以禁用默认的自适应采样并通过builder设置固定速率采样。
builder.UseSampling(fixedSamplingPercentage);
, and according to the sdk, we can also set include and exclude options ,并且根据sdk,我们还可以设置包含和排除选项
public static TelemetryProcessorChainBuilder UseSampling(this TelemetryProcessorChainBuilder builder, double samplingPercentage, string excludedTypes = null, string includedTypes = null);
my code here:我的代码在这里:
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();
Each request here will lead to an exception in my test, and here's the application insights detail:这里的每个请求都会导致我的测试出现异常,这是应用程序洞察力的详细信息:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.