I want to disable sending of manually tracking dependencies in my project, because they are consuming a lot of resources (data ingested) in my azure. Also, I want to be able to re-enable for debugging purpose. The cose used for manually track the dependencies is the following:
var ai = new TelemetryClient(TelemetryConfiguration.Active);
ai.TrackDependency(new DependencyTelemetry("User", "CElaboraRichieste", "GetStringXML", "Inizio"));
I've successfully removed the automatic dependencies by removing the DependencyTrackingTelemetryModule module in ApplicationInsights.config, but I wasn't able to do the same with manually tracked deps. Is there a way to accomplish my goal by editing such config and not introducing a new config parameter? Thanks!
CodePudding user response:
I would create a TelemetryProcessor and have it dicard dependency telemetry when not in debug mode (or whatever logic you want to determine whether telemetry should be processed or discarded). For example:
public class DependencyFilter : ITelemetryProcessor
{
private readonly ITelemetryProcessor _next;
public DependencyFilter(ITelemetryProcessor next)
{
_next = next;
}
public void Process(ITelemetry item)
{
bool isDebugMode = false;
#if DEBUG
isDebugMode = true;
#endif
if(item is DependencyTelemetry & !isDebugMode
return;
_next.Process(item)
}
}
You need to register the processor type in the config file by using the full namespace and type name and assembly:
<TelemetryProcessors>
...
<Add Type="WebApp.DependencyFilter , WebApp" />
...
</TelemetryProcessors>