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

Api hosted in service fabric can not pickup config #1566

Closed
AndersMalmgren opened this issue Apr 24, 2019 · 8 comments
Closed

Api hosted in service fabric can not pickup config #1566

AndersMalmgren opened this issue Apr 24, 2019 · 8 comments

Comments

@AndersMalmgren
Copy link

If you are reporting bug/issue, please provide detailed Repro instructions.

Repro Steps

Using a service fabric template project, I have made a repro project here https://github.com/AndersMalmgren/ServiceFabricLoggingRepro

Configure it for app insight doing

services
   .AddApplicationInsightsTelemetry()

Actual Behavior

It fails to pickup the config and log says
Application Insights Telemetry (unconfigured)
If I explicit supply it with Configuration doing

services
   .AddApplicationInsightsTelemetry(Configuration)

It works, but this is not how it behaves outside of service fabric.

Expected Behavior

It should work the same way as if hosted outside of service fabric

Version Info

SDK Version : 2.7.0-beta3
.NET Version : Core 2,2
How Application was onboarded with SDK(VisualStudio/StatusMonitor/Azure Extension) :
OS :
Hosting Info (IIS/Azure WebApps/ etc) : Service fabric with kestrel

@cijothomas
Copy link
Contributor

services.AddApplicationInsightsTelemetry() is expected to pickup instrumentation key from appsettings.json. I don't see ikey configured in appseting.json https://github.com/AndersMalmgren/ServiceFabricLoggingRepro/blob/master/FabricApi/appsettings.json

The following is an eg: with instrumentation key.
{
"ApplicationInsights": {
"InstrumentationKey": "putinstrumentationkeyhere"
},
"Logging": {
"LogLevel": {
"Default": "Warning"
}
}
}

@AndersMalmgren
Copy link
Author

Hi @cijothomas

Service fabric does not use that json. It uses a custom configuration provider

https://github.com/AndersMalmgren/ServiceFabricLoggingRepro/blob/master/FabricApi/FabricApi.cs#L45

It's populated using the service fabric settings file
https://github.com/AndersMalmgren/ServiceFabricLoggingRepro/blob/master/FabricApi/PackageRoot/Config/Settings.xml

To test it put a breakpoint in Startup.cs you will see that it populated correctly

I got this response from the service fabric team. I'm not sure its accurate though, your code correctly picks up the config in vanilla ASP Core.

@AndersMalmgren , if you still want the same default behavior work for asp.net core and service fabric the same way, you need to open an issue for App Insight, asking them to change DefaultApplicationInsightsServiceConfigureOptions to use the Configuration from DI container rather than build their own ConfigurationBuilder.

@cijothomas
Copy link
Contributor

@AndersMalmgren If SF don't use that json, AI SDK wont pickup settings.
See instrumentation key part from this doc:
https://docs.microsoft.com/en-us/azure/azure-monitor/app/asp-net-core-no-visualstudio#enabling-application-insights-server-side-telemetry

If you are configuring settings outside of the these, you need to call .AddApplicationInsightsTelemetry(Configuration)

Will keep this issue as an enhancement to modify SDK to pick config from DI.

@AndersMalmgren
Copy link
Author

AndersMalmgren commented Apr 25, 2019

This is false, from vanilla ASP Core I can use a custom configuration provider exactly the same way the service fabric configuration provider works and app insight will be able to pick it up without explicit supplying config instance.

Edit: or am I confusing it with native logging, I will check my repro

Edit: I was confusing it with native logging, native logging didn't work either until I used the CreateDefualtBuilder on the Webhost

@cijothomas
Copy link
Contributor

https://github.com/Microsoft/ApplicationInsights- aspnetcore/blob/develop/src/Microsoft.ApplicationInsights.AspNetCore/Extensions/DefaultApplicationInsightsServiceConfigureOptions.cs#L31

We only read (by default) from appsettings.json and ENV.

@AndersMalmgren
Copy link
Author

Yeah I was confusing it with native logging. Yeah, much better just injecting the IConfiguration

@chuanboz
Copy link

if injecting the IConfiguration, there is a priority issue that needs to be considered, that whether the injected IConfiguration has lower or higher priority than current default appSettings.json; It also needs to consider backwords compatibility of old behavior, otherwise it could be a breaking change.

@cijothomas
Copy link
Contributor

@chuanboz Yes agreed.

At this stage, if not using the default appsettings.json, then there is workaround of supplying configuration using .AddApplicationInsightsTelemetry(Configuration) overload.

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

4 participants