I'm currently trying to setup Application Insights for a WebApi running on Service Fabric. While this is super easy to configure for a .NET Core application, it seems to be way more complicated for a .NET Classic application.
The official docs do only contain a rather primitive way to setup Application Insights by clicking through Visual Studio - which in the end did not work for me (it tried to add a reference to the .NET Core Nuget Package for Application Insights).
Important facts about the project
- TargetFramework is net461
- The application is running on Service Fabric 6.5.664.9590
What i tried so far
In my project, i referenced these three nuget packages:
- Microsoft.ApplicationInsights.Web
- Microsoft.ApplicationInsights.DependencyCollector
Content of the ApplicationInsights.config (I added it to the root of the project)
<?xml version="1.0" encoding="utf-8"?>
<ApplicationInsights xmlns="http://schemas.microsoft.com/ApplicationInsights/2013/Settings">
<TelemetryModules>
<Add Type="Microsoft.ApplicationInsights.Web.RequestTrackingTelemetryModule, Microsoft.AI.Web" />
<Add Type="Microsoft.ApplicationInsights.DependencyCollector.DependencyTrackingTelemetryModule, Microsoft.AI.DependencyCollector" />
</TelemetryModules>
<TelemetryInitializers>
<Add Type="Microsoft.ApplicationInsights.Web.OperationNameTelemetryInitializer, Microsoft.AI.Web" />
<Add Type="Microsoft.ApplicationInsights.Web.OperationIdTelemetryInitializer, Microsoft.AI.Web" />
</TelemetryInitializers>
</ApplicationInsights>
In Startup.cs, i overwrite the instrumentation key - because it differs based on the environment the application is running on (read more about that here)
public IServiceProvider ConfigureServices(IServiceCollection services)
{
services.AddMvc();
services.AddAuthentication(...);
TelemetryConfiguration.Active.InstrumentationKey = _applicationInsightSettings.InstrumentationKey;
}
However - no request traces or any other information is sent to Application Insights. What am I missing?
Edit
The configuration part is working - when debugging the app, I can see that the TelemetryInitializers
property in TelemetryConfiguration.Active
is set to what i configured in ApplicationInsight.config
. But nothing is being sent to ApplicationInsights and there are also no errors or exceptions happening.
My solution
Turns out the easiest solution was to get rid of the net461
target framework constraint. A dependency I used (a NuGet package) was limiting me to use net461
. Once I got rid of that dependency, and moved the application to .NET Core and boom - everything works just magically.