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

Capturing response metrics in HttpResponse.OnStarting #456

Open
ofsjoerdk opened this issue Nov 28, 2023 · 0 comments
Open

Capturing response metrics in HttpResponse.OnStarting #456

ofsjoerdk opened this issue Nov 28, 2023 · 0 comments

Comments

@ofsjoerdk
Copy link

Related to this: #150. HttpRequestCountMiddleware/HttpRequestDurationMiddleware record response status codes before asp.net's built-in exception handling has kicked in, thus recording a response that's about to turn into a http 500 as http 200. The mentioned issue suggests to use ExceptionHandlerMiddleware, but I'd much rather just let asp's default exception handling kick in and record the actual response afterwards.

One way of doing that would be hooking into HttpContext.Response.OnStarting, and only call HttpRequestCountMiddleware.CreateChild().Inc() and HttpRequestDurationMiddleware.CreateChild().Observe() from there. I'm currently doing that through a bit of reflection (and being sure not to actually insert HttpRequest* middleware into the asp pipeline, just increment their counters) but this is obviously not a preferred solution. It seems to work fine, though.

So my question is, would it be possible to provide alternate versions of HttpRequestCountMiddleware/HttpRequestDurationMiddleware that record metrics "as late as possible"? Or alternatively, expose enough of the internal API to be able to implement that stuff manually without resorting to using reflection?

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