How to prevent losing telemetry events with Application Insight's Persistence Channel?

三世轮回 提交于 2020-01-01 12:06:11

问题


I have integrated Microsoft Application Insights into my Windows Forms app. In the document Application Insights on Windows Desktop apps, services and worker roles which uses the default in-memory channel, after flushing the application sleeps for one second before exiting.

 tc.Flush(); // only for desktop apps

 // Allow time for flushing:
 System.Threading.Thread.Sleep(1000);

The document states:

Note that Flush() is synchronous for the persistence channel, but asynchronous for other channels.

As this example is using the in-memory channel, I can deduct that flushing in the code example is asynchronous, hence the sleep.

In my code I'm using the persistence channel. Just before exiting my program I'm raising an event Application Shutdown:

static void Main(string[] args)
{
    try { /* application code */ }
    finally
    {
        Telemetry.Instance.TrackEvent("Application Shutdown");
        Telemetry.Instance.Flush();
        System.Threading.Thread.Sleep(1000); // allow time for flushing
    }
}

Sticking to the documentation, Flush is synchronous so the sleep is not needed prior to application exit. Looking at the events arriving in the Azure portal, I can see though that for most users the Application Shutdown event is not arriving in the cloud. Stepping through the debugger and stepping over Flush I cannot feel any delay also.

I'm sure that I use persistence channel because I can see data is buffered in %LOCALAPPDATA%\Microsoft\ApplicationInsights.

My questions is:

  • As Persistence Channel's Flush clearly is synchronous, what could be the issue that the last events of every application run are not displayed in Azure?

回答1:


If I remember this correctly, Flush() synchronously writes the remaining telemetry to the buffer (%LOCALAPPDATA% in case of the persistent channel), but it does not initiate any delivery action. I would expect this telemetry to show up later on with the next application start if the buffer location does not change because AI will read the buffered data and will send it out. I might be mistaken here, the logic behind this could've been changed a while ago..



来源:https://stackoverflow.com/questions/33239928/how-to-prevent-losing-telemetry-events-with-application-insights-persistence-ch

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!