85 lines
2.8 KiB
C#
85 lines
2.8 KiB
C#
using Microsoft.ApplicationInsights.Channel;
|
|
using Microsoft.ApplicationInsights.DataContracts;
|
|
using Microsoft.ApplicationInsights.Extensibility;
|
|
|
|
namespace gehGassi.Web.Helper
|
|
{
|
|
/// <summary>
|
|
/// Ausfiltern von unerwünschten Events des Azure-Storage und SignalR für Application-Insights
|
|
/// </summary>
|
|
public class ApplicationInsightsTelemetryProcessor : ITelemetryProcessor
|
|
{
|
|
private ITelemetryProcessor Next { get; set; }
|
|
|
|
public ApplicationInsightsTelemetryProcessor(ITelemetryProcessor next)
|
|
{
|
|
Next = next;
|
|
}
|
|
|
|
public void Process(ITelemetry item)
|
|
{
|
|
if (item is RequestTelemetry request && !string.IsNullOrWhiteSpace(request.Name))
|
|
{
|
|
var requestName = request.Name.ToLower();
|
|
|
|
if (requestName.Contains("signalr"))
|
|
return;
|
|
if (requestName.Contains("negotiate"))
|
|
return;
|
|
if ((requestName.StartsWith("get api") || requestName.StartsWith("post api")) && requestName.Contains("/"))
|
|
{
|
|
if (!VerifyRequestIsValid(item))
|
|
return;
|
|
}
|
|
}
|
|
|
|
if (!VerifyDepdendencyIsValid(item))
|
|
return;
|
|
|
|
Next.Process(item);
|
|
}
|
|
|
|
private bool VerifyDepdendencyIsValid(ITelemetry item)
|
|
{
|
|
var dependency = item as DependencyTelemetry;
|
|
|
|
|
|
if (dependency == null)
|
|
return true;
|
|
|
|
//Filter
|
|
if (dependency.Success == false)
|
|
{
|
|
if (dependency.ResultCode is "409" or "404")
|
|
dependency.Success = true;
|
|
if (dependency.Type.ToLower() == "azure blob" && dependency.ResultCode is "409" or "404")
|
|
dependency.Success = true;
|
|
if (dependency.Type.ToLower() == "http" && dependency.ResultCode is "409")
|
|
dependency.Success = true;
|
|
if (dependency.Type.ToLower() == "inproc | microsoft.storage" && dependency.Name == "BlobContainerClient.Create")
|
|
dependency.Success = true;
|
|
if (dependency.Type.ToLower() == "inproc | microsoft.storage" && dependency.Name == "ShareClient.CreateIfNotExists")
|
|
dependency.Success = true;
|
|
}
|
|
|
|
return dependency.Success != true;
|
|
}
|
|
|
|
private bool VerifyRequestIsValid(ITelemetry item)
|
|
{
|
|
var request = item as RequestTelemetry;
|
|
|
|
if (request == null)
|
|
return true;
|
|
|
|
//Filter
|
|
if (request.Success == false)
|
|
{
|
|
if (request.ResponseCode is "400" or "401" or "404")
|
|
request.Success = true;
|
|
}
|
|
return request.Success != true;
|
|
}
|
|
}
|
|
}
|