Edit

Share via


Exception diagnostics are suppressed when IExceptionHandler.TryHandleAsync returns true

The ASP.NET Core exception handler middleware no longer records diagnostics for exceptions handled by IExceptionHandler by default.

Version introduced

.NET 10 Preview 7

Previous behavior

Previously, the exception handler middleware recorded diagnostics about exceptions handled by IExceptionHandler.

The exception diagnostics are:

New behavior

Starting in .NET 10, if IExceptionHandler.TryHandleAsync returns true, then exception diagnostics are no longer recorded by default.

Type of breaking change

This change is a behavioral change.

Reason for change

ASP.NET Core users have given feedback that the previous behavior was undesirable. Their IExceptionHandler implementation reported that the exception was handled, but the error handling middleware still recorded the error in the app's telemetry.

ASP.NET Core now follows the behavior expected by users by suppressing diagnostics when IExceptionHandler handles the exception. Configuration options are also available to customize exception diagnostics behavior if needed.

If you want handled exceptions to continue to record telemetry, you can use the new ExceptionHandlerOptions.SuppressDiagnosticsCallback option:

app.UseExceptionHandler(new ExceptionHandlerOptions
{
    SuppressDiagnosticsCallback = context => false;
});

The context passed to the callback includes information about the exception, the request, and whether the exception was handled. The callback returns false to indicate that diagnostics shouldn't be suppressed, thus restoring the previous behavior.

Affected APIs