Search code examples
c#azureazure-functionsazure-application-insightstelemetry

Is there memory impact or performance cause without TelemetryClient.Flush()


Using telemetry client to log custom event log as follow:

  var telemetryClient = new TelemetryClient();
  telemetryClient.InstrumentationKey = "<your actual insight instrumentkey>";    
  telemetryClient.TrackRequest(req.RequestUri.ToString(), DateTime.Now, Stopwatch.StartNew().Elapsed, "200", true);

My question is: do we need to flush the client using telemetryClient.Flush() or is it not required?

Even when not flushing it also works and we are able to see the log.


Solution

  • Usually, you don't need to call flush() if you not aware of the point in which the application is shut down. The flush is really pushing all the data into app insights (background).

    But let say if you know the point in which the application is shut down then you can call the flush manually to make sure all the data sent properly(without keeping anything in the buffer)

    Typically if you call the flush it will send the data immediately without keeping in the buffer

    Refer this SO