IvanJosipovic / BlazorApplicationInsights

Application Insights for Blazor web applications

Home Page:https://BlazorApplicationInsights.netlify.app

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Disable telemetry in Development environment

sergey-tihon opened this issue · comments

Is there an official and easy way to disable AppInsights telemetry in Development environment?

Not that I'm aware of. I keep it on but use a Dev App Insights instance so that alerts don't trigger. Additionally, you could use an adblocker.

Quote from https://docs.microsoft.com/en-us/azure/azure-monitor/app/javascript#telemetry-initializers

The input argument to addTelemetryInitializer is a callback that takes a ITelemetryItem as an argument and returns a boolean or void. If returning false, the telemetry item isn't sent, else it proceeds to the next telemetry initializer, if any, or is sent to the telemetry collection endpoint.

Looks like telemetryInitializer may return false and disable telemetry.

We can add property to TelemetryItem that will control this behaviour during initialisation.

public bool SendTelemetry {get; set} = true;

or one similar to .net client

public bool DisableTelemetry {get; set} = false;

p.s. solution found on StackOverflow

This is now supported in v3.