-
Notifications
You must be signed in to change notification settings - Fork 286
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
Conversation
|
||
public string GetEnvironmentVariable(string name) | ||
{ | ||
return null; |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
Current coverage is 84.97% (diff: 55.55%)@@ 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
|
@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; |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes
There was a problem hiding this comment.
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
There was a problem hiding this 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; |
There was a problem hiding this comment.
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
microsoft/ApplicationInsights-dotnet-server#136