Simpler Apache HttpClient request wrapper
MODIFY
instrumentation/apache-httpclient/apache-httpclient-4.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/apachehttpclient/v4_0/ApacheHttpClientHelper.java
instrumentation/apache-httpclient/apache-httpclient-4.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/apachehttpclient/v4_0/ApacheHttpClientHelper.java
@@ -9,12 +9,11 @@ import static io.opentelemetry.javaagent.instrumentation.apachehttpclient.v4_0.A
import io.opentelemetry.context.Context;
import org.apache.http.HttpResponse;
-import org.apache.http.client.methods.HttpUriRequest;
public final class ApacheHttpClientHelper {
public static void doMethodExit(
- Context context, HttpUriRequest request, Object result, Throwable throwable) {
+ Context context, ApacheHttpClientRequest request, Object result, Throwable throwable) {
if (throwable != null) {
instrumenter().end(context, request, null, throwable);
} else if (result instanceof HttpResponse) {

MODIFY
instrumentation/apache-httpclient/apache-httpclient-4.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/apachehttpclient/v4_0/ApacheHttpClientHttpAttributesExtractor.java
instrumentation/apache-httpclient/apache-httpclient-4.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/apachehttpclient/v4_0/ApacheHttpClientHttpAttributesExtractor.java
package io.opentelemetry.javaagent.instrumentation.apachehttpclient.v4_0;
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpAttributesExtractor;
-import io.opentelemetry.semconv.trace.attributes.SemanticAttributes;
-import java.net.URI;
-import org.apache.http.Header;
import org.apache.http.HttpResponse;
-import org.apache.http.ProtocolVersion;
-import org.apache.http.client.methods.HttpUriRequest;
import org.checkerframework.checker.nullness.qual.Nullable;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
final class ApacheHttpClientHttpAttributesExtractor
- extends HttpAttributesExtractor<HttpUriRequest, HttpResponse> {
-
- private static final Logger logger =
- LoggerFactory.getLogger(ApacheHttpClientHttpAttributesExtractor.class);
+ extends HttpAttributesExtractor<ApacheHttpClientRequest, HttpResponse> {
@Override
- protected String method(HttpUriRequest request) {
+ protected String method(ApacheHttpClientRequest request) {
return request.getMethod();
}
@Override
- protected String url(HttpUriRequest request) {
- return request.getURI().toString();
+ protected String url(ApacheHttpClientRequest request) {
+ return request.getUrl();
}
@Override
- protected String target(HttpUriRequest request) {
- URI uri = request.getURI();
- String pathString = uri.getPath();
- String queryString = uri.getQuery();
- if (pathString != null && queryString != null) {
- return pathString + "?" + queryString;
- } else if (queryString != null) {
- return "?" + queryString;
- } else {
- return pathString;
- }
+ protected String target(ApacheHttpClientRequest request) {
+ return request.getTarget();
}
@Override
@Nullable
- protected String host(HttpUriRequest request) {
- Header header = request.getFirstHeader("Host");
- if (header != null) {
- return header.getValue();
- }
- return null;
+ protected String host(ApacheHttpClientRequest request) {
+ return request.getHeader("Host");
}
@Override
@Nullable
- protected String scheme(HttpUriRequest request) {
- return request.getURI().getScheme();
+ protected String scheme(ApacheHttpClientRequest request) {
+ return request.getScheme();
}
@Override
@Nullable
- protected String userAgent(HttpUriRequest request) {
- Header header = request.getFirstHeader("User-Agent");
- return header != null ? header.getValue() : null;
+ protected String userAgent(ApacheHttpClientRequest request) {
+ return request.getHeader("User-Agent");
}
@Override
@Nullable
- protected Long requestContentLength(HttpUriRequest request, @Nullable HttpResponse response) {
+ protected Long requestContentLength(
+ ApacheHttpClientRequest request, @Nullable HttpResponse response) {
return null;
}
@Override
@Nullable
protected Long requestContentLengthUncompressed(
- HttpUriRequest request, @Nullable HttpResponse response) {
+ ApacheHttpClientRequest request, @Nullable HttpResponse response) {
return null;
}
@Override
- protected Integer statusCode(HttpUriRequest request, HttpResponse response) {
+ protected Integer statusCode(ApacheHttpClientRequest request, HttpResponse response) {
return response.getStatusLine().getStatusCode();
}
@Override
@Nullable
- protected String flavor(HttpUriRequest request, @Nullable HttpResponse response) {
- ProtocolVersion protocolVersion = request.getRequestLine().getProtocolVersion();
- String protocol = protocolVersion.getProtocol();
- if (!protocol.equals("HTTP")) {
- return null;
- }
- int major = protocolVersion.getMajor();
- int minor = protocolVersion.getMinor();
- if (major == 1 && minor == 0) {
- return SemanticAttributes.HttpFlavorValues.HTTP_1_0;
- }
- if (major == 1 && minor == 1) {
- return SemanticAttributes.HttpFlavorValues.HTTP_1_1;
- }
- if (major == 2 && minor == 0) {
- return SemanticAttributes.HttpFlavorValues.HTTP_2_0;
- }
- logger.debug("unexpected http protocol version: " + protocolVersion);
- return null;
+ protected String flavor(ApacheHttpClientRequest request, @Nullable HttpResponse response) {
+ return request.getFlavor();
}
@Override
@Nullable
- protected Long responseContentLength(HttpUriRequest request, HttpResponse response) {
+ protected Long responseContentLength(ApacheHttpClientRequest request, HttpResponse response) {
return null;
}
@Override
@Nullable
- protected Long responseContentLengthUncompressed(HttpUriRequest request, HttpResponse response) {
+ protected Long responseContentLengthUncompressed(
+ ApacheHttpClientRequest request, HttpResponse response) {
return null;
}
@Override
@Nullable
- protected String serverName(HttpUriRequest request, @Nullable HttpResponse response) {
+ protected String serverName(ApacheHttpClientRequest request, @Nullable HttpResponse response) {
return null;
}
@Override
@Nullable
- protected String route(HttpUriRequest request) {
+ protected String route(ApacheHttpClientRequest request) {
return null;
}
@Override
@Nullable
- protected String clientIp(HttpUriRequest request, @Nullable HttpResponse response) {
+ protected String clientIp(ApacheHttpClientRequest request, @Nullable HttpResponse response) {
return null;
}
}

MODIFY
instrumentation/apache-httpclient/apache-httpclient-4.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/apachehttpclient/v4_0/ApacheHttpClientInstrumentation.java
instrumentation/apache-httpclient/apache-httpclient-4.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/apachehttpclient/v4_0/ApacheHttpClientInstrumentation.java
@@ -129,14 +129,18 @@ public class ApacheHttpClientInstrumentation implements TypeInstrumentation {
@Advice.OnMethodEnter(suppress = Throwable.class)
public static void methodEnter(
@Advice.Argument(0) HttpUriRequest request,
+ @Advice.Local("otelRequest") ApacheHttpClientRequest otelRequest,
@Advice.Local("otelContext") Context context,
@Advice.Local("otelScope") Scope scope) {
Context parentContext = currentContext();
- if (!instrumenter().shouldStart(parentContext, request)) {
+
+ otelRequest = new ApacheHttpClientRequest(request);
+
+ if (!instrumenter().shouldStart(parentContext, otelRequest)) {
return;
}
- context = instrumenter().start(parentContext, request);
+ context = instrumenter().start(parentContext, otelRequest);
scope = context.makeCurrent();
}
@@ -145,6 +149,7 @@ public class ApacheHttpClientInstrumentation implements TypeInstrumentation {
@Advice.Argument(0) HttpUriRequest request,
@Advice.Return Object result,
@Advice.Thrown Throwable throwable,
+ @Advice.Local("otelRequest") ApacheHttpClientRequest otelRequest,
@Advice.Local("otelContext") Context context,
@Advice.Local("otelScope") Scope scope) {
if (scope == null) {
@@ -152,7 +157,7 @@ public class ApacheHttpClientInstrumentation implements TypeInstrumentation {
}
scope.close();
- ApacheHttpClientHelper.doMethodExit(context, request, result, throwable);
+ ApacheHttpClientHelper.doMethodExit(context, otelRequest, result, throwable);
}
}
@@ -163,20 +168,25 @@ public class ApacheHttpClientInstrumentation implements TypeInstrumentation {
public static void methodEnter(
@Advice.Argument(0) HttpUriRequest request,
@Advice.Argument(value = 1, readOnly = false) ResponseHandler<?> handler,
+ @Advice.Local("otelRequest") ApacheHttpClientRequest otelRequest,
@Advice.Local("otelContext") Context context,
@Advice.Local("otelScope") Scope scope) {
Context parentContext = currentContext();
- if (!instrumenter().shouldStart(parentContext, request)) {
+
+ otelRequest = new ApacheHttpClientRequest(request);
+
+ if (!instrumenter().shouldStart(parentContext, otelRequest)) {
return;
}
- context = instrumenter().start(parentContext, request);
+ context = instrumenter().start(parentContext, otelRequest);
scope = context.makeCurrent();
// Wrap the handler so we capture the status code
if (handler != null) {
handler =
- new WrappingStatusSettingResponseHandler<>(context, parentContext, request, handler);
+ new WrappingStatusSettingResponseHandler<>(
+ context, parentContext, otelRequest, handler);
}
}
@@ -185,6 +195,7 @@ public class ApacheHttpClientInstrumentation implements TypeInstrumentation {
@Advice.Argument(0) HttpUriRequest request,
@Advice.Return Object result,
@Advice.Thrown Throwable throwable,
+ @Advice.Local("otelRequest") ApacheHttpClientRequest otelRequest,
@Advice.Local("otelContext") Context context,
@Advice.Local("otelScope") Scope scope) {
if (scope == null) {
@@ -192,7 +203,7 @@ public class ApacheHttpClientInstrumentation implements TypeInstrumentation {
}
scope.close();
- ApacheHttpClientHelper.doMethodExit(context, request, result, throwable);
+ ApacheHttpClientHelper.doMethodExit(context, otelRequest, result, throwable);
}
}
@@ -203,18 +214,18 @@ public class ApacheHttpClientInstrumentation implements TypeInstrumentation {
public static void methodEnter(
@Advice.Argument(0) HttpHost host,
@Advice.Argument(1) HttpRequest request,
- @Advice.Local("fullRequest") HttpUriRequest fullRequest,
+ @Advice.Local("otelRequest") ApacheHttpClientRequest otelRequest,
@Advice.Local("otelContext") Context context,
@Advice.Local("otelScope") Scope scope) {
Context parentContext = currentContext();
- fullRequest = new HostAndRequestAsHttpUriRequest(host, request);
+ otelRequest = new ApacheHttpClientRequest(host, request);
- if (!instrumenter().shouldStart(parentContext, fullRequest)) {
+ if (!instrumenter().shouldStart(parentContext, otelRequest)) {
return;
}
- context = instrumenter().start(parentContext, fullRequest);
+ context = instrumenter().start(parentContext, otelRequest);
scope = context.makeCurrent();
}
@@ -222,7 +233,7 @@ public class ApacheHttpClientInstrumentation implements TypeInstrumentation {
public static void methodExit(
@Advice.Return Object result,
@Advice.Thrown Throwable throwable,
- @Advice.Local("fullRequest") HttpUriRequest fullRequest,
+ @Advice.Local("otelRequest") ApacheHttpClientRequest otelRequest,
@Advice.Local("otelContext") Context context,
@Advice.Local("otelScope") Scope scope) {
if (scope == null) {
@@ -230,7 +241,7 @@ public class ApacheHttpClientInstrumentation implements TypeInstrumentation {
}
scope.close();
- ApacheHttpClientHelper.doMethodExit(context, fullRequest, result, throwable);
+ ApacheHttpClientHelper.doMethodExit(context, otelRequest, result, throwable);
}
}
@@ -242,22 +253,22 @@ public class ApacheHttpClientInstrumentation implements TypeInstrumentation {
@Advice.Argument(0) HttpHost host,
@Advice.Argument(1) HttpRequest request,
@Advice.Argument(value = 2, readOnly = false) ResponseHandler<?> handler,
- @Advice.Local("fullRequest") HttpUriRequest fullRequest,
+ @Advice.Local("otelRequest") ApacheHttpClientRequest otelRequest,
@Advice.Local("otelContext") Context context,
@Advice.Local("otelScope") Scope scope) {
Context parentContext = currentContext();
- if (!instrumenter().shouldStart(parentContext, fullRequest)) {
+ if (!instrumenter().shouldStart(parentContext, otelRequest)) {
return;
}
- context = instrumenter().start(parentContext, fullRequest);
+ context = instrumenter().start(parentContext, otelRequest);
scope = context.makeCurrent();
// Wrap the handler so we capture the status code
if (handler != null) {
handler =
new WrappingStatusSettingResponseHandler<>(
- context, parentContext, fullRequest, handler);
+ context, parentContext, otelRequest, handler);
}
}
@@ -265,7 +276,7 @@ public class ApacheHttpClientInstrumentation implements TypeInstrumentation {
public static void methodExit(
@Advice.Return Object result,
@Advice.Thrown Throwable throwable,
- @Advice.Local("fullRequest") HttpUriRequest fullRequest,
+ @Advice.Local("otelRequest") ApacheHttpClientRequest otelRequest,
@Advice.Local("otelContext") Context context,
@Advice.Local("otelScope") Scope scope) {
if (scope == null) {
@@ -273,7 +284,7 @@ public class ApacheHttpClientInstrumentation implements TypeInstrumentation {
}
scope.close();
- ApacheHttpClientHelper.doMethodExit(context, fullRequest, result, throwable);
+ ApacheHttpClientHelper.doMethodExit(context, otelRequest, result, throwable);
}
}
}

MODIFY
instrumentation/apache-httpclient/apache-httpclient-4.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/apachehttpclient/v4_0/ApacheHttpClientNetAttributesExtractor.java
instrumentation/apache-httpclient/apache-httpclient-4.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/apachehttpclient/v4_0/ApacheHttpClientNetAttributesExtractor.java
@@ -7,49 +7,30 @@ package io.opentelemetry.javaagent.instrumentation.apachehttpclient.v4_0;
import io.opentelemetry.instrumentation.api.instrumenter.net.NetAttributesExtractor;
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes;
-import java.net.URI;
import org.apache.http.HttpResponse;
-import org.apache.http.client.methods.HttpUriRequest;
import org.checkerframework.checker.nullness.qual.Nullable;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
final class ApacheHttpClientNetAttributesExtractor
- extends NetAttributesExtractor<HttpUriRequest, HttpResponse> {
-
- private static final Logger logger =
- LoggerFactory.getLogger(ApacheHttpClientNetAttributesExtractor.class);
+ extends NetAttributesExtractor<ApacheHttpClientRequest, HttpResponse> {
@Override
- public String transport(HttpUriRequest request) {
+ public String transport(ApacheHttpClientRequest request) {
return SemanticAttributes.NetTransportValues.IP_TCP;
}
@Override
- public @Nullable String peerName(HttpUriRequest request, @Nullable HttpResponse response) {
- return request.getURI().getHost();
+ public @Nullable String peerName(
+ ApacheHttpClientRequest request, @Nullable HttpResponse response) {
+ return request.getPeerName();
}
@Override
- public Integer peerPort(HttpUriRequest request, @Nullable HttpResponse response) {
- URI uri = request.getURI();
- int port = uri.getPort();
- if (port != -1) {
- return port;
- }
- switch (uri.getScheme()) {
- case "http":
- return 80;
- case "https":
- return 443;
- default:
- logger.debug("no default port mapping for scheme: {}", uri.getScheme());
- return null;
- }
+ public Integer peerPort(ApacheHttpClientRequest request, @Nullable HttpResponse response) {
+ return request.getPeerPort();
}
@Override
- public @Nullable String peerIp(HttpUriRequest request, @Nullable HttpResponse response) {
+ public @Nullable String peerIp(ApacheHttpClientRequest request, @Nullable HttpResponse response) {
return null;
}
}

ADD
instrumentation/apache-httpclient/apache-httpclient-4.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/apachehttpclient/v4_0/ApacheHttpClientRequest.java
+/*
+ * Copyright The OpenTelemetry Authors
+ * SPDX-License-Identifier: Apache-2.0
+ */
+
+package io.opentelemetry.javaagent.instrumentation.apachehttpclient.v4_0;
+
+import io.opentelemetry.semconv.trace.attributes.SemanticAttributes;
+import java.net.URI;
+import java.net.URISyntaxException;
+import org.apache.http.Header;
+import org.apache.http.HttpHost;
+import org.apache.http.HttpRequest;
+import org.apache.http.ProtocolVersion;
+import org.apache.http.client.methods.HttpUriRequest;
+import org.checkerframework.checker.nullness.qual.Nullable;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public final class ApacheHttpClientRequest {
+
+ private static final Logger logger = LoggerFactory.getLogger(ApacheHttpClientRequest.class);
+
+ @Nullable private final URI uri;
+
+ private final HttpRequest delegate;
+
+ public ApacheHttpClientRequest(HttpHost httpHost, HttpRequest httpRequest) {
+ URI calculatedUri;
+ try {
+ calculatedUri = new URI(httpHost.toURI() + httpRequest.getRequestLine().getUri());
+ } catch (URISyntaxException e) {
+ logger.debug(e.getMessage(), e);
+ calculatedUri = null;
+ }
+ uri = calculatedUri;
+ delegate = httpRequest;
+ }
+
+ public ApacheHttpClientRequest(HttpUriRequest httpRequest) {
+ uri = httpRequest.getURI();
+ delegate = httpRequest;
+ }
+
+ public String getHeader(String name) {
+ Header header = delegate.getFirstHeader(name);
+ return header != null ? header.getValue() : null;
+ }
+
+ public void setHeader(String name, String value) {
+ delegate.setHeader(name, value);
+ }
+
+ public String getMethod() {
+ return delegate.getRequestLine().getMethod();
+ }
+
+ public String getUrl() {
+ return uri != null ? uri.toString() : null;
+ }
+
+ public String getTarget() {
+ if (uri == null) {
+ return null;
+ }
+ String pathString = uri.getPath();
+ String queryString = uri.getQuery();
+ if (pathString != null && queryString != null) {
+ return pathString + "?" + queryString;
+ } else if (queryString != null) {
+ return "?" + queryString;
+ } else {
+ return pathString;
+ }
+ }
+
+ public String getScheme() {
+ return uri != null ? uri.getScheme() : null;
+ }
+
+ public String getFlavor() {
+ ProtocolVersion protocolVersion = delegate.getProtocolVersion();
+ String protocol = protocolVersion.getProtocol();
+ if (!protocol.equals("HTTP")) {
+ return null;
+ }
+ int major = protocolVersion.getMajor();
+ int minor = protocolVersion.getMinor();
+ if (major == 1 && minor == 0) {
+ return SemanticAttributes.HttpFlavorValues.HTTP_1_0;
+ }
+ if (major == 1 && minor == 1) {
+ return SemanticAttributes.HttpFlavorValues.HTTP_1_1;
+ }
+ if (major == 2 && minor == 0) {
+ return SemanticAttributes.HttpFlavorValues.HTTP_2_0;
+ }
+ logger.debug("unexpected http protocol version: " + protocolVersion);
+ return null;
+ }
+
+ public String getPeerName() {
+ return uri != null ? uri.getHost() : null;
+ }
+
+ public Integer getPeerPort() {
+ if (uri == null) {
+ return null;
+ }
+ int port = uri.getPort();
+ if (port != -1) {
+ return port;
+ }
+ switch (uri.getScheme()) {
+ case "http":
+ return 80;
+ case "https":
+ return 443;
+ default:
+ logger.debug("no default port mapping for scheme: {}", uri.getScheme());
+ return null;
+ }
+ }
+}

MODIFY
instrumentation/apache-httpclient/apache-httpclient-4.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/apachehttpclient/v4_0/ApacheHttpClientSingletons.java
instrumentation/apache-httpclient/apache-httpclient-4.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/apachehttpclient/v4_0/ApacheHttpClientSingletons.java
@@ -14,25 +14,24 @@ import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanNameExtrac
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanStatusExtractor;
import io.opentelemetry.javaagent.instrumentation.api.instrumenter.PeerServiceAttributesExtractor;
import org.apache.http.HttpResponse;
-import org.apache.http.client.methods.HttpUriRequest;
public final class ApacheHttpClientSingletons {
private static final String INSTRUMENTATION_NAME = "io.opentelemetry.apache-httpclient-4.0";
- private static final Instrumenter<HttpUriRequest, HttpResponse> INSTRUMENTER;
+ private static final Instrumenter<ApacheHttpClientRequest, HttpResponse> INSTRUMENTER;
static {
- HttpAttributesExtractor<HttpUriRequest, HttpResponse> httpAttributesExtractor =
+ HttpAttributesExtractor<ApacheHttpClientRequest, HttpResponse> httpAttributesExtractor =
new ApacheHttpClientHttpAttributesExtractor();
- SpanNameExtractor<? super HttpUriRequest> spanNameExtractor =
+ SpanNameExtractor<? super ApacheHttpClientRequest> spanNameExtractor =
HttpSpanNameExtractor.create(httpAttributesExtractor);
- SpanStatusExtractor<? super HttpUriRequest, ? super HttpResponse> spanStatusExtractor =
+ SpanStatusExtractor<? super ApacheHttpClientRequest, ? super HttpResponse> spanStatusExtractor =
HttpSpanStatusExtractor.create(httpAttributesExtractor);
ApacheHttpClientNetAttributesExtractor netAttributesExtractor =
new ApacheHttpClientNetAttributesExtractor();
INSTRUMENTER =
- Instrumenter.<HttpUriRequest, HttpResponse>newBuilder(
+ Instrumenter.<ApacheHttpClientRequest, HttpResponse>newBuilder(
GlobalOpenTelemetry.get(), INSTRUMENTATION_NAME, spanNameExtractor)
.setSpanStatusExtractor(spanStatusExtractor)
.addAttributesExtractor(httpAttributesExtractor)
@@ -41,7 +40,7 @@ public final class ApacheHttpClientSingletons {
.newClientInstrumenter(new HttpHeaderSetter());
}
- public static Instrumenter<HttpUriRequest, HttpResponse> instrumenter() {
+ public static Instrumenter<ApacheHttpClientRequest, HttpResponse> instrumenter() {
return INSTRUMENTER;
}

DELETE
instrumentation/apache-httpclient/apache-httpclient-4.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/apachehttpclient/v4_0/HostAndRequestAsHttpUriRequest.java
-/*
- * Copyright The OpenTelemetry Authors
- * SPDX-License-Identifier: Apache-2.0
- */
-
-package io.opentelemetry.javaagent.instrumentation.apachehttpclient.v4_0;
-
-import java.net.URI;
-import java.net.URISyntaxException;
-import org.apache.http.HttpHost;
-import org.apache.http.HttpRequest;
-import org.apache.http.ProtocolVersion;
-import org.apache.http.RequestLine;
-import org.apache.http.client.methods.HttpUriRequest;
-import org.apache.http.message.AbstractHttpMessage;
-import org.checkerframework.checker.nullness.qual.Nullable;
-
-/** Wraps HttpHost and HttpRequest into a HttpUriRequest for tracers and injectors. */
-public final class HostAndRequestAsHttpUriRequest extends AbstractHttpMessage
- implements HttpUriRequest {
-
- private final String method;
- private final RequestLine requestLine;
- private final ProtocolVersion protocolVersion;
- @Nullable private final URI uri;
-
- private final HttpRequest actualRequest;
-
- public HostAndRequestAsHttpUriRequest(HttpHost httpHost, HttpRequest httpRequest) {
- method = httpRequest.getRequestLine().getMethod();
- requestLine = httpRequest.getRequestLine();
- protocolVersion = requestLine.getProtocolVersion();
-
- URI calculatedUri;
- try {
- calculatedUri = new URI(httpHost.toURI() + httpRequest.getRequestLine().getUri());
- } catch (URISyntaxException e) {
- calculatedUri = null;
- }
- uri = calculatedUri;
- actualRequest = httpRequest;
- }
-
- @Override
- public void abort() {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public boolean isAborted() {
- return false;
- }
-
- @Override
- public void setHeader(String name, String value) {
- actualRequest.setHeader(name, value);
- }
-
- @Override
- public String getMethod() {
- return method;
- }
-
- @Override
- public RequestLine getRequestLine() {
- return requestLine;
- }
-
- @Override
- public ProtocolVersion getProtocolVersion() {
- return protocolVersion;
- }
-
- @Override
- public URI getURI() {
- return uri;
- }
-}

MODIFY
instrumentation/apache-httpclient/apache-httpclient-4.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/apachehttpclient/v4_0/HttpHeaderSetter.java
instrumentation/apache-httpclient/apache-httpclient-4.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/apachehttpclient/v4_0/HttpHeaderSetter.java
package io.opentelemetry.javaagent.instrumentation.apachehttpclient.v4_0;
import io.opentelemetry.context.propagation.TextMapSetter;
-import org.apache.http.client.methods.HttpUriRequest;
-final class HttpHeaderSetter implements TextMapSetter<HttpUriRequest> {
+final class HttpHeaderSetter implements TextMapSetter<ApacheHttpClientRequest> {
@Override
- public void set(HttpUriRequest carrier, String key, String value) {
+ public void set(ApacheHttpClientRequest carrier, String key, String value) {
carrier.setHeader(key, value);
}
}

MODIFY
instrumentation/apache-httpclient/apache-httpclient-4.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/apachehttpclient/v4_0/WrappingStatusSettingResponseHandler.java
instrumentation/apache-httpclient/apache-httpclient-4.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/apachehttpclient/v4_0/WrappingStatusSettingResponseHandler.java
@@ -12,16 +12,18 @@ import io.opentelemetry.context.Scope;
import java.io.IOException;
import org.apache.http.HttpResponse;
import org.apache.http.client.ResponseHandler;
-import org.apache.http.client.methods.HttpUriRequest;
public final class WrappingStatusSettingResponseHandler<T> implements ResponseHandler<T> {
private final Context context;
private final Context parentContext;
- private final HttpUriRequest request;
+ private final ApacheHttpClientRequest request;
private final ResponseHandler<T> handler;
public WrappingStatusSettingResponseHandler(
- Context context, Context parentContext, HttpUriRequest request, ResponseHandler<T> handler) {
+ Context context,
+ Context parentContext,
+ ApacheHttpClientRequest request,
+ ResponseHandler<T> handler) {
this.context = context;
this.parentContext = parentContext;
this.request = request;

Simpler Apache HttpClient request wrapper (#3489)