diff --git a/src/main/java/org/prebid/server/bidder/HttpBidderRequester.java b/src/main/java/org/prebid/server/bidder/HttpBidderRequester.java index 2a2fde46430..aa917b017cb 100644 --- a/src/main/java/org/prebid/server/bidder/HttpBidderRequester.java +++ b/src/main/java/org/prebid/server/bidder/HttpBidderRequester.java @@ -26,6 +26,7 @@ import org.prebid.server.exception.PreBidException; import org.prebid.server.execution.Timeout; import org.prebid.server.json.JacksonMapper; +import org.prebid.server.log.ConditionalLogger; import org.prebid.server.log.Logger; import org.prebid.server.log.LoggerFactory; import org.prebid.server.model.CaseInsensitiveMultiMap; @@ -62,24 +63,28 @@ public class HttpBidderRequester { private static final Logger logger = LoggerFactory.getLogger(HttpBidderRequester.class); + private static final ConditionalLogger conditionalLogger = new ConditionalLogger(logger); private final HttpClient httpClient; private final BidderRequestCompletionTrackerFactory completionTrackerFactory; private final BidderErrorNotifier bidderErrorNotifier; private final HttpBidderRequestEnricher requestEnricher; private final JacksonMapper mapper; + private final double logSamplingRate; public HttpBidderRequester(HttpClient httpClient, BidderRequestCompletionTrackerFactory completionTrackerFactory, BidderErrorNotifier bidderErrorNotifier, HttpBidderRequestEnricher requestEnricher, - JacksonMapper mapper) { + JacksonMapper mapper, + double logSamplingRate) { this.httpClient = Objects.requireNonNull(httpClient); this.completionTrackerFactory = completionTrackerFactoryOrFallback(completionTrackerFactory); this.bidderErrorNotifier = Objects.requireNonNull(bidderErrorNotifier); this.requestEnricher = Objects.requireNonNull(requestEnricher); this.mapper = Objects.requireNonNull(mapper); + this.logSamplingRate = logSamplingRate; } /** @@ -241,9 +246,9 @@ private static byte[] gzip(byte[] value) { /** * Produces {@link Future} with {@link BidderCall} containing request and error description. */ - private static Future> failResponse(Throwable exception, HttpRequest httpRequest) { - logger.warn("Error occurred while sending HTTP request to a bidder url: {} with message: {}", - httpRequest.getUri(), exception.getMessage()); + private Future> failResponse(Throwable exception, HttpRequest httpRequest) { + conditionalLogger.warn("Error occurred while sending HTTP request to a bidder url: %s with message: %s" + .formatted(httpRequest.getUri(), exception.getMessage()), logSamplingRate); logger.debug("Error occurred while sending HTTP request to a bidder url: {}", exception, httpRequest.getUri()); diff --git a/src/main/java/org/prebid/server/spring/config/ServiceConfiguration.java b/src/main/java/org/prebid/server/spring/config/ServiceConfiguration.java index 71e014fcc23..7d657bc7b8c 100644 --- a/src/main/java/org/prebid/server/spring/config/ServiceConfiguration.java +++ b/src/main/java/org/prebid/server/spring/config/ServiceConfiguration.java @@ -752,11 +752,13 @@ HttpBidderRequester httpBidderRequester( HttpBidderRequestEnricher requestEnricher, JacksonMapper mapper) { - return new HttpBidderRequester(httpClient, + return new HttpBidderRequester( + httpClient, bidderRequestCompletionTrackerFactory, bidderErrorNotifier, requestEnricher, - mapper); + mapper, + logSamplingRate); } @Bean diff --git a/src/test/java/org/prebid/server/bidder/HttpBidderRequesterTest.java b/src/test/java/org/prebid/server/bidder/HttpBidderRequesterTest.java index 83079b4d825..2970e643595 100644 --- a/src/test/java/org/prebid/server/bidder/HttpBidderRequesterTest.java +++ b/src/test/java/org/prebid/server/bidder/HttpBidderRequesterTest.java @@ -117,7 +117,7 @@ public void setUp() { expiredTimeout = timeoutFactory.create(clock.instant().minusMillis(1500L).toEpochMilli(), 1000L); target = new HttpBidderRequester( - httpClient, null, bidderErrorNotifier, requestEnricher, jacksonMapper); + httpClient, null, bidderErrorNotifier, requestEnricher, jacksonMapper, 0.0); given(bidder.makeBidderResponse(any(BidderCall.class), any(BidRequest.class))).willCallRealMethod(); } @@ -506,7 +506,8 @@ public void processBids(List bids) { }, bidderErrorNotifier, requestEnricher, - jacksonMapper); + jacksonMapper, + 0.0); final BidRequest bidRequest = bidRequestWithDeals("deal1", "deal2"); final BidderRequest bidderRequest = BidderRequest.builder()