简体   繁体   中英

How do you integrate Application Insights into Service Fabric?

I currently use Azure Application Insights for logging on all of my Web API and MVC applications. Obviously the majority of this logging is automatic which is great. For events that I manually want to capture I have implemented a "LoggingUtility" which has methods like "LogError" and "LogInformation" that simply call Trace.TraceError and Trace.TraceInformation (the thinking is that the implementation of logging could be changed in one place in the future). The Trace is then captured by Application Insights.

I have started to develop some Stateful Services in Azure Service Fabric and cannot seem to find a way to use Application Insights. I have stumbled upon several articles pointing me towards a NuGet package that was in prerelease but has now been removed ( https://www.nuget.org/packages/Microsoft.ServiceFabric.Telemetry.ApplicationInsights/ ).

Of course the Service Fabric templates generate the "ServiceEventSource" but firstly I cannot see how this would be useful for Application Insights and ideally I want all logging to be done through my "LoggingUtility" class.

Is it possible to integrate Application Insights into Service Fabric? If so, can I simply continue using Trace (via my "LoggingUtility" class)?

You have two options: 1. Using the Application Insights SDK in your LoggingUtility class to send information directly to AI 2. Using Windows Azure Diagnostics (WAD) to forward Eventsource traces to AI, using the provided EventSource class in the SF project templates. That class you can modify to be your LoggingUtility class implementation.

Considering that you are running your SF cluster in Azure, the second approach is the current recommendation, as Service Fabric system service events are also using Event Tracing.

For configuring Azure Diagnostics to AI, follow the steps outlined in this article: https://azure.microsoft.com/en-us/blog/azure-diagnostics-integration-with-application-insights/

Be aware this article targets Cloud Services and VMs, but just use the VM Scale Set for configuring Azure Diagnostics in stead of a VM. That should work.

The NuGet package is no longer supported: https://social.msdn.microsoft.com/Forums/en-US/f0f1ad78-4d83-48e5-b1da-4a9f0eddb9b2/application-insights-for-service-fabric?forum=AzureServiceFabric

我们使用了新的Microsoft.Extensions.Logging并编写了一个见解记录器-它通过Trace获取服务结构消息,我们还提取了所有未添加的ETW内容。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM