'How to reduce size of WebClient wiretap logs or chunks?

I am working with a microservice packaged in a Coretto Docker image and Spring Boot 2.5.7 + logstash

I've configured WebClient with wiretap feature to log every request and response. The problem is that the logs that arrive to the log platform, Datadog, are split every 16kb (don't know by which tool, probably by Docker). I know that WebClient reads chunks of data, but I would like to reduce its size so it fits in the log. Here some example of the logs (response body is trimmed by me for simplicity):

Expected, well formed JSON event:

{"event_type":"logging","event":{"timestamp":"2022-04-18T11:17:09.323Z","level":"DEBUG","thread_name":"reactor-http-nio-2","logger_name":"reactor.netty.http.client.HttpClient","message":"[2e922c83-1, L:/127.0.0.1:57016 - R:localhost/127.0.0.1:8000] READ: 2048B HTTP/1.1 200 OK\r\nContent-Type: application/vnd.mambu.v2+json\r ... 20.0000000000, \"disbu"}}
{"event_type":"logging","event":{"timestamp":"2022-04-18T11:17:09.323Z","level":"DEBUG","thread_name":"reactor-http-nio-2","logger_name":"reactor.netty.http.client.HttpClient","message":"rsementDetails\": {\n      \"encodedKey\": \"8a9a86967c931894017c995cfb9811ee\",\n      \"expectedDisbursementDate\": \"2021-10-19T15:34:37-03:00\",\n      \"disbursementDate\": \"2021-10-19T15:34:37-03:00\",\n      \"transactionDetails\": {\n        \"encodedKey\": \"8a9a86967c931894017c995cfb9811ef\"}}

Real output (missing JSON headers in second log line):

{"event_type":"logging","event":{"timestamp":"2022-04-18T11:17:09.641Z","level":"DEBUG","thread_name":"reactor-http-nio-2","logger_name":"reactor.netty.http.client.HttpClient","message":"[2e922c83-1, L:/127.0.0.1:57016 - R:localhost/127.0.0.1:8000] READ: 16384B     \"feesBalance\": 0,\n      \"penaltyDue\": 0,\n      \"penaltyPaid\": 0,\n      \"penaltyBalance\": 0,\n      \"holdBalance\": 0,\n    \"disbu

rsementDetails\": {\n      \"encodedKey\": \"8a9a86967c931894017c995cfb9811ee\",\n      \"expectedDisbursementDate\": \"2021-10-19T15:34:37-03:00\",\n      \"disbursementDate\": \"2021-10-19T15:34:37-03:00\",\n      \"transactionDetails\": {\n        \"encodedKey\": \"8a9a86967c931894017c995cfb9811ef\"}}

I already tried this config without success:

private val webClient = WebClient.builder()
    .defaultHeader("Accept", "application/json")
    .clientConnector(
        ReactorClientHttpConnector(
        HttpClient.create()
            .wiretap(HttpClient::class.java.name, LogLevel.DEBUG, AdvancedByteBufFormat.TEXTUAL)
        )
    )
    .exchangeStrategies(
        ExchangeStrategies.builder()
            .codecs { clientDefaultCodecsConfigurer: ClientCodecConfigurer ->
                clientDefaultCodecsConfigurer.defaultCodecs().maxInMemorySize(10000)
                val decoder = Jackson2JsonDecoder(
                    Jackson2ObjectMapperBuilder.json().build<ObjectMapper>(),
                    MediaType.APPLICATION_JSON,
                    MimeType.valueOf("application/json")
                )
                decoder.maxInMemorySize = 10000
                clientDefaultCodecsConfigurer.defaultCodecs().jackson2JsonDecoder(decoder)
            }.build()
    )


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source