ApplicationInsights-dotnet icon indicating copy to clipboard operation
ApplicationInsights-dotnet copied to clipboard

What should the Delay be? 5 seconds or 5years?

Open mikeblakeuk opened this issue 2 years ago • 1 comments

What should the Delay be? 5 seconds or 5years?

Should it be async?

https://github.com/microsoft/ApplicationInsights-dotnet/blob/405fd6a9916956f2233520c8ab66110a1f9dcfbc/examples/ConsoleApp/Program.cs#L56

mikeblakeuk avatar Jun 14 '22 11:06 mikeblakeuk

Or 1 second? https://docs.microsoft.com/en-us/azure/azure-monitor/app/worker-service

Or can we just add a helper method to do this for us!?

mikeblakeuk avatar Jun 14 '22 11:06 mikeblakeuk

You are talking about the Delay after the Flush() method, usually in an application shutdown. I also think it's not very well documented. I just opened a feedback here, if you want to give a thumbs up 👍 😄

In general, it depends on the TelemetryChannel configured by your logger. The default is ServerTelemetryChannel, but there is also an InMemoryChannel.

So if you use an InMemoryChannel you need to know that Flush() is synchronized, so you don't need to use any Thread.Sleep() or Task.Delay() methods.

But if you have a ServerTelemetryChannel, and this is probably the case, you should use Sleep or Delay, and how much time to spent there depends on several aspects. In my projects we initially used 3 seconds but after some problems we put 10 seconds and it was better. And, I think this should make you smile, the FlushAsync() method has been released, which solves the problem :)

gioce90 avatar Feb 03 '23 08:02 gioce90

So it's not needed when using FlushAsync ?

mikeblakeuk avatar Feb 03 '23 10:02 mikeblakeuk

So it's not needed when using FlushAsync ?

Correct. Although you should probably consider passing a CancellationToken with a long timeout (1 minute, say?) on the FlushAsync in case there is some problem that blocks transmission.

pharring avatar Feb 03 '23 17:02 pharring

Should the TODO be done/removed? https://github.com/microsoft/ApplicationInsights-dotnet/blob/24e5b04e8f8a08de8efd1a973293e65914dd3df5/BASE/src/Microsoft.ApplicationInsights/TelemetryClient.cs#L694

mikeblakeuk avatar Feb 08 '23 17:02 mikeblakeuk

Also the docs need to include the mandatory CancellationToken https://learn.microsoft.com/en-gb/azure/azure-monitor/app/api-custom-events-metrics#flushing-data

mikeblakeuk avatar Feb 08 '23 17:02 mikeblakeuk

Should the TODO be done/removed?

https://github.com/microsoft/ApplicationInsights-dotnet/blob/24e5b04e8f8a08de8efd1a973293e65914dd3df5/BASE/src/Microsoft.ApplicationInsights/TelemetryClient.cs#L694

No. Its still a TODO. (Its specifically referring to in-memory metrics aggregation (every 1 minute), which is not flushed with TelemetryClient.Flush

cijothomas avatar Feb 08 '23 17:02 cijothomas

This issue is stale because it has been open 300 days with no activity. Remove stale label or this will be closed in 7 days. Commenting will instruct the bot to automatically remove the label.

github-actions[bot] avatar Dec 06 '23 00:12 github-actions[bot]