1
votes

Is it possible to disable Application Insights dependency tracking for a specific method/function?

My specific problem is that I've got a custom ITelemetryInitializer and within that, I'm calling a static function that can have an external dependency if the value isn't already cached in memory. Within that function, it's creating a new ITelemetry and calling my ITelemetryInitializer, which generates a new ITelemetry, etc., resulting in a StackOverflowException.

Basically (this is NOT my actual code):

public void Initialize(ITelemetry telemetry)
{
    var cached = GetCachedValue();
    if(cached)
        return cached;
    else
    {
        var value = GetData();  // New Telemetry gets created here - since it's not cached yet, the new telemetry gets initialized and goes right back here.
        SetCachedValue(value);
    }
}

I'm reworking my initializer to NOT use the external dependency, but I think the question is still valid - if there's a specific thing I don't want tracked, can I disable telemetry for that thing (in my example, I'd want to turn off tracking for the GetData method)?

1

1 Answers

1
votes

It is possible to disable dependency tracking using ITelemetryProcessor (https://docs.microsoft.com/en-us/azure/application-insights/app-insights-api-filtering-sampling).

But this will not help in your case since ITelemetryInitializer will be called first anyway. The right solution is not to do dependency calls from ITelemetryInitializer.