백현명
백현명

Reputation: 21

What are the differences between ExchangeStrategies and wiretap for WebClient logging?

I am working with Spring WebClient and exploring ways to enable detailed logging for debugging purposes. Specifically, I am looking at two approaches: ExchangeStrategies and wiretap. Below are the details of my configuration:

  1. Using wiretap for logging.

    I have configured the WebClient to use Netty's wiretap feature to log network-level data for HTTP requests and responses:

    HttpClient httpClient = HttpClient.create()
    .wiretap("reactor.netty.http.client.HttpClient", LogLevel.DEBUG, AdvancedByteBufFormat.TEXTUAL);
    
    WebClient webClient = WebClient.builder()
    .clientConnector(new ReactorClientHttpConnector(httpClient))
    .build();
    

    This logs details such as headers, request body, response body, and HTTP status codes at the network level.

  2. Using ExchangeStrategies for logging.

    Additionally, I enabled logging for the serialization/deserialization process by customizing the ExchangeStrategies:

    ExchangeStrategies strategies = ExchangeStrategies.builder()
        .codecs(configurer -> configurer.defaultCodecs().maxInMemorySize(1024 * 1024 * 50))
        .build();
    
    strategies.messageWriters().stream()
        .filter(LoggingCodecSupport.class::isInstance)
        .forEach(writer -> ((LoggingCodecSupport) writer).setEnableLoggingRequestDetails(true));
    

    This approach focuses on logging details during the transformation of request and response bodies into objects.

My questions:

  1. What are the functional differences between ExchangeStrategies and wiretap for debugging purposes in WebClient?
  2. Are there scenarios where one method is preferred over the other?
  3. How can I ensure that both the serialization/deserialization process and network-level data are logged in detail?

Environment:
Spring Boot: 3.3.2
Spring WebFlux: 3.3.2
Reactor Netty: 1.2.6
JDK: 17

Upvotes: 0

Views: 15

Answers (0)

Related Questions