Summary
- Respect IConfiguration used in an application.
- Bind all properties of
ApplicationInsightsServiceOptions from IConfiguration. Currently, InstrumentationKey, ConnectionString, DeveloperMode and EndpointAddress are the only properties which gets bound to ApplicationInsightsServiceOptions from configuration.
Related Issues:
Api hosted in service fabric can not pickup config #1566
Custom ConfigurationProviders are not respected #1297
Which settings are available wihin appsettings.json? #1448
ApplicationInsights does not inherently read ApplicationInsightsServiceOptions from appsettings.json #1806
ConnectionString not read from appsettings.json when using AddApplicationInsightsTelemetry(ApplicationInsightsServiceOptions) #1726
Configuration issue with AzureKeyVault #1878
Current Behavior
Which ASP.NET Core Configuration providers are supported with Application Insights?
- appsettings.json
- appsettings.Environment.json
- Environmental variables
- Application Insights special environment variables
Configuration providers that are added later override previous key settings. For example, if InstrumentationKey is set in both appsettings.json and the environment variable, the environment variable value is used. Application Insights special environment variables configuration provider, overrides values from all other providers.
If a key and value is set in more than one configuration providers, the value from the last provider added is used.
What are the names of special Application Insights Environment Variables?
APPINSIGHTS_INSTRUMENTATIONKEY, APPLICATIONINSIGHTS_CONNECTION_STRING, APPINSIGHTS_DEVELOPER_MODE, APPINSIGHTS_ENDPOINTADDRESS
Which application insights properties are supported through configuration file?.
InstrumentationKey, ConnectionString, DeveloperMode and EndpointAddress
What happens if additional properties like EnableAdaptiveSampling, EnableHeartbeat are present in ASP.NET Core Configuration?
Application Insights will not read these properties and will not be used when tracking an app.
Is there a workaround to read other application insights properties defined in ApplicationInsightsServiceOptions through ASP.NET Core Configuration Providers?
Please refer #1806 for workaround.
Documentation: https://docs.microsoft.com/en-us/azure/azure-monitor/app/asp-net-core#enable-application-insights-server-side-telemetry-no-visual-studio
Proposal
- Read all properties defined in
ApplicationInsightsServiceOptions from any ASP.NET Core Configuration Providers.
- By default, read values from
IConfiguration used within an application. A call to services.AddApplicationInsightsTelemetry() will read properties from any custom configuration providers like JSON file, XML file, Azure Key Vault, etc.,
Which ASP.NET Core Configuration providers will be supported?
All Configuration supported with ASP.NET Core Framework.
- appSettings.json
- appsettings.Environment.json
- An existing IConfiguration from app – this enables reading from any configuration providers
- Environmental variables
- Application Insights special environment variables
What is the hierarchy of configuration file?
// Example appsettings.json:
{
"ApplicationInsights": {
"InstrumentationKey": "ikeyhere",
"ConnectionString": "connectionstringhere",
"EnableAdaptiveSampling": false,
"EnablePerformanceCounterCollectionModule": true,
"EnableAzureInstanceMetadataTelemetryModule": true,
"EnableRequestTrackingTelemetryModule": true,
"EnableDependencyTrackingTelemetryModule": true,
"EnableAppServicesHeartbeatTelemetryModule": true,
"EnableEventCounterCollectionModule": true,
"AddAutoCollectedMetricExtractor": true,
"EnableQuickPulseMetricStream": true,
"EnableDebugLogger": true,
"EnableHeartbeat": true,
"EnableAuthenticationTrackingJavaScript": false,
"ApplicationVersion": "Version",
"RequestCollectionOptions": {
"InjectResponseHeaders": true,
"TrackExceptions": false,
"EnableW3CDistributedTracing": true
},
"DependencyCollectionOptions": {
"EnableLegacyCorrelationHeadersInjection": false
},
"TelemetryChannel": {
"EndpointAddress": "http://testendpoint/v2/track",
"DeveloperMode": true
}
}
}
Is the new configuration model supported in all versions of .NET Framework?
No. These changes will be available to .NET Core apps that target NET461, NETSTANDARD2.0 or higher versions.
A .NET Core app is targeting NET46, would these changes impact that app?
There are no impact with these changes to apps targeting old version of .NET Framework. It should continue to work in the same way as defined in current behavior section.
Summary
ApplicationInsightsServiceOptionsfrom IConfiguration. Currently,InstrumentationKey,ConnectionString,DeveloperModeandEndpointAddressare the only properties which gets bound toApplicationInsightsServiceOptionsfrom configuration.Related Issues:
Api hosted in service fabric can not pickup config #1566
Custom ConfigurationProviders are not respected #1297
Which settings are available wihin appsettings.json? #1448
ApplicationInsights does not inherently read ApplicationInsightsServiceOptions from appsettings.json #1806
ConnectionString not read from appsettings.json when using AddApplicationInsightsTelemetry(ApplicationInsightsServiceOptions) #1726
Configuration issue with AzureKeyVault #1878
Current Behavior
Which ASP.NET Core Configuration providers are supported with Application Insights?
Configuration providers that are added later override previous key settings. For example, if
InstrumentationKeyis set in bothappsettings.jsonand theenvironment variable, theenvironment variablevalue is used. Application Insights special environment variables configuration provider, overrides values from all other providers.What are the names of special Application Insights Environment Variables?
APPINSIGHTS_INSTRUMENTATIONKEY,APPLICATIONINSIGHTS_CONNECTION_STRING,APPINSIGHTS_DEVELOPER_MODE,APPINSIGHTS_ENDPOINTADDRESSWhich application insights properties are supported through configuration file?.
InstrumentationKey,ConnectionString,DeveloperModeandEndpointAddressWhat happens if additional properties like
EnableAdaptiveSampling,EnableHeartbeatare present in ASP.NET Core Configuration?Application Insights will not read these properties and will not be used when tracking an app.
Is there a workaround to read other application insights properties defined in
ApplicationInsightsServiceOptionsthrough ASP.NET Core Configuration Providers?Please refer #1806 for workaround.
Documentation: https://docs.microsoft.com/en-us/azure/azure-monitor/app/asp-net-core#enable-application-insights-server-side-telemetry-no-visual-studio
Proposal
ApplicationInsightsServiceOptionsfrom any ASP.NET Core Configuration Providers.IConfigurationused within an application. A call toservices.AddApplicationInsightsTelemetry()will read properties from any custom configuration providers like JSON file, XML file, Azure Key Vault, etc.,Which ASP.NET Core Configuration providers will be supported?
All Configuration supported with ASP.NET Core Framework.
What is the hierarchy of configuration file?
Is the new configuration model supported in all versions of .NET Framework?
No. These changes will be available to .NET Core apps that target
NET461,NETSTANDARD2.0or higher versions.A .NET Core app is targeting NET46, would these changes impact that app?
There are no impact with these changes to apps targeting old version of .NET Framework. It should continue to work in the same way as defined in current behavior section.