【问题标题】:How can I suppress an http error 440 in Azure Application Insights如何在 Azure Application Insights 中抑制 http 错误 440
【发布时间】:2019-11-09 20:29:32
【问题描述】:

Azure Application Insights 是一个很棒的工具,但我们遇到了一些虚假错误。具体来说,当用户在我们的 Web 应用程序上超时时,该应用程序会抛出一个 http 440 错误(我猜这是 MS 特定的代码),即会话已过期。这是一种误报,我不想跟踪这些,也不想从他们那里得到警报。

有没有办法在 Application Insights 中抑制这种情况,或者我必须在代码中做些什么才能做到这一点?

如果它们不能被抑制,我想如果我可以从那里过滤掉 440,我可以设置一个警报。

【问题讨论】:

标签: azure azure-application-insights http-error


【解决方案1】:

你可以使用ITelemetryProcessor来过滤掉http错误440:

在您的 Web 项目中,添加类似 MyErrorFilter 的类:

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

        public MyErrorFilter(ITelemetryProcessor next)
        {
           this.Next = next;
        }

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

            if (request != null &&
            request.ResponseCode.Equals("440", StringComparison.OrdinalIgnoreCase))
            {
                // To filter out an item, just terminate the chain:
                return;
            }
            // Send everything else:
            this.Next.Process(item);
        }
    }

如果是 .net framework web 项目,在 ApplicationInsights.config 文件中添加 this(type is assembly_name.class_name):

<TelemetryProcessors>

  <Add Type="WebApplication9.MyErrorFilter, WebApplication9"></Add>
</TelemetryProcessors>

如果是.net core web项目,安装或更新Microsoft.ApplicationInsights.AspNetCore到2.7.1,然后在Startup.cs -> ConfigureServices方法中,添加如下代码行:

services.AddApplicationInsightsTelemetry();
services.AddApplicationInsightsTelemetryProcessor<MyErrorFilter>();

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-02-23
    • 2017-06-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多