In .NET 8 ASP.NET Core applications, the new IExceptionHandler<T> exception handlers result in exceptions showing as Unhandled in the APM UI even when they return true to indicate the exception was handled.
Even though ArithmericExceptionHandler in the above reproduction correclty handles the exception and returns true the exception is still shown on the Errors tab as Unhandled in APM:
APM Agent version
1.26.0
Environment
Operating system and version: N/A
.NET Framework/Core name and version .NET 8.0.2
Application Target Framework(s) (e.g. net462, netcoreapp3.1): net80
Describe the bug
In .NET 8 ASP.NET Core applications, the new
IExceptionHandler<T>
exception handlers result in exceptions showing asUnhandled
in the APM UI even when they returntrue
to indicate the exception was handled.To Reproduce
A reproduction is available here: https://github.com/ben-wallis/apm-agent-dotnet/commit/be1ac9d63d9fda0055e87284e6b0572e6e2d0b2c
Even though
ArithmericExceptionHandler
in the above reproduction correclty handles the exception and returnstrue
the exception is still shown on the Errors tab as Unhandled in APM:Exceptions handled by
IExceptionHandler<T>
implementations emit theMicrosoft.AspNetCore.Diagnostics.HandledException
diagnostic event, whereas those that are truly unhandled emit theMicrosoft.AspNetCore.Diagnostics.UnhandledException
diagnostic event. Despite this difference, both diagnostic events result in the exception being captured as unhandled inAspNetCoreDiagnosticListener.cs
due to both of these diagnostic events being handled in the same code path: https://github.com/elastic/apm-agent-dotnet/blame/a82dba1e52b20f303c16a772c3fdfdbffcdbfb76/src/integrations/Elastic.Apm.AspNetCore/DiagnosticListener/AspNetCoreDiagnosticListener.cs#L77Expected behavior
Handled exceptions are not shown as Unhandled in the APM UI
Actual behavior
Handled exceptions are shown as Unhandled in the APM UI