Skip to content

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Sep 25, 2025

Fixes #36057
Fixes #35852

This PR documents the new SuppressDiagnosticsCallback setting introduced in .NET 10 as part of the exception handler middleware improvements.

Changes Made

Enhanced IExceptionHandler Documentation

  • Added explanation that IExceptionHandler contains a single method (TryHandleAsync)
  • Documented how the exception handling middleware works by iterating through registered handlers
  • Clarified the behavior when exceptions are handled vs. unhandled

Documented .NET 10 Breaking Change

  • Explained that .NET 10 now suppresses diagnostics (logs and metrics) for handled exceptions by default
  • Noted the difference from .NET 8 and 9 behavior where diagnostics were always emitted
  • Added context about why this change was made based on user feedback

Added New Configuration Section

Created a dedicated "SuppressDiagnosticsCallback" section with practical code examples:

Revert to .NET 8/9 behavior:

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

Conditional suppression based on exception type:

app.UseExceptionHandler(new ExceptionHandlerOptions
{
    SuppressDiagnosticsCallback = context => context.Exception is ArgumentException
});

Added Documentation Links

  • Ensured the breaking change announcement link is accessible in Additional resources

Updated Metadata

  • Added ai-usage: ai-assisted metadata as required
  • Updated ms.date to current date

Review Feedback Addressed

  • Changed "The built-in implementation" to "Exception handling middleware" for clarity
  • Removed redundant xref link from Additional resources

The documentation now provides developers with clear guidance on how to configure exception diagnostics behavior in .NET 10 while maintaining backward compatibility options.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

@Copilot Copilot AI changed the title [WIP] Document new ExceptionHandlerOptions.SuppressDiagnosticsCallback setting -- part 2 code and text for the new feature Document new ExceptionHandlerOptions.SuppressDiagnosticsCallback setting Sep 25, 2025
@Copilot Copilot AI requested a review from tdykstra September 25, 2025 18:47
Copilot finished work on behalf of tdykstra September 25, 2025 18:47
Copy link
Contributor

@tdykstra tdykstra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot This looks really good! I just left a couple suggestions, which I'd like to resolve before asking others to review.

@tdykstra tdykstra marked this pull request as ready for review September 29, 2025 15:17
Copy link
Contributor

@wadepickett wadepickett left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tdykstra, Looks good, approved, assuming the change you suggested is committed.

@tdykstra tdykstra requested a review from JamesNK September 29, 2025 18:14
`IExceptionHandler` implementations are registered by calling [`IServiceCollection.AddExceptionHandler<T>`](/dotnet/api/microsoft.extensions.dependencyinjection.exceptionhandlerservicecollectionextensions.addexceptionhandler). The lifetime of an `IExceptionHandler` instance is singleton. Multiple implementations can be added, and they're called in the order registered.

If an exception handler handles a request, it can return `true` to stop processing. If an exception isn't handled by any exception handler, then control falls back to the default behavior and options from the middleware. Different metrics and logs are emitted for handled versus unhandled exceptions.
The built-in implementation works by iterating through the registered exception handlers in order until one returns `true` from `TryHandleAsync`, indicating that the exception has been handled. If an exception handler handles an exception, it can return `true` to stop processing. If an exception isn't handled by any exception handler, then control falls back to the default behavior and options from the middleware.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot

The built-in implementation works by iterating through the registered exception handlers

The built-in implementation of what? I don't think this is clear.

I think it should be rephrased to something like:

Exception handling middleware interates through registered exception handlers...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated to clarify that it's the exception handling middleware that iterates through registered exception handlers. See commit 2c8a4e5.

@JamesNK
Copy link
Member

JamesNK commented Sep 29, 2025

One thing that I commented above. Otherwise it looks good.

@Copilot Copilot AI requested a review from JamesNK September 29, 2025 23:38
Copilot finished work on behalf of JamesNK September 29, 2025 23:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Document new ExceptionHandlerOptions.SuppressDiagnosticsCallback setting -- part 2 code and text for the new feature Document new ExceptionHandlerOptions.SuppressDiagnosticsCallback setting -- part 1 moniker version include files
4 participants