问题描述
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上显示为失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!