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

APPINSIGHTS_INSTRUMENTATIONKEY AppSetting overrides ikey specified in code #236

Closed
AlexBulankou opened this issue Nov 29, 2016 · 3 comments
Assignees
Labels
Milestone

Comments

@AlexBulankou
Copy link

  1. Create 4.6 Web Application, enable Application Insights SDK 2.2 Beta 4 and specify in Global.asax.cs:

  2. TelemetryConfiguration.Active.InstrumentationKey = "ikey1";

  3. Publish to Azure WebApp and verify that telemetry is being sent to ikey1

  4. Add AppSetting to WebApp: APPINSIGHTS_INSTRUMENTATIONKEY pointing to ikey2

Expected: telemetry continues to be sent to ikey1, because settings in code take priority
Actual: telemetry now is being sent to ikey2, while QuickPulse events continue to go to ikey1.

@AlexBulankou AlexBulankou changed the title APPINSIGHTS_INSTRUMENTATIONKEY overrides ikey specified in code APPINSIGHTS_INSTRUMENTATIONKEY AppSetting overrides ikey specified in code Nov 29, 2016
@SergeyKanzhelev
Copy link
Contributor

Since I took a look at code anyway - there are two places we set the key from the env variable:

This will not respect TelemetryConfiguration.Active.InstrumentationKey = "ikey1";, but will work when you set new TelemetryClient("ikey1").TrackTrace("trace"):

https://github.com/Microsoft/ApplicationInsights-dotnet/blob/develop/src/Core/Managed/Shared/TelemetryClient.cs#L382-L387

This logic will not "override" the setting from the configuration file, but TelemetryConfiguration.Active.InstrumentationKey = "ikey1";, will override it:

https://github.com/Microsoft/ApplicationInsights-dotnet/blob/de488729c28b721a758e0024ea2d4f79909ff797/src/Core/Managed/Net40/Extensibility/Implementation/TelemetryConfigurationFactory.cs#L76-L81

So clearly the code needs to be refactored and we need unit tests that will "describe" the expected behavior

@Dmitry-Matveev Dmitry-Matveev added this to the 2.2 milestone Nov 29, 2016
@dnduffy
Copy link
Member

dnduffy commented Nov 29, 2016

There is one small problem here, how do you tell the difference between a value in TelemetryConfiguration.Active.InstrumentationKey that was set explicitly in code from one that TelemetryConfigurationFactory.Instance.Initialize placed there from reading the config entry?

@dnduffy
Copy link
Member

dnduffy commented Nov 30, 2016

I've changed the logic and updated the unit tests.
Pull request is here: microsoft/ApplicationInsights-dotnet#379

@dnduffy dnduffy closed this as completed Nov 30, 2016
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

4 participants