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

Read iKey from environment variable (APPINSIGHTS_INSTRUMENTATIONKEY) #315

Merged
merged 7 commits into from
Sep 27, 2016

Conversation

abaranch
Copy link
Contributor


public string GetEnvironmentVariable(string name)
{
return null;
Copy link
Member

Choose a reason for hiding this comment

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

Is there maybe a .NET Core equivalent for getting environment variables we could use?

Copy link
Member

Choose a reason for hiding this comment

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

Maybe something in Microsoft.Extensions.Configuration.EnvironmentVariables or Microsoft.Extensions.Configuration could be used.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not in PCL. Those are .Net Core specific namespaces. If ever change target framework we can start supporting it.

Copy link
Member

Choose a reason for hiding this comment

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

Good point, I keep thinking of .NET Core as a replacement for PCL but it is completely new and isn't portable backwards (as such).


if (string.IsNullOrEmpty(instrumentationKey))
{
instrumentationKey = PlatformSingleton.Current.GetEnvironmentVariable(InstrumentationKeyWebSitesEnvironmentVariable);
Copy link
Contributor

Choose a reason for hiding this comment

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

So this ikey has the least priority? Is it what we want for Web Apps case? In Web Apps you can configure ikey in AI.config file and then override it using Web App settings. Not other way around.

Also I'm concerned about performance of it. Maybe just read it once and cache? Or we need to support the scenario when environment variable will be changed later?

Copy link
Member

Choose a reason for hiding this comment

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

I agree on caching, discussing the priority ordering, but I don't think it should change during runtime.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, priority order is correct for web sites (@iusafaro)
Resolved caching.

Copy link
Contributor

Choose a reason for hiding this comment

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

@iusafaro, this priority order doesn't make sense to me. Can you pls elaborate why it is done this way?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Per offline discussion we will change the order so it is: code -> environment variable -> config

@codecov-io
Copy link

codecov-io commented Sep 26, 2016

Current coverage is 84.97% (diff: 55.55%)

Merging #315 into develop will decrease coverage by 0.05%

@@            develop       #315   diff @@
==========================================
  Files           137        137          
  Lines          5175       5184     +9   
  Methods        1084       1085     +1   
  Messages          0          0          
  Branches        752        755     +3   
==========================================
+ Hits           4400       4405     +5   
- Misses          471        473     +2   
- Partials        304        306     +2   

Powered by Codecov. Last update 7c73502...ac35f0f

@SergeyKanzhelev
Copy link
Contributor

@iusafaro can you please ensure that we do not need to re-read instrumentation key from the environment variable after Web App swap?


if (string.IsNullOrEmpty(instrumentationKey))
{
instrumentationKey = this.configuration.InstrumentationKey;
Copy link
Contributor

Choose a reason for hiding this comment

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

So we doing it before initializers have a chance to override it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes

Copy link
Contributor

Choose a reason for hiding this comment

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

Thinking about it - I guess it is fine

Copy link
Contributor

@SergeyKanzhelev SergeyKanzhelev left a comment

Choose a reason for hiding this comment

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

The only question is whether Web Apps will restart an application on swap


if (string.IsNullOrEmpty(instrumentationKey))
{
instrumentationKey = this.configuration.InstrumentationKey;
Copy link
Contributor

Choose a reason for hiding this comment

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

Thinking about it - I guess it is fine

@abaranch abaranch merged commit 891502c into develop Sep 27, 2016
@abaranch abaranch deleted the abaranch/readIKeyFromEnvVar branch October 7, 2016 21:40
TimothyMothra added a commit that referenced this pull request Oct 25, 2019
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.

5 participants