-
Notifications
You must be signed in to change notification settings - Fork 15
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
LogHttpDependency() - allow status codes within the range of 100 to 599 #516
Comments
I agree that we should not be too restrictive here. Complying with the RFC would indeed be better then relying on the pre-defined status codes in the .NET lib. But, the |
Thank you for your issue, @mic-hnk ! And your effort to fix this yourself. |
I agree with @mic-hnk that we should not be too harsh on checking if the http status code is a member of the HttpSTatusCode enum. Especially since an integer for which there's no enum value defined can be casted to a HttpStatusCode member. Moreover, in my opinion services should not fail or crash because of input-validation on cross cutting concerns like logging. |
It depends on what you want to achieve. In broader sense though there can be a server which replies with a valid http code which would break your library. It's not ideal that thing outside my control (server response's status code) results in an exception. - just a personal opinion ;) Make a final call please and I will move on. |
I agree with your opinion @mic-hnk . :) Therefore, my proposal would be some kind of implementation that looks like this: public void LogDependency (HttpStatusCode statusCode, .... )
{
LogDependency((int)statusCode, .... );
}
public void LogDependency (int statusCode, .... )
{
Guard.NotLessThen(statusCode, 100);
Guard.NotGreaterThen(statusCode, 599);
...
} |
When the PR is merged, I believe we should be able to create a new minor release. |
Agreed! 👍 |
Done in #515 |
🎉 @mic-hnk, your feature is now available in Observability v2.8! Thx again! |
Is your feature request related to a problem? Please describe.
One of http dependencies on my application returns status codes outside System.Net.HttpStatusCode enum range for some client errors.
It results in exceptions being thrown by the Guard rule:
Guard.For(() => !Enum.IsDefined(typeof(HttpStatusCode), statusCode), new ArgumentException("Requires a response HTTP status code that's within the bound of the enumeration to track a HTTP dependency"));
Describe the solution you'd like
I would like the extension method to allow status codes according to https://www.rfc-editor.org/rfc/rfc9110#name-status-codes
Describe alternatives you've considered
Alternatively, maybe logging component should not be busy with guarding http status codes. I would expect the http dependency entry to be logged regardless of the status code.
The solution would be to remove status code related guards from the discussed extension methods.
Additional context
I am happy to prepare a PR.
Possible code change: #515
The text was updated successfully, but these errors were encountered: