Skip to content

Commit

Permalink
Update Apache HttpClient5 to 5.4.1
Browse files Browse the repository at this point in the history
  • Loading branch information
reta committed Feb 19, 2025
1 parent f8fce2d commit d6032fd
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 6 deletions.
3 changes: 1 addition & 2 deletions instrumentation/httpclient5/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@
<main.basedir>${project.basedir}/../..</main.basedir>

<!-- To obey the integration tests, we need to use the version >= 5.2 -->
<!-- TODO: pinned due to timeouts on 5.4.x on brave.httpclient5.ITTracingCachingH2ClientBuilder.cacheControl -->
<httpclient5.version>5.3.1</httpclient5.version>
<httpclient5.version>5.4.1</httpclient5.version>
</properties>

<dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ static boolean isLocalCached(HttpContext context, Span span) {
if (!HAS_CLIENT_CACHE_SUPPORT) {
return false;
}
boolean cacheHit = CacheResponseStatus.CACHE_HIT == context.getAttribute(
HttpCacheContext.CACHE_RESPONSE_STATUS);
final HttpCacheContext cacheContext = HttpCacheContext.cast(context);
final boolean cacheHit = CacheResponseStatus.CACHE_HIT == cacheContext.getCacheResponseStatus();
if (cacheHit) {
span.tag("http.cache_hit", "");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import java.io.IOException;
import java.util.concurrent.Future;
import org.apache.hc.client5.http.impl.async.CloseableHttpAsyncClient;
import org.apache.hc.client5.http.protocol.HttpClientContext;
import org.apache.hc.core5.concurrent.FutureCallback;
import org.apache.hc.core5.function.Supplier;
import org.apache.hc.core5.http.HttpHost;
Expand Down Expand Up @@ -58,15 +59,17 @@ protected <T> Future<T> doExecute(
HandlerFactory<AsyncPushConsumer> pushHandlerFactory, HttpContext context,
FutureCallback<T> callback) {
TraceContext invocationContext = currentTraceContext.get();

final HttpClientContext clientContext = HttpClientContext.castOrCreate(context);
if (invocationContext != null) {
context.setAttribute(TraceContext.class.getName(), invocationContext);
clientContext.setAttribute(TraceContext.class.getName(), invocationContext);
}

if (callback != null && invocationContext != null) {
callback = new TraceContextFutureCallback<>(callback, currentTraceContext, invocationContext);
}

return delegate.execute(target, requestProducer, responseConsumer, pushHandlerFactory, context,
return delegate.execute(target, requestProducer, responseConsumer, pushHandlerFactory, clientContext,
callback);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@
import brave.propagation.SamplingFlags;
import brave.propagation.TraceContext;
import java.io.IOException;
import java.time.ZonedDateTime;
import java.util.Arrays;
import okhttp3.mockwebserver.MockResponse;
import org.apache.hc.client5.http.impl.async.H2AsyncClientBuilder;
import org.apache.hc.client5.http.impl.cache.CachingH2AsyncClientBuilder;
import org.apache.hc.client5.http.utils.DateUtils;
import org.junit.jupiter.api.Test;

import static brave.Span.Kind.CLIENT;
Expand All @@ -33,6 +35,7 @@ protected H2AsyncClientBuilder newClientBuilder() {
server.enqueue(new MockResponse()
.addHeader("Content-Type", "text/plain")
.addHeader("Cache-Control", "max-age=600, stale-while-revalidate=1200")
.addHeader("Date", DateUtils.FORMATTER_RFC1123.format(ZonedDateTime.now()))
.setBody("Hello"));

TraceContext parent = newTraceContext(SamplingFlags.SAMPLED);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@
import brave.propagation.SamplingFlags;
import brave.propagation.TraceContext;
import java.io.IOException;
import java.time.ZonedDateTime;
import java.util.Arrays;
import okhttp3.mockwebserver.MockResponse;
import org.apache.hc.client5.http.impl.async.HttpAsyncClientBuilder;
import org.apache.hc.client5.http.impl.cache.CachingHttpAsyncClientBuilder;
import org.apache.hc.client5.http.utils.DateUtils;
import org.junit.jupiter.api.Test;

import static brave.Span.Kind.CLIENT;
Expand All @@ -32,6 +34,7 @@ protected HttpAsyncClientBuilder newClientBuilder() {
server.enqueue(new MockResponse()
.addHeader("Content-Type", "text/plain")
.addHeader("Cache-Control", "max-age=600, stale-while-revalidate=1200")
.addHeader("Date", DateUtils.FORMATTER_RFC1123.format(ZonedDateTime.now()))
.setBody("Hello"));

TraceContext parent = newTraceContext(SamplingFlags.SAMPLED);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@
import brave.propagation.SamplingFlags;
import brave.propagation.TraceContext;
import java.io.IOException;
import java.time.ZonedDateTime;
import java.util.Arrays;
import okhttp3.mockwebserver.MockResponse;
import org.apache.hc.client5.http.impl.cache.CachingHttpClientBuilder;
import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
import org.apache.hc.client5.http.utils.DateUtils;
import org.junit.jupiter.api.Test;

import static brave.Span.Kind.CLIENT;
Expand All @@ -32,6 +34,7 @@ protected CloseableHttpClient newClient(int port) {
server.enqueue(new MockResponse()
.addHeader("Content-Type", "text/plain")
.addHeader("Cache-Control", "max-age=600, stale-while-revalidate=1200")
.addHeader("Date", DateUtils.FORMATTER_RFC1123.format(ZonedDateTime.now()))
.setBody("Hello"));

TraceContext parent = newTraceContext(SamplingFlags.SAMPLED);
Expand Down

0 comments on commit d6032fd

Please sign in to comment.