Skip to content

Commit f5d12e4

Browse files
committed
Clean up
1 parent e7cf4c9 commit f5d12e4

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

src/Middleware/Diagnostics/src/ExceptionHandler/ExceptionHandlerMiddlewareImpl.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,6 @@ private async Task HandleException(HttpContext context, ExceptionDispatchInfo ed
116116

117117
if ((edi.SourceException is OperationCanceledException || edi.SourceException is IOException) && context.RequestAborted.IsCancellationRequested)
118118
{
119-
// Don't log unhandled exception for aborted request.
120119
_logger.RequestAbortedException();
121120

122121
if (!context.Response.HasStarted)
@@ -131,9 +130,9 @@ private async Task HandleException(HttpContext context, ExceptionDispatchInfo ed
131130
// We can't do anything if the response has already started, just abort.
132131
if (context.Response.HasStarted)
133132
{
134-
DiagnosticsTelemetry.ReportUnhandledException(_logger, context, edi.SourceException);
135133
_logger.ResponseStartedErrorHandler();
136134

135+
DiagnosticsTelemetry.ReportUnhandledException(_logger, context, edi.SourceException);
137136
_metrics.RequestException(exceptionName, ExceptionResult.Skipped, handler: null);
138137
edi.Throw();
139138
}
@@ -251,7 +250,7 @@ private async Task HandleException(HttpContext context, ExceptionDispatchInfo ed
251250
return;
252251
}
253252

254-
// Log original unhandled exception before it is wrapped.
253+
// Exception is unhandled. Record diagnostics for the unhandled exception before it is wrapped.
255254
DiagnosticsTelemetry.ReportUnhandledException(_logger, context, edi.SourceException);
256255

257256
edi = ExceptionDispatchInfo.Capture(new InvalidOperationException($"The exception handler configured on {nameof(ExceptionHandlerOptions)} produced a 404 status response. " +

src/Middleware/Diagnostics/src/ExceptionHandler/ExceptionHandlerOptions.cs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

4+
using System.Diagnostics.Tracing;
45
using Microsoft.AspNetCore.Diagnostics;
56
using Microsoft.AspNetCore.Http;
7+
using Microsoft.Extensions.Logging;
68

79
namespace Microsoft.AspNetCore.Builder;
810

@@ -48,9 +50,25 @@ public class ExceptionHandlerOptions
4850
public Func<Exception, int>? StatusCodeSelector { get; set; }
4951

5052
/// <summary>
51-
/// Gets or sets a callback that can return <see langword="true" /> be used to suppress some diagnostics by <see cref="ExceptionHandlerMiddleware" />.
53+
/// Gets or sets a callback that can return <see langword="true" /> be used to suppress diagnostics by <see cref="ExceptionHandlerMiddleware" />.
54+
/// <para>
5255
/// This callback is only run if the exception was handled by the middleware.
5356
/// Unhandled exceptions and exceptions thrown after the response has started are always logged.
57+
/// </para>
58+
/// <para>
59+
/// Suppress diagnostics include:
60+
/// </para>
61+
/// <list type="bullet">
62+
/// <item>
63+
/// <description>Logging <c>UnhandledException</c> to <see cref="ILogger"/>.</description>
64+
/// </item>
65+
/// <item>
66+
/// <description>Writing <c>Microsoft.AspNetCore.Diagnostics.HandledException</c> event to <see cref="EventSource" />.</description>
67+
/// </item>
68+
/// <item>
69+
/// <description>Adding <c>error.type</c> tag to the <c>http.server.request.duration</c> metric.</description>
70+
/// </item>
71+
/// </list>
5472
/// </summary>
5573
public Func<ExceptionHandlerSuppressDiagnosticsContext, bool>? SuppressDiagnosticsCallback { get; set; }
5674
}

0 commit comments

Comments
 (0)