![](/img/trans.png)
[英]I want to customize alert emails sent from Azure Application Insights. How Can I do it?
[英]How to customize Application Insights
我有一個帶有 Microsoft Application Insights 的 Web 應用程序。 我監控所有請求、異常、性能等。
是否可以自定義和禁用某些請求的監控?
我想禁用某些類型的靜態文件的監視器,例如 *.js、*.css、*.png。
你當然可以。 您的選擇之一是使用遙測過濾器。 請參閱文檔。 一個基於 url 過濾掉請求的例子是這樣的:
/// <summary>
/// A Telemetry filter lets you define whether a telemetry item is dropped or not
/// </summary>
public class CustomTelemetryFilter : ITelemetryProcessor
{
private readonly ITelemetryProcessor _next;
public CustomTelemetryFilter(ITelemetryProcessor next)
{
_next = next;
}
public void Process(ITelemetry item)
{
// Example: process all telemetry except requests to .png files
var isRequestToUrlContainingSpecificText = item is RequestTelemetry request && request.Url.ToString().EndsWith(".png");
if (!isRequestToUrlContainingSpecificText)
_next.Process(item); // Process the item
else
{
// Item is dropped here
}
}
}
在前端,您還可以定義一個過濾器以停止發送遙測,如果它符合特定條件,請參閱文檔
var filteringFunction = (envelope) => {
if (envelope.data.someField === 'tobefilteredout') {
return false;
}
return true;
};
...
appInsights.addTelemetryInitializer(filteringFunction);
您可以為給定的文件格式添加以下行
TelemetryConfiguration.Active.DisableTelemetry = true;
感謝vivek nuna ,應用此設置后
TelemetryConfiguration.Active.DisableTelemetry = true;
您還可以使用以下設置一起啟用 AJAX 請求收集:
disableAjaxTracking: false
Where dableAjaxTracking: [boolean] - 如果為 true,則不會自動收集 Ajax 調用。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.