Application Insights with ServiceFabric StatefulServices and .Net Core 2.1

784 Views Asked by At

i have an ServiceFabric StatefulService with Remoting inside a ServiceFabric Solution which also contains a Stateless WebApi and want to use Application Insights for monitoring this service. The WebApi uses already AI and it works fine.

I tried this in a dummy project an everything works fine with configuring AI in the constructor of the service:

    public ReliableService(StatefulServiceContext context) : base(context)
    {
        var instrumentationKey = "myIKey";
        TelemetryConfiguration.Active.TelemetryInitializers.Add(
            FabricTelemetryInitializerExtension.CreateFabricTelemetryInitializer(this.Context)
        );
        _telemetryClient    = new Microsoft.ApplicationInsights.TelemetryClient { InstrumentationKey = instrumentationKey };
        TelemetryConfiguration.Active.InstrumentationKey = instrumentationKey;

        TelemetryConfiguration.Active.TelemetryInitializers.Add(new OperationCorrelationTelemetryInitializer());
        TelemetryConfiguration.Active.TelemetryInitializers.Add(new HttpDependenciesParsingTelemetryInitializer());
        new DependencyTrackingTelemetryModule().Initialize(TelemetryConfiguration.Active);
        new ServiceRemotingRequestTrackingTelemetryModule().Initialize(TelemetryConfiguration.Active);
        new ServiceRemotingDependencyTrackingTelemetryModule().Initialize(TelemetryConfiguration.Active);

    }

But when I copy the same code to the existing project only the WebApi sends telemetry data to AI, nothing from the statefull service.

Any idea what i'm doing wrong? The documentations are not really helpful for me, there is not full example of using AI in a statefull service with remoting.

Thank you for your answers!

1

There are 1 best solutions below

2
On

You will need this package https://github.com/Microsoft/ApplicationInsights-ServiceFabric to make it work with Service Remoting.
The configuration story is very different depends on your project type, e.g, console app, Asp.Net, or Asp.Net Core. If you're on Asp.Net/Asp.Net core project, the configuration story will be better than what you have done in the dummy project.
Here is some examples that could be helpful https://github.com/yantang-msft/service-fabric-application-insights-example