How to see payload being sent to OpenSearch server through the JAVA library

Versions (relevant - OpenSearch/Dashboard/Server OS/Browser):

Describe the issue: How to see the payload being send to OpenSearch through the JAVA library.
I tried but I don’t see the actual payload :
final Logger logger2 = LoggerFactory.getLogger(“org.opensearch.client”);
((ch.qos.logback.classic.Logger) logger2).setLevel(Level.DEBUG);

I used the following code but is a lot of boiler plate code that I would like to avoid:

httpClientBuilder.addInterceptorLast( new HttpRequestInterceptor() {
@Override
public void process(HttpRequest request, HttpContext context) throws HttpException, IOException {
if (request instanceof HttpEntityEnclosingRequest) {
var entityRequest = (HttpEntityEnclosingRequest) request;
var entity = entityRequest.getEntity();
if (entity != null) {
var inputStream = entity.getContent();
var scanner = new Scanner(inputStream, StandardCharsets.UTF_8.name()).useDelimiter(“\A”);
var requestBody = scanner.next();
scanner.close();
var method = request.getRequestLine().getMethod();
logger.info(“OpenSearch, Method: ‘{}’ request {}”, method, requestBody);
}
}
}
}
);

Configuration:

Relevant Logs or Screenshots:

Hi @dnsmgr ,

AFAIK, Apache HttpClient 4.x / 5.x and opensearch-java clients do not provide the capability to log request / response payload and headers (since those could leak sensitive information). The approach with HttpRequestInterceptor (that you are using) is the most common way to implement that from application side.

Thank you.