I am logging the custom telemetry events using Telemetry Client in azure function. It logs the custom event almost every time certain event is triggered but it fails occasionally say once in a thousandth time. I can ascertain that no exception is thrown and event is processed successfully without any error. Here is an example of how I am logging the custom telemetry.
try
{
_telemetryClient.TrackEvent("MyCustomEventName",
new KeyValuePair<string, string>("CustomEvent",
JsonSerializer.Serialize(customEventObject)));
}
catch (Exception e)
{
_logger.LogError(e,"Failed to log CustomEventObject");
}
I am logging the exception if telemetry client fails and logger shows no exception. Is there any reason Telemetry Client could fail to dispatch the event? If yes, how to diagnose and handle it?
I am on .net core 3.1 with Azure Function Runtime 3.1.3.0