Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changed the logic for loading the iKey from an environment variable to not override config or code settings. #379

Merged
merged 3 commits into from
Nov 30, 2016

Conversation

dnduffy
Copy link
Member

@dnduffy dnduffy commented Nov 30, 2016

No description provided.

Assert.DoesNotThrow(() => client.TrackTrace(message));
Assert.Equal(expectedKey, sentTelemetry.Context.InstrumentationKey);

// Set in code method two.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please split into two unit tests. Generally we are trying to keep one test for the single scenario/check

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did that originally, it was just a lot of copied and pasted code, and the test naming got weirder but I can do it again.

Assert.Equal(expectedKey, sentTelemetry.Context.InstrumentationKey);

Environment.SetEnvironmentVariable("APPINSIGHTS_INSTRUMENTATIONKEY", null);
TelemetryConfiguration.Active.InstrumentationKey = oldActiveKey; // Restore state to not impact other tests.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You called 'ClearActiveTelemetryConfiguration' in the beginning. So you still need to restore keys?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm hoping to avoid going through and finding and fixing any more tests that fail from circumstantial ordering that happen to depend on previous tests setting context for them.

// If no configuration override was passed to the constructor then the default configuration instance will have been used.
// If no iKey was present in the config then the environment variable will have been loaded into the default instance.
instrumentationKey = this.configuration.InstrumentationKey;
if (string.IsNullOrEmpty(instrumentationKey) && this.configuration != TelemetryConfiguration.Active)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need this logic at all? Do we have test for non-Active config and why do we need to use environment variable for it?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we need this logic because if you specify a custom config with no iKey it won't pickup from the environment variable but this way provides a fallback when trying to send telemetry.

// If no configuration override was passed to the constructor then the default configuration instance will have been used.
// If no iKey was present in the config then the environment variable will have been loaded into the default instance.
instrumentationKey = this.configuration.InstrumentationKey;
if (string.IsNullOrEmpty(instrumentationKey) && this.configuration != TelemetryConfiguration.Active)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So the decision is to use the ikey from the ApplicaitonInsights.config to take priority? TelemtryConfigurationFactory seems to kept this logic. Can you please add a test for this case or just point to it

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe that the test which I modified covers this but we can figure out how to make it clearer.

@dnduffy dnduffy merged commit 47925e5 into develop Nov 30, 2016
@dnduffy dnduffy deleted the dnduffy/FixIKeySourcePriorityBug branch November 30, 2016 21:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants