我已经按照指南here进行了操作。我在代码"中尝试了配置和#34;初始化和注册我们的遥测处理器的方法。我的目标是过滤掉一些HTTP响应,以便那些不会进入采样数据的人。我没有取得任何成功。虽然我们的处理器在应用程序启动时初始化,但Process方法永远不会被命中。此外,我已经确保配置中有 InstrumentationKey ,并且我使用了正确的密钥。我还缺少什么?
这就是我所拥有的:
public class MyTelemetryProcessor : 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 MyTelemetryProcessor(ITelemetryProcessor next)
{
this.Next = next; <-- this is always hit indicating this processor is active
}
public void Process(ITelemetry item)
{
// To filter out an item, just return
if (!OKtoSend(item)) { return; } <-- breakpoint here is never hit
// Modify the item if required
ModifyItem(item);
this.Next.Process(item);
}
private bool OKtoSend(ITelemetry item) <-- and consequently this method is never hit
{
var request = item as RequestTelemetry; <-- breakpoint here is never hit
// some more code goes here
return request.Success.GetValueOrDefault(false);
}
// Example: replace with your own modifiers.
private void ModifyItem(ITelemetry item)
{
item.Context.Properties.Add("app-version", "1." + MyParamFromConfigFile);
}
}
这就是它的注册方式。我可以看到在应用程序启动时调试期间会出现这种情况:
var builder = TelemetryConfiguration.Active.TelemetryProcessorChainBuilder;
builder.Use((next) => new MyTelemetryProcessor (next));
builder.Build();
答案 0 :(得分:2)
在aspnetcore中,我的解决方案是使用: services.AddApplicationInsightsTelemetryProcessor(typeof(BasicTelemetryFilter));
(使用常规的CreateWebHostBuilder:
WebHost.CreateDefaultBuilder(args)
.UseApplicationInsights()
.UseStartup<Startup>();
)