简体   繁体   English

如何将 Azure Application Insights for Asp.Net Core 5.0 配置为仅发送 4% 的请求和 100% 的异常?

[英]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.

相关问题 如何在Azure上的Application Insights中将异常链接到请求? - How to link exceptions to requests in Application Insights on Azure? 如何从 ASP.NET Core 应用程序将应用程序洞察数据发布到 REST API 而不是 Azure? - How to post application insights data to REST API instead of Azure from ASP.NET Core application? 具有Application Insights的asp.net core 2记录器 - asp.net core 2 Logger with Application Insights 如何为 ASP.NET Core 3.1 配置 Azure App Service 应用程序设置? - How to configure Azure App Service application settings for ASP.NET Core 3.1? 如何在 Asp.Net Core 应用程序中配置 MassTransit Saga - How to configure MassTransit Saga in Asp.Net Core application 如何在 ASP.NET Core 5.0 中处理来自客户端的双重请求? - How to handle double requests from the client in ASP.NET Core 5.0? 来自 ASP.NET Core 身份的 Application Insights 用户 ID - Application Insights User ID from ASP.NET Core identity Application Insights 开发人员模式在 ASP.NET 核心 3.1 中不起作用 - Application Insights Developer Mode not working in ASP.NET Core 3.1 Azure DevOps 构建管道中的 ASP.NET 核心 web 应用程序控制器需要 100% 的代码覆盖率 - Require 100% code coverage for ASP.NET Core web application controllers in Azure DevOps build pipeline 如何使用 ASP.NET Core 5.0 MVC 上传图片 - How to upload an image with ASP.NET Core 5.0 MVC
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM