Disable Application Insights in Debug

Disable application insights in debug

As explained in the question not deploying or deploying an ApplicationInsights.config without <instrumentationkey>key</instrumentationkey> block events from being generated.
You can then put the instrumentation key in code (only on release in my case)

#if !DEBUG
Microsoft.ApplicationInsights.Extensibility.TelemetryConfiguration.Active.InstrumentationKey = "instrumentation key";
#endif

Every TelemetryClient created after this call will have the correct key and will track events so you don't have to change the code in all places.
Not calling the method above or leaving the parameter empty will block events because there isn't a key configured.

Basically the ApplicationInsights.config file overrides any code that set the instrumentation key, removing the <instrumentationkey>key</instrumentationkey> inside it will let you use code to configure the key.
If you remove the file completely it doesn't work.

Here is the confirm:
"If you want to set the key dynamically - for example if you want to send results from your application to different resources - you can omit the key from the configuration file, and set it in code instead."

Reference: https://azure.microsoft.com/en-us/documentation/articles/app-insights-configuration-with-applicationinsights-config/#_instrumentationkey

How do I disable Application Insights logging in Microsoft.ApplicationInsights.AspNetCore Version=2.20.0 and upper?

You could just not set the instrumentation key in debug/development mode so the telemetry is not send to azure but still visible in the Visual Studio tool

Sample Image

Turn off Application Insights

Where is exactly turned on I don't know, but I guess that you are looking for a way to feature toggle application insights, and to do so in your Application_Start you could do:

TelemetryConfiguration.Active.DisableTelemetry = true;

Doing this you'll stop sending telemetry info.

I hope this help, if it doesn't please let us know what you tried so I could have a better understanding of your question.

For more information you can check their documentation here. The section about Custom Initializers is also quite interesting and maybe will help you as well.

Stop Application Insights from posting to Debug console

Hans Passant is right. DeveloperMode is what triggers AI to write events in DebugOutput. Note though that it also forces AI to send data immediately. So if we set it to false data will be batched and sent out once a minute.

Disable manually tracking dependencies in ApplicationInsights.config

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>

Disable Application Insights Browser Telemetry for a Recurring JavaScript call

You can use a telemetry intializer. When the initializer method returns false the telemetry item is ignored. An example:

    var telemetryInitializer = (envelope) => {
var data = envelope.data.baseData;
if (data.url && data.url.includes("/Status")) {
return false;
}
return true;
};
appInsights.addTelemetryInitializer(telemetryInitializer);


Related Topics



Leave a reply



Submit