本文介绍了调用Azure存储时预期的HTTP 409响应代码.CreateIfNotExists()在App Insights上显示为失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

据报道不存在则创建它),/ Azure / azure-storage-net / issues / 862"target ="_ blank">在GitHub上)导致HTTP 409响应代码,在Application Insights中记录为异常/失败。这极大地增加了App Insights Monitor中的噪音,使得查找真正重要的异常变得更加困难。我不认为
Application Insights应该将此报告为失败,但处理此问题的最佳做法是什么?

As reported on GitHub, ordinary calls to Azure Storage to check if a table exists (and create it if it doesn't) results in an HTTP 409 response code, which is recorded as an Exception/Failure in Application Insights. This greatly increases the noise in App Insights Monitor and makes it more difficult to find exceptions that truly matter. I don't think that Application Insights should be reporting this as a failure, but what's the best practice for dealing with this?

我认为存储SDK不应该'顺便提一下,邀请409并向App Insights抛出一个可见的异常。

It's my opinion that the Storage SDK shouldn't be inviting a 409 and throwing a visible exception to App Insights, by the way.

推荐答案

using Microsoft.ApplicationInsights.Channel;
using Microsoft.ApplicationInsights.Extensibility;

public class SuccessfulDependencyFilter : ITelemetryProcessor
  {

    private ITelemetryProcessor Next { get; set; }

    // You can pass values from .config
    public string MyParamFromConfigFile { get; set; }

    // Link processors to each other in a chain.
    public SuccessfulDependencyFilter(ITelemetryProcessor next)
    {
        this.Next = next;
    }
    public void Process(ITelemetry item)
    {
        // To filter out an item, just return
        if (!OKtoSend(item)) { return; }
        // Modify the item if required
        ModifyItem(item);

        this.Next.Process(item);
    }

    // Example: replace with your own criteria.
    private bool OKtoSend (ITelemetry item)
    {
        var dependency = item as DependencyTelemetry;
        if (dependency == null) return true;

        return dependency.Success != true;
    }

    // Example: replace with your own modifiers.
    private void ModifyItem (ITelemetry item)
    {
        item.Context.Properties.Add("app-version", "1." + MyParamFromConfigFile);
    }
}

然后,您可以在ApplicationInsights.config或代码中注册它:

Then, you can register it in ApplicationInsights.config or in the code:

    <TelemetryProcessors>
      <Add Type="WebApplication9.SuccessfulDependencyFilter, WebApplication9">
         <!-- Set public property -->
         <MyParamFromConfigFile>2-beta</MyParamFromConfigFile>
      </Add>
    </TelemetryProcessors>


在您的情况下,您可以比较响应代码和用于Azure存储依赖性遥测项目的命令,以过滤掉您想要忽略的遥测项目。$

In your case, you can compare the response code and the command used for Azure Storage dependency telemetry item to filter out telemetry items you would like to omit.


这篇关于调用Azure存储时预期的HTTP 409响应代码.CreateIfNotExists()在App Insights上显示为失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!