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

Automatically read all properties of ApplicationInsightsServiceOptions from IConfiguration #1882

Closed
rajkumar-rangaraj opened this issue May 29, 2020 · 0 comments
Milestone

Comments

@rajkumar-rangaraj
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants