Skip to content
This repository has been archived by the owner on Jun 10, 2020. It is now read-only.

Initializing TelemetryConfiguration twice can result into DiagnosticListeners to pump events into wrong pipeline #955

Closed
RamjotSingh opened this issue Aug 13, 2019 · 2 comments
Labels

Comments

@RamjotSingh
Copy link

RamjotSingh commented Aug 13, 2019

If you are reporting bug/issue, please provide detailed Repro instructions.

Issue description

Using .UseApplicationInsights or .AddApplicationInsightsTelemetry during WebHostBuilder phase and then adding\customizing the TelemetryConfiguration later on during Startup(e.g. adding TelemetryInitilializers) will result into any customization done during Startup.cs phase not work at all.

Repro

DiagnosticListenerBugAI.zip

If the line

services.AddApplicationInsightsTelemetry(Guid.Empty.ToString());

is uncommented in Program.cs, NullTelemetryInitializer will not be called for auto tracked events like requests, dependencies etc. However if the line is moved to Startup.cs and removed from Program.cs the initializer is called as expected.

Root Cause

If the registration is done during WebHostBuilder phase the whole init is done twice, once when the server is booting up and once for actual operations.
Code in ActiveSubscriptionManager.cs will register the very first time and then retain the instance and call this instance when events happen, this means the second instance is never used which has customizations from WebHostBuilder + Startup.cs.

Version Info

SDK Version (version of https://www.nuget.org/packages/Microsoft.ApplicationInsights.AspNetCore) : 2.7.1
.NET Core Version (TargetFramework in your .csproj file) : .NetCore2.1 and above
How Application was onboarded with SDK(Installed Nugets/VisualStudio/Azure WebAppExtension) : N/A
OS : N/A
Hosting Info (IIS/Azure Web Apps/Running From Visual Studio etc) : N/A

@RamjotSingh
Copy link
Author

@TimothyMothra Can you take a look?

@lmolkova
Copy link
Member

lmolkova commented Aug 14, 2019

This is expected and unfortunately cannot be fixed. Some history #621 and microsoft/ApplicationInsights-dotnet-server#1013. We do not support having two different configurations with different settings in one process.

We can only advise you not to do this or dispose the first configuration and all the modules once you are done with them.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants