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

Missing overrides in LoggingHttpMessageHandler and LoggingScopeHttpMessageHandler #85143

Merged
merged 26 commits into from
May 4, 2023

Conversation

mphelt
Copy link
Contributor

@mphelt mphelt commented Apr 21, 2023

add missing overrides in LoggingHttpMessageHandler and LoggingScopeHttpMessageHandler

Fixes #85104

@ghost ghost added the community-contribution Indicates that the PR has been added by a community member label Apr 21, 2023
@ghost
Copy link

ghost commented Apr 21, 2023

Tagging subscribers to this area: @dotnet/ncl
See info in area-owners.md if you want to be subscribed.

Issue Details

add missing overrides in LoggingHttpMessageHandler and LoggingScopeHttpMessageHandler (#85104)

Author: mphelt
Assignees: -
Labels:

area-Extensions-HttpClientFactory, community-contribution

Milestone: -

@mphelt
Copy link
Contributor Author

mphelt commented Apr 21, 2023

@dotnet-policy-service agree

@CarnaViire
Copy link
Member

@mphelt thanks for your contribution!
You need to surround your overrides in #if NET5_0_OR_GREATER because synchronous Send was only added in .NET 5: https://learn.microsoft.com/en-us/dotnet/api/system.net.http.httpmessagehandler.send
And test should have a filter as well: [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNetCore))]

@mphelt
Copy link
Contributor Author

mphelt commented Apr 25, 2023

@CarnaViire

You need to surround your overrides in #if NET5_0_OR_GREATER

I've added them, but I didn't thought of it initially, as none of the base classes has those conditions - how are they different?

@Wraith2
I've fixed those typos in both my copy of the remarks as well as the source one.

Comment on lines 79 to 88
var shouldRedactHeaderValue = _options?.ShouldRedactHeaderValue ?? _shouldNotRedactHeaderValue;

// Not using a scope here because we always expect this to be at the end of the pipeline, thus there's
// not really anything to surround.
Log.RequestStart(_logger, request, shouldRedactHeaderValue);
var stopwatch = ValueStopwatch.StartNew();
var response = base.Send(request, cancellationToken);
Log.RequestEnd(_logger, response, stopwatch.GetElapsedTime(), shouldRedactHeaderValue);

return response;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we deduplicate this logic between Send and SendAsync (same for LoggingScopeHttpMessageHandler)?

E.g. by extracting it to a helper method

private async Task<HttpResponseMessage> SendAsyncCore(HttpRequestMessage request, bool async, CancellationToken cancellationToken)

@mphelt mphelt marked this pull request as ready for review April 27, 2023 11:53
Copy link
Member

@MihaZupan MihaZupan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a few comments regarding the code style used in this repo, otherwise looks good, thanks.

Unfortunately I had to add #if NET5_0_OR_GREATER directives inside useAsync ? ... : ... - is there a cleaner way to do that?

I think it's okay as-is.

@CarnaViire
Copy link
Member

I've added them, but I didn't thought of it initially, as none of the base classes has those conditions - how are they different?

It's because previously only .NET Standard 2.0 API surface was used, which includes only async send: https://learn.microsoft.com/en-us/dotnet/api/system.net.http.delegatinghandler.sendasync?view=netstandard-2.0 -- because Microsoft.Extensions.Http is compiled for .NET Standard 2.0.
But we missed the fact that when it's used in .NET 5+ apps, the sync API can be used, but it won't be overridden.

Handlers that this PR is changing are not sealed, should I make those helper methods protected virtual?

This would be adding the helper method to the public surface, which should go through API review process: https://github.com/dotnet/runtime/blob/main/docs/project/api-review-process.md
In general, I don't think it would bring too much value, as it's more of an implementation detail. Users can still derive from and substitute the logging handlers -- they would just need to override both of the Sends, which is true for deriving from DelegatingHandler as well.
As for configuring logging, there's a separate umbrella issue for that: #77312

@mphelt
Copy link
Contributor Author

mphelt commented May 4, 2023

@CarnaViire, thank you for explanation. Is there any way to re-run those failing checks? They seem to have failed for reasons not connected to this particular PR.

@CarnaViire
Copy link
Member

@mphelt I believe the failures were fixed in #85304, could you please update to the latest main? Thanks!

Copy link
Member

@CarnaViire CarnaViire left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

@CarnaViire
Copy link
Member

Test failure is unrelated #85772

@CarnaViire CarnaViire merged commit 4b104fb into dotnet:main May 4, 2023
@karelz karelz added this to the 8.0.0 milestone May 27, 2023
@ghost ghost locked as resolved and limited conversation to collaborators Jun 26, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-Extensions-HttpClientFactory community-contribution Indicates that the PR has been added by a community member
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Missing overrides in LoggingHttpMessageHandler and LoggingScopeHttpMessageHandler
5 participants