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

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

Open
bryansan-msft opened this issue Oct 11, 2024 · 2 comments
Assignees
Labels
bug This issue describes a behavior which is not expected - a bug.

Comments

@bryansan-msft
Copy link

bryansan-msft commented Oct 11, 2024

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 bryansan-msft added bug This issue describes a behavior which is not expected - a bug. untriaged labels Oct 11, 2024
@evgenyfedorov2
Copy link
Contributor

@dariusclay

@dariusclay dariusclay self-assigned this Oct 14, 2024
@dariusclay
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue describes a behavior which is not expected - a bug.
Projects
None yet
Development

No branches or pull requests

3 participants