ApplicationInsights-dotnet
ApplicationInsights-dotnet copied to clipboard
What should the Delay be? 5 seconds or 5years?
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
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!?
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 :)
So it's not needed when using FlushAsync ?
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.
Should the TODO be done/removed? https://github.com/microsoft/ApplicationInsights-dotnet/blob/24e5b04e8f8a08de8efd1a973293e65914dd3df5/BASE/src/Microsoft.ApplicationInsights/TelemetryClient.cs#L694
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
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
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.