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();
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With