Skip to content

Commit

Permalink
log request/response without body for POST (zalando#1571)
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthias Drews committed Jul 7, 2023
1 parent b94db6c commit ebdc72d
Show file tree
Hide file tree
Showing 2 changed files with 163 additions and 104 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import org.springframework.http.HttpMethod;
import org.springframework.http.server.reactive.ServerHttpRequest;
import org.springframework.http.server.reactive.ServerHttpRequestDecorator;
import reactor.core.publisher.Mono;
import reactor.core.publisher.Flux;

import java.util.Arrays;
Expand Down Expand Up @@ -49,10 +50,12 @@ public Flux<DataBuffer> getBody() {
private Publisher<? extends DataBuffer> bufferingWrap(Publisher<? extends DataBuffer> body) {
if (serverRequest.shouldBuffer()) {
return Flux
.from(DataBufferCopyUtils.wrapAndBuffer(body, serverRequest::buffer))
.doOnComplete(writeHook);
.from(DataBufferCopyUtils.wrapAndBuffer(body, serverRequest::buffer))
.doOnComplete(writeHook);
} else {
return body;
return Mono.fromRunnable(writeHook)
.contextCapture() // needed to log MDC fields like traceId/spanId
.thenMany(body);
}
}
}
Loading

0 comments on commit ebdc72d

Please sign in to comment.