Skip to content
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

ProblemDetailsMiddleware and DiagnosticListener.Write for handled exceptions #193

Open
dungimon opened this issue Apr 25, 2023 · 0 comments

Comments

@dungimon
Copy link

I'm using your library along with ElasticAPM and the unfortunate combination of both is causing all my handled exceptions to be logged in elastic. I only want unhandled exceptions to be logged so actual exceptions that need attention aren't lost in the noise. Unfortunately the app I work on throws and handles more exceptions that I'd like, and the likelihood of a system wide refactoring anytime soon is unlikely.

The culprit is line 126 of Hellang.Middleware.ProblemDetails.ProblemDetailsMiddleware:

private const string DiagnosticListenerKey = "Microsoft.AspNetCore.Diagnostics.HandledException";
......        
if (DiagnosticListener.IsEnabled() && DiagnosticListener.IsEnabled(DiagnosticListenerKey))
{
    DiagnosticListener.Write(DiagnosticListenerKey, new { httpContext = context, exception = error });
}

Because the elastic apm automatically adds the AspNetCoreErrorDiagnosticsSubscriber (non-negotiable) then the IsEnabled always returns true and the diagnostic write is always executed.

Is there a workaround for this? or is there scope for this library to accomodate this and allow for this to be toggled on/off? thanks!

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

No branches or pull requests

1 participant