TelemetryClient does not send any data unless Flush is called

爱⌒轻易说出口 提交于 2019-12-23 07:36:43

问题


I'm using TelemetryClient (v0.17.0.576) directly in my code and it looks like I can push data to Azure only when I manually call Flush at the end which feels wrong. Am I missing something here ?

var configuration = TelemetryConfiguration.CreateDefault();
configuration.InstrumentationKey = "KEY";
var client = new TelemetryClient(configuration);

for (int i = 0; i < 10; i++)
{
   log.Information("Loop: {0} {1}", i, value);

   client.Track(new TraceTelemetry(value));
}
client.Flush();

回答1:


For performance reasons, the Application Insights SDK batches telemetry and sends it up in chunks. To see this in action you can replace your Flush call with a call to Thread.Sleep (70000) and you will see the instrumentation uploaded to AI once the app terminates.




回答2:


Adding to Mario Hewardt's answer. If you use the persistence channel:

TelemetryConfiguration.Active.TelemetryChannel = new PersistenceChannel();

Flush() is synchronous (so you don't need sleep the thread for an abitrary length of time). It also has the benefit of saving the telemetry data to a local file if Application Insights cannot be contacted, which will then be sent next time Flush() is called with a good connection.




回答3:


Thread.sleep(30000) is working for me, but flush is not working in application. I would like to use Flush() method as i can't sleep my application for 30 seconds. Is Flush() method is related to version Specific or i am missing something else?

I have Console application which call another Console Library, which will further call another console library which have telemetry class (ie Console Application --> DLL --> DLL (having telemetry implementation)).



来源:https://stackoverflow.com/questions/30904930/telemetryclient-does-not-send-any-data-unless-flush-is-called

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