Remove khttp instrumentation
DELETE
instrumentation/khttp-0.1/javaagent/khttp-0.1-javaagent.gradle
-apply from: "$rootDir/gradle/instrumentation.gradle"
-
-muzzle {
- pass {
- group = 'com.github.jkcclemens'
- module = 'khttp'
- versions = "(,)"
- assertInverse = true
- }
-}
-
-repositories {
- maven { url 'https://jitpack.io' }
-}
-
-dependencies {
- library 'com.github.jkcclemens:khttp:0.1.0'
-}
\ No newline at end of file

DELETE
instrumentation/khttp-0.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/khttp/KHttpHeadersInjectAdapter.java
-/*
- * Copyright The OpenTelemetry Authors
- * SPDX-License-Identifier: Apache-2.0
- */
-
-package io.opentelemetry.javaagent.instrumentation.khttp;
-
-import io.opentelemetry.context.propagation.TextMapSetter;
-import java.util.HashMap;
-import java.util.Map;
-
-public class KHttpHeadersInjectAdapter implements TextMapSetter<Map<String, String>> {
-
- public static Map<String, String> asWritable(Map<String, String> headers) {
- // Kotlin likes to use read-only data structures, so wrap into new writable map
- return new HashMap<>(headers);
- }
-
- public static final KHttpHeadersInjectAdapter SETTER = new KHttpHeadersInjectAdapter();
-
- @Override
- public void set(Map<String, String> carrier, String key, String value) {
- carrier.put(key, value);
- }
-}

DELETE
instrumentation/khttp-0.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/khttp/KHttpInstrumentation.java
-/*
- * Copyright The OpenTelemetry Authors
- * SPDX-License-Identifier: Apache-2.0
- */
-
-package io.opentelemetry.javaagent.instrumentation.khttp;
-
-import static io.opentelemetry.javaagent.extension.matcher.AgentElementMatchers.extendsClass;
-import static io.opentelemetry.javaagent.extension.matcher.ClassLoaderMatcher.hasClassesNamed;
-import static io.opentelemetry.javaagent.instrumentation.api.Java8BytecodeBridge.currentContext;
-import static io.opentelemetry.javaagent.instrumentation.khttp.KHttpHeadersInjectAdapter.asWritable;
-import static io.opentelemetry.javaagent.instrumentation.khttp.KHttpTracer.tracer;
-import static net.bytebuddy.matcher.ElementMatchers.isAbstract;
-import static net.bytebuddy.matcher.ElementMatchers.isMethod;
-import static net.bytebuddy.matcher.ElementMatchers.named;
-import static net.bytebuddy.matcher.ElementMatchers.not;
-import static net.bytebuddy.matcher.ElementMatchers.returns;
-import static net.bytebuddy.matcher.ElementMatchers.takesArgument;
-
-import io.opentelemetry.context.Context;
-import io.opentelemetry.context.Scope;
-import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation;
-import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer;
-import java.util.Map;
-import khttp.responses.Response;
-import net.bytebuddy.asm.Advice;
-import net.bytebuddy.description.type.TypeDescription;
-import net.bytebuddy.matcher.ElementMatcher;
-
-public class KHttpInstrumentation implements TypeInstrumentation {
- @Override
- public ElementMatcher<ClassLoader> classLoaderOptimization() {
- return hasClassesNamed("khttp.KHttp");
- }
-
- @Override
- public ElementMatcher<TypeDescription> typeMatcher() {
- return extendsClass(named("khttp.KHttp"));
- }
-
- @Override
- public void transform(TypeTransformer transformer) {
- transformer.applyAdviceToMethod(
- isMethod()
- .and(not(isAbstract()))
- .and(named("request"))
- .and(takesArgument(0, String.class))
- .and(takesArgument(1, String.class))
- .and(takesArgument(2, Map.class))
- .and(returns(named("khttp.responses.Response"))),
- KHttpInstrumentation.class.getName() + "$RequestAdvice");
- }
-
- public static class RequestAdvice {
-
- @Advice.OnMethodEnter(suppress = Throwable.class)
- public static void methodEnter(
- @Advice.Argument(value = 0) String method,
- @Advice.Argument(value = 1) String uri,
- @Advice.Argument(value = 2, readOnly = false) Map<String, String> headers,
- @Advice.Local("otelContext") Context context,
- @Advice.Local("otelScope") Scope scope) {
- Context parentContext = currentContext();
- if (!tracer().shouldStartSpan(parentContext)) {
- return;
- }
-
- headers = asWritable(headers);
- context =
- tracer().startSpan(parentContext, new RequestWrapper(method, uri, headers), headers);
- scope = context.makeCurrent();
- }
-
- @Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class)
- public static void methodExit(
- @Advice.Return Response response,
- @Advice.Thrown Throwable throwable,
- @Advice.Local("otelContext") Context context,
- @Advice.Local("otelScope") Scope scope) {
- if (scope == null) {
- return;
- }
-
- scope.close();
- tracer().endMaybeExceptionally(context, response, throwable);
- }
- }
-}

DELETE
instrumentation/khttp-0.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/khttp/KHttpInstrumentationModule.java
-/*
- * Copyright The OpenTelemetry Authors
- * SPDX-License-Identifier: Apache-2.0
- */
-
-package io.opentelemetry.javaagent.instrumentation.khttp;
-
-import static java.util.Collections.singletonList;
-
-import com.google.auto.service.AutoService;
-import io.opentelemetry.javaagent.extension.instrumentation.InstrumentationModule;
-import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation;
-import java.util.List;
-
-@AutoService(InstrumentationModule.class)
-public class KHttpInstrumentationModule extends InstrumentationModule {
-
- public KHttpInstrumentationModule() {
- super("khttp");
- }
-
- @Override
- public List<TypeInstrumentation> typeInstrumentations() {
- return singletonList(new KHttpInstrumentation());
- }
-}

DELETE
instrumentation/khttp-0.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/khttp/KHttpTracer.java
-/*
- * Copyright The OpenTelemetry Authors
- * SPDX-License-Identifier: Apache-2.0
- */
-
-package io.opentelemetry.javaagent.instrumentation.khttp;
-
-import static io.opentelemetry.javaagent.instrumentation.khttp.KHttpHeadersInjectAdapter.SETTER;
-
-import io.opentelemetry.context.propagation.TextMapSetter;
-import io.opentelemetry.instrumentation.api.tracer.HttpClientTracer;
-import io.opentelemetry.instrumentation.api.tracer.net.NetPeerAttributes;
-import java.net.URI;
-import java.net.URISyntaxException;
-import java.util.Map;
-import khttp.responses.Response;
-
-public class KHttpTracer extends HttpClientTracer<RequestWrapper, Map<String, String>, Response> {
- private static final KHttpTracer TRACER = new KHttpTracer();
-
- private KHttpTracer() {
- super(NetPeerAttributes.INSTANCE);
- }
-
- public static KHttpTracer tracer() {
- return TRACER;
- }
-
- @Override
- protected String method(RequestWrapper requestWrapper) {
- return requestWrapper.method;
- }
-
- @Override
- protected URI url(RequestWrapper requestWrapper) throws URISyntaxException {
- return new URI(requestWrapper.uri);
- }
-
- @Override
- protected Integer status(Response response) {
- return response.getStatusCode();
- }
-
- @Override
- protected String requestHeader(RequestWrapper requestWrapper, String name) {
- return requestWrapper.headers.get(name);
- }
-
- @Override
- protected String responseHeader(Response response, String name) {
- return response.getHeaders().get(name);
- }
-
- @Override
- protected TextMapSetter<Map<String, String>> getSetter() {
- return SETTER;
- }
-
- @Override
- protected String getInstrumentationName() {
- return "io.opentelemetry.javaagent.khttp-0.1";
- }
-}

DELETE
instrumentation/khttp-0.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/khttp/RequestWrapper.java
-/*
- * Copyright The OpenTelemetry Authors
- * SPDX-License-Identifier: Apache-2.0
- */
-
-package io.opentelemetry.javaagent.instrumentation.khttp;
-
-import java.util.Map;
-
-public class RequestWrapper {
- final String method;
- final String uri;
- final Map<String, String> headers;
-
- public RequestWrapper(String method, String uri, Map<String, String> headers) {
- this.method = method;
- this.uri = uri;
- this.headers = headers;
- }
-}

DELETE
instrumentation/khttp-0.1/javaagent/src/test/groovy/KHttpClientTest.groovy
-/*
- * Copyright The OpenTelemetry Authors
- * SPDX-License-Identifier: Apache-2.0
- */
-
-import io.opentelemetry.instrumentation.test.AgentTestTrait
-import io.opentelemetry.instrumentation.test.base.HttpClientTest
-import khttp.KHttp
-
-class KHttpClientTest extends HttpClientTest<Void> implements AgentTestTrait {
-
- @Override
- Void buildRequest(String method, URI uri, Map<String, String> headers) {
- return null
- }
-
- @Override
- int sendRequest(Void request, String method, URI uri, Map<String, String> headers) {
- 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)
- return response.statusCode
- }
-
- @Override
- boolean testCircularRedirects() {
- return false
- }
-
- @Override
- boolean testReusedRequest() {
- // these tests will pass, but they don't really test anything since REQUEST is Void
- false
- }
-
- @Override
- boolean testCallback() {
- return false
- }
-
- @Override
- String userAgent() {
- return "khttp"
- }
-}

MODIFY
settings.gradle
settings.gradle
@@ -187,7 +187,6 @@ include ':instrumentation:jsf:myfaces-1.2:javaagent'
include ':instrumentation:jsp-2.3:javaagent'
include ':instrumentation:kafka-clients-0.11:javaagent'
include ':instrumentation:kafka-streams-0.11:javaagent'
-include ':instrumentation:khttp-0.1:javaagent'
include ':instrumentation:kotlinx-coroutines:javaagent'
include ':instrumentation:kubernetes-client-7.0:javaagent'
include ':instrumentation:kubernetes-client-7.0:javaagent-unit-tests'

Remove khttp instrumentation (#3087)