-
Notifications
You must be signed in to change notification settings - Fork 10.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add diagnostics exception handling metrics #48648
Conversation
@@ -36,6 +36,7 @@ public class ExceptionHandlerMiddleware | |||
options, | |||
diagnosticListener, | |||
Enumerable.Empty<IExceptionHandler>(), | |||
new DummyMeterFactory(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I hate public middleware. We end up having to screw around with constructors and DI.
Any objection to creating an issue to make them obsolete and eventually remove them?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess it means we only need to worry about API compat on AddX and UseX extension methods that might exist for each middleware.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes obsolete them as Error and make them throw, but we've about given up removing APIs due to binary compat.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess it means we only need to worry about API compat on AddX and UseX extension methods that might exist for each middleware.
Yes. The important thing is the constructor isn't public. It is easy to modify dependencies.
@@ -159,13 +156,16 @@ public async Task Invoke(HttpContext context) | |||
WriteDiagnosticEvent(_diagnosticSource, eventName, new { httpContext = context, exception = ex }); | |||
} | |||
|
|||
_metrics.RequestException(exceptionName, ExceptionResult.Unhandled, handler: null); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Handled? I guess not since it was not handled by the app, just default logic.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I put Unhandled
here because it's literally right below a diagnostic event that reports the exception as unhandled:
Lines 156 to 160 in 6575b28
const string eventName = "Microsoft.AspNetCore.Diagnostics.UnhandledException"; | |
if (_diagnosticSource.IsEnabled(eventName)) | |
{ | |
WriteDiagnosticEvent(_diagnosticSource, eventName, new { httpContext = context, exception = ex }); | |
} |
|
||
namespace Microsoft.AspNetCore.Diagnostics; | ||
|
||
internal sealed class DummyMeterFactory : IMeterFactory |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not needed if you make the public middleware constructor throw.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not a big deal to add this.
Making the public middleware ctor throw would require breaking change process. I'd prefer to leave it working and go with obsoleting and eventually removing it. Less disruptive.
API review: #48670 |
5ea33e0
to
b615955
Compare
b615955
to
c657f73
Compare
@JamesNK, this change will be considered for inclusion in the blog post for the release it'll ship in. Nice work! Please ensure that the original comment in this thread contains a clear explanation of what the change does, why it's important (what problem does it solve?), and, if relevant, include things like code samples and/or performance numbers. This content may not be exactly what goes into the blog post, but it will help the team putting together the announcement. Thanks! |
Fixes #48625
Adds a new meter and counter. The counter is used by developer exception middleware and exception handler middleware.
Result of handler:
OperationCanceledException
+RequestAborted.IsCancellationRequested
)IExceptionHandler
returns true,IProblemDetailsService
returns true, or the status code is anything other than 404. If anIExceptionHandler
orIProblemDetailsService
return true then the type name is set for thehandler
tag.Note: The
exception-name
is still enriched onto the main HTTP request counter. Other detail (result, handler) is only available on the new counter.