You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Jun 10, 2020. It is now read-only.
When wiring up application insights using the WebHostBuilder extension, it seems to ignore the environment specific instrumentation key from appsettings.ENVIRONMENT.json
var host = new WebHostBuilder()
.UseKestrel()
.UseContentRoot(Directory.GetCurrentDirectory())
.UseIISIntegration()
.UseStartup<Startup>()
.UseApplicationInsights()
.Build();
host.Run();
Looking at the source I see that its using DefaultApplicationInsightsServiceConfigureOptions which uses its own ConfigurationBuilder and only adds "appsettings.json" and not appsettings.ENVIRONMENT.json.
public void Configure(ApplicationInsightsServiceOptions options)
{
var configBuilder = new ConfigurationBuilder()
.SetBasePath(this.hostingEnvironment.ContentRootPath)
.AddJsonFile("appsettings.json", true)
.AddEnvironmentVariables();
ApplicationInsightsExtensions.AddTelemetryConfiguration(configBuilder.Build(), options);
if (Debugger.IsAttached)
{
options.DeveloperMode = true;
}
}
Is using different app insight resources for each environment not a valid approach moving forward?
Since the File->New->Project wires up app insights using the WebHostBuilder this seems like a gotcha for users that need to override the instrumentation key per environment.
I will be happy to submit a PR for review if this was an oversight!
The text was updated successfully, but these errors were encountered:
When wiring up application insights using the WebHostBuilder extension, it seems to ignore the environment specific instrumentation key from appsettings.ENVIRONMENT.json
Method used: https://github.com/Microsoft/ApplicationInsights-aspnetcore/blob/develop/src/Microsoft.ApplicationInsights.AspNetCore/Extensions/ApplicationInsightsWebHostBuilderExtensions.cs#L18
Looking at the source I see that its using DefaultApplicationInsightsServiceConfigureOptions which uses its own ConfigurationBuilder and only adds "appsettings.json" and not appsettings.ENVIRONMENT.json.
See: https://github.com/Microsoft/ApplicationInsights-aspnetcore/blob/develop/src/Microsoft.ApplicationInsights.AspNetCore/Extensions/DefaultApplicationInsightsServiceConfigureOptions.cs#L31
I will be happy to submit a PR for review if this was an oversight!
The text was updated successfully, but these errors were encountered: