-
Notifications
You must be signed in to change notification settings - Fork 293
Description
TelemetryClient has Initialize() (https://github.com/Microsoft/ApplicationInsights-dotnet/blob/develop/src/Microsoft.ApplicationInsights/TelemetryClient.cs#L456) method, which is used by AutoCollection TelemetryModules (https://github.com/Microsoft/ApplicationInsights-dotnet/blob/develop/src/Microsoft.ApplicationInsights/TelemetryClient.cs#L456) to populate the instrumentation key from TelemetryClient.
This method causes all TelemetryInitializers to run. Apart from this, when Track() is eventually called, all TelemetryInitializers are run again.
While most TelemetryInitializers are written in such a way that it detects 'no action needed, exit quickly' - but there are exceptions.
An example is SyntheticUserAgentTelemetryInitializer, which, if called multiple times, will do all the compute-intensive task of checking useragent to the list of potential 'bot' strings.
https://github.com/Microsoft/ApplicationInsights-dotnet-server/blob/develop/Src/Web/Web.Shared.Net/SyntheticUserAgentTelemetryInitializer.cs#L50
(there are others similar to this in AI default list itself, but potentially many more written by others)
Proposal is to add a new method (but hidden) in TelemetryClient called InitializeInstrumentationKey(ITelemetry telemetry), which can used by auto collection modules to populate instrumentation key. Once all auto collectors move to this method, the customer confusions about TelemetryInitializers being called multiple times is going to be mitigated. (along with the perf improvement!)