extensions icon indicating copy to clipboard operation
extensions copied to clipboard

AddExtendedHttpClientLogging is truncating body response when it mustn't do it

Open bryansan-msft opened this issue 1 year ago • 2 comments

Description

I'm querying an API that returns a big json (around 250KB) and the application which makes this request have configured response body logging using the AddExtendedHttpClientLogging method from the Microsoft.Extensions.Http.Diagnostics 8.10.0 nuget library. For some reason, the body of the response is truncated when reading it from the HttpResponseMessage so I am not able to process the response. If i disable body logging the response is not truncated at all.

I tried a very small json response like around 1KB and the response is not truncated at all. However, I tried a json around 64KB and it is truncated.

I tried increasing the body limit from the default value to 1.5MB when calling the method AddExtendedHttpClientLogging, which it shouldnt be necessary at all to be honest, and the 64KB test is no longer truncated so it is something related to this configuration. As far as I understand the library can truncate the emitted log but it shouldnt being truncating the final response.

Reproduction Steps

ConsoleApp2.zip

Expected behavior

Final response that you read from a HttpResponseMessage shouldnt be truncated in any scenario. Logs emitted by the library can be truncated depending on what you configured.

Actual behavior

Final response that you read from a HttpResponseMessage is being truncated depending on what you configured in the library.

Regression?

Cant say it.

Known Workarounds

Havent found any, just stop using the library and do your own logging class.

Configuration

I attached a console app in this issue but is also happening in an asp.net application.

Partial result of dotnet --info .NET SDK: Version: 8.0.403 Commit: c64aa40a71 Workload version: 8.0.400-manifests.e99c892e MSBuild version: 17.11.9+a69bbaaf5

Runtime Environment: OS Name: Windows OS Version: 10.0.26100 OS Platform: Windows RID: win-x64

Other information

No response

bryansan-msft avatar Oct 11 '24 13:10 bryansan-msft

@dariusclay

evgenyfedorov2 avatar Oct 11 '24 13:10 evgenyfedorov2

There's some things to consider here. One, logging the response body should not be used in production contexts. Next, even when logging the body there will be some overhead due to having to buffer the response and pipe it back to the caller. The fix will come soon as I have already been working on this issue internally.

dariusclay avatar Oct 14 '24 08:10 dariusclay

Thank very much @dariusclay

ghost avatar Nov 18 '24 11:11 ghost