-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Changed HttpLoggingPolicy
to ensure a response is logged even if its body is never consumed by a client.
#39964
Conversation
…body is never consumed by a client.
# Conflicts: # sdk/core/azure-core/src/main/java/com/azure/core/http/policy/HttpLoggingPolicy.java
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should ensure we close/consume bodies whenever possible because, orthogonal to logging, this signals underlying HTTP client implementation that response is consumed and it can return the underlying connection to the pool where it can be used for other requests.
Not closing the response body leads (orthogonally to logging) to connection staying 'busy' waiting for someone to consume the response, creating a bottleneck for the application.
While I have no objections eagerly buffering when request/response body logging is enabled, I believe we need to solve a bigger problem (if) we leak connections.
sdk/core/azure-core/src/main/java/com/azure/core/http/policy/HttpLoggingPolicy.java
Outdated
Show resolved
Hide resolved
sdk/core/azure-core/src/main/java/com/azure/core/http/policy/HttpLoggingPolicy.java
Show resolved
Hide resolved
sdk/core/azure-core/src/main/java/com/azure/core/http/policy/HttpLoggingPolicy.java
Outdated
Show resolved
Hide resolved
API change check API changes are not detected in this pull request. |
Currently, the
HttpLoggingPolicy.LoggingHttpResponse
class we use for logging a response will only log when either itsFlux<ByteBuffer> getBody()
orBinaryData getBodyAsBinaryData()
methods get called (I assume to avoid eagerly buffering the response body). This causes a situation where policies such asBearerTokenAuthenticationPolicy
don't log the response because they don't care about accessing the body but only the headers.We're changing the logic in
HttpLoggingPolicy
to log the response no matter if the body is accessed or not. If theHttpLogLevel
does not include the body (e.g.HEADERS
), then it will not be consumed eagerly, otherwise we will include it in the log. We assume body logging is used in non-production scenarios, as it is more resource intensive, and it usually is enabled only when debugging issues.As for tests, there are still a few failing ones, so I'll spend some time this week fixing that scenario.