Support user agent in khttp
MODIFY
instrumentation/khttp-0.1/src/main/java/io/opentelemetry/auto/instrumentation/khttp/KHttpAdvice.java
instrumentation/khttp-0.1/src/main/java/io/opentelemetry/auto/instrumentation/khttp/KHttpAdvice.java
@@ -50,7 +50,7 @@ public class KHttpAdvice {
final Span span = TRACER.spanBuilder("HTTP " + method).setSpanKind(CLIENT).startSpan();
DECORATE.afterStart(span);
- DECORATE.onRequest(span, new RequestWrapper(method, uri));
+ DECORATE.onRequest(span, new RequestWrapper(method, uri, headers));
final Context context = withSpan(span, Context.current());

MODIFY
instrumentation/khttp-0.1/src/main/java/io/opentelemetry/auto/instrumentation/khttp/KHttpDecorator.java
instrumentation/khttp-0.1/src/main/java/io/opentelemetry/auto/instrumentation/khttp/KHttpDecorator.java
@@ -46,8 +46,7 @@ public class KHttpDecorator extends HttpClientDecorator<RequestWrapper, Response
@Override
protected String requestHeader(RequestWrapper requestWrapper, String name) {
- // TODO: Find out how to get request header.
- return null;
+ return requestWrapper.headers.get(name);
}
@Override

MODIFY
instrumentation/khttp-0.1/src/main/java/io/opentelemetry/auto/instrumentation/khttp/RequestWrapper.java
instrumentation/khttp-0.1/src/main/java/io/opentelemetry/auto/instrumentation/khttp/RequestWrapper.java
package io.opentelemetry.auto.instrumentation.khttp;
+import java.util.Map;
+
public class RequestWrapper {
- String method;
- String uri;
+ final String method;
+ final String uri;
+ final Map<String, String> headers;
- public RequestWrapper(String method, String uri) {
+ public RequestWrapper(String method, String uri, Map<String, String> headers) {
this.method = method;
this.uri = uri;
+ this.headers = headers;
}
}

MODIFY
instrumentation/khttp-0.1/src/test/groovy/KHttpClientTest.groovy
instrumentation/khttp-0.1/src/test/groovy/KHttpClientTest.groovy
@@ -21,6 +21,7 @@ class KHttpClientTest extends HttpClientTest {
@Override
int doRequest(String method, URI uri, Map<String, String> headers, Closure callback) {
+ headers.put("User-Agent", "khttp")
// khttp applies the same timeout for both connect and read
def timeoutSeconds = CONNECT_TIMEOUT_MS / 1000
def response = KHttp.request(method, uri.toString(), headers, Collections.emptyMap(), null, null, null, null, timeoutSeconds)
@@ -34,4 +35,9 @@ class KHttpClientTest extends HttpClientTest {
boolean testCircularRedirects() {
return false
}
+
+ @Override
+ String userAgent() {
+ return "khttp"
+ }
}

Support user agent in khttp (#719)