Refactoring OkHttp
MODIFY
dd-java-agent/pom.xml
dd-java-agent/pom.xml
<artifactId>opentracing-agent</artifactId>
<version>${ot.agent.version}</version>
</dependency>
- <dependency>
- <groupId>io.opentracing.contrib</groupId>
- <artifactId>opentracing-agent-rules-java-okhttp</artifactId>
- <version>${ot.agent.version}</version>
- </dependency>
+
<!-- Used to find annotated methods -->
<dependency>
</exclusion>
</exclusions>
</dependency>
+ <dependency>
+ <groupId>com.squareup.okhttp3</groupId>
+ <artifactId>okhttp</artifactId>
+ <version>3.6.0</version>
+ <scope>provided</scope>
+ </dependency>
<!-- AWS SDK instrumentation -->
<dependency>

ADD
dd-java-agent/src/main/java/io/opentracing/contrib/agent/helper/OkHttpHelper.java
+package io.opentracing.contrib.agent.helper;
+
+import io.opentracing.contrib.okhttp3.TracingInterceptor;
+import okhttp3.OkHttpClient;
+import org.jboss.byteman.rule.Rule;
+
+import java.util.Collections;
+
+import static io.opentracing.contrib.okhttp3.OkHttpClientSpanDecorator.STANDARD_TAGS;
+
+/**
+ * Created by gpolaert on 6/15/17.
+ */
+public class OkHttpHelper extends DDTracingHelper<OkHttpClient.Builder> {
+
+
+ public OkHttpHelper(Rule rule) {
+ super(rule);
+ }
+
+ @Override
+ protected OkHttpClient.Builder doPatch(OkHttpClient.Builder builder) throws Exception {
+ TracingInterceptor interceptor = new TracingInterceptor(tracer, Collections.singletonList(STANDARD_TAGS));
+ builder.addInterceptor(interceptor);
+ builder.addNetworkInterceptor(interceptor);
+
+ return builder;
+ }
+}
\ No newline at end of file

MODIFY
dd-java-agent/src/main/resources/otarules.btm
dd-java-agent/src/main/resources/otarules.btm
@@ -66,7 +66,6 @@ ENDRULE
# ===========================
# State 0 - no filter installed
# State 1 - filter installed
-
RULE jetty
CLASS org.eclipse.jetty.servlet.ServletContextHandler
METHOD <init>
@@ -80,7 +79,6 @@ ENDRULE
# Instrument Tomcat
# ===========================
-
RULE tomcat
CLASS org.apache.catalina.core.ApplicationContext
METHOD <init>
@@ -90,3 +88,17 @@ IF TRUE
DO
patch($this)
ENDRULE
+
+
+
+# Instrument OkHttp
+# ===========================
+RULE okhttp
+CLASS okhttp3.OkHttpClient$Builder
+METHOD build()
+HELPER io.opentracing.contrib.agent.helper.OkHttpHelper
+AT EXIT
+IF TRUE
+DO
+ patch($this)
+ENDRULE

Refactoring OkHttp