【问题标题】:How to make application insights ignore cancel如何使应用程序洞察力忽略取消
【发布时间】:2020-01-21 17:29:49
【问题描述】:

当用户按下多种类型的取消按钮时,会给出 500 响应代码。

不会导致性能问题,只是会导致应用程序见解混乱。

任何过滤掉它的方法都会有所帮助。

遥测中也没有显示任何可共享的内容,只有使用 500 代码和时间调用的 API 方法。分享那个截图。

【问题讨论】:

  • 您的答案可能会受益于额外的上下文以使其更清晰。
  • 项目是什么样的? .NET core web api 还是其他?

标签: azure-application-insights


【解决方案1】:

既然你知道响应码是500,你可以使用telemetry processor来过滤掉这些码500的请求。

假设您使用的是.NET core,您可以按照以下步骤操作:

创建一个实现ITelemetryProcessor的类,然后过滤掉响应码为500的请求(或更多条件根据您的需要)。示例代码如下所示:

public class IgnoreCancelFilter : ITelemetryProcessor
{
    private ITelemetryProcessor Next { get; set; }

    // next will point to the next TelemetryProcessor in the chain.
    public IgnoreCancelFilter(ITelemetryProcessor next)
    {
        this.Next = next;
    }

    public void Process(ITelemetry item)
    {
        var request = item as RequestTelemetry;

        if (request != null &&
        request.ResponseCode.Equals("500", StringComparison.OrdinalIgnoreCase))
        {
        // To filter out an item, return without calling the next processor.
        return;
        }

    // Send everything else
    this.Next.Process(item);
   }

}

然后,在 Startup.cs 类的 ConfigureServices 方法中注册它。

public void ConfigureServices(IServiceCollection services)
{
    // ...
    services.AddApplicationInsightsTelemetry();
    services.AddApplicationInsightsTelemetryProcessor<IgnoreCancelFilter>();

}

如果编程语言不是.NET core,可以在这个article找到.NET framework/js等合适的方法。

【讨论】:

  • 这种方法的问题是它阻塞了所有的 500 错误。在现实世界中,我希望看到真正需要解决的 500 个问题。寻找一种过滤取消请求的方法,这导致天蓝色认为这是一个错误,但事实并非如此。
  • @ManaswiB,是的,这会阻止所有 500 个错误。我的建议是,当出现这种 500 取消错误时,你可以调试一下,看看有没有其他属性可以用来识别它。
猜你喜欢
  • 2020-04-12
  • 1970-01-01
  • 2020-11-17
  • 1970-01-01
  • 2016-09-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多