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

feat: log http response body in debug mode #95

Merged
merged 6 commits into from Sep 10, 2021
Merged

Conversation

MayurGubrele
Copy link
Member

@MayurGubrele MayurGubrele commented Aug 23, 2021

  • Adding functionality to log HTTP response body when log_level=debug
  • Classes affected: AbstractHttpSink.java, SerializableHttpResponse.java, SerializableHttpResponseTest.java HttpSinkTest.java, PromSinkTest.java

@kevinbheda
Copy link
Contributor

we should log the source message incase we receive no response from downstream.

@MayurGubrele
Copy link
Member Author

we should log the source message incase we receive no response from downstream.

We do it when the response received is null

import java.util.List;
import java.util.stream.Collectors;

public class SerializableHttpResponse implements Serializable {
Copy link
Member

Choose a reason for hiding this comment

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

what is the purpose of this class?
we can just call the debug method, if debug level is enabled.

@@ -85,6 +90,10 @@ private boolean shouldLogRequest(HttpResponse response) {
return response == null || getRequestLogStatusCodeRanges().containsKey(response.getStatusLine().getStatusCode());
}

private boolean shouldLogResponse(HttpResponse response) {
return response != null;
Copy link
Member

Choose a reason for hiding this comment

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

shouldn't this return true if the debug level is enabled?

Copy link
Member

Choose a reason for hiding this comment

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

we can add a method in instrumentation if not already there.
and call that

 if (instrumentation.isDebugEnabled()) {
    instrumentation.logDebug("");
 }

@@ -48,6 +49,10 @@ public AbstractHttpSink(Instrumentation instrumentation, String sinkType, HttpCl
try {
response = httpClient.execute(httpRequest);
getInstrumentation().logInfo("Response Status: {}", statusCode(response));
if (shouldLogResponse(response)) {
SerializableHttpResponse serializableHttpResponse = new SerializableHttpResponse(response);
Copy link
Member

Choose a reason for hiding this comment

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

I am a little sceptical of creating a new SerializableHttpResponse class for every non-empty response. I guess it won't matter much since it's in the local scope. But still, we can have a check, right ?

@arujit
Copy link
Member

arujit commented Sep 6, 2021

@MayurGubrele this branch has some conflicts right now. Can you please check and update things accordingly. Will merge post that.

Copy link
Member

@lavkesh lavkesh left a comment

Choose a reason for hiding this comment

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

Let's check the instrumentation.isDebugEnabled() before calling the instrumentation.debug() as the parameter evaluation cost is relatively more.. It's a standard practice, please read it here.
https://logging.apache.org/log4j/1.2/manual.html#Performance

Let's remove the SerializableHttpResponse class entirely, It's not needed.

@ravisuhag ravisuhag changed the title feat: Log http response body in debug mode feat: log http response body in debug mode Sep 10, 2021
@ravisuhag ravisuhag merged commit 1918215 into main Sep 10, 2021
@ravisuhag ravisuhag deleted the log-http-response branch September 10, 2021 04:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants