Open
Description
- Nuget Packages : Microsoft.ApplicationInsights (2.23)
- Runtime version : net9.0
- Hosting environment : Windows x64
Describe the bug
When the exception contains a very long message (>32k characters), the AppInsights package silently fails saving the exception in the exception table.
Also, when an exception contains somme inner exceptions with big stacktraces, this threshold can be reach faster (see example below, with 5 exception messages with 10k characters each) (strange : it works fine with 10 exceptions of 5k characters, and with 4 exceptions of 10k characters (so total characters is > 32k))
Possible similar issues :
#2284
#2946
To Reproduce
using Microsoft.ApplicationInsights.Extensibility;
using Microsoft.ApplicationInsights;
using System.Text;
class Program
{
public static void Main(string[] args)
{
var telemetryConfig = TelemetryConfiguration.CreateDefault();
var aiConnectionString = "yourConnectionString";
telemetryConfig.ConnectionString = aiConnectionString;
var telemetryClient = new TelemetryClient(telemetryConfig);
Console.WriteLine("Press a key...");
Console.ReadLine();
try
{
ThrowNestedExceptions(5);
}
catch (Exception ex)
{
telemetryClient.TrackException(ex);
}
telemetryClient.Flush();
Task.Delay(1000).Wait();
Console.WriteLine("Done! Press a key...");
Console.ReadLine();
}
static void ThrowNestedExceptions(int depth)
{
const int messageLength = 10000;
try
{
if (depth > 0)
{
ThrowNestedExceptions(depth - 1);
}
else
{
throw new Exception(BuildLongMessage(messageLength));
}
}
catch (Exception ex)
{
throw new Exception(BuildLongMessage(messageLength), ex);
}
}
static string BuildLongMessage(int length)
{
var sb = new StringBuilder();
for (int i = 0; i<length; i++)
{
sb.Append('x');
}
return sb.ToString();
}
}