Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TelemetryClient does not send any data unless Flush is called

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();
like image 827
Pawel Pabich Avatar asked Jun 18 '15 01:06

Pawel Pabich


2 Answers

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.

like image 156
Mario Hewardt Avatar answered Nov 12 '22 10:11

Mario Hewardt


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.

like image 20
James Bateson Avatar answered Nov 12 '22 10:11

James Bateson