This is an automated email from the ASF dual-hosted git repository.
wusheng pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/skywalking.git
The following commit(s) were added to refs/heads/master by this push:
new b934a14 Add `okhttp-4.x` plugin (#6899)
b934a14 is described below
commit b934a143c2a08dd34bba12039f0380776fec9902
Author: liqiangz <[email protected]>
AuthorDate: Thu May 6 18:54:39 2021 +0800
Add `okhttp-4.x` plugin (#6899)
---
CHANGES.md | 1 +
.../apm-sdk-plugin/okhttp-3.x-plugin/pom.xml | 6 +++++
.../v3/define/AbstractOkhttpInstrumentation.java | 29 ++++++++++++++++++++++
.../okhttp/v3/define/AsyncCallInstrumentation.java | 7 +++---
.../okhttp/v3/define/CallbackInstrumentation.java | 7 +++---
.../okhttp/v3/define/RealCallInstrumentation.java | 7 +++---
.../plugin/okhttp/v3/RealCallInterceptorTest.java | 1 +
.../pom.xml | 18 ++++++++++----
.../v4/define/AbstractOkhttpInstrumentation.java | 29 ++++++++++++++++++++++
.../v4}/define/AsyncCallInstrumentation.java | 13 +++++-----
.../okhttp/v4}/define/CallbackInstrumentation.java | 9 +++----
.../okhttp/v4}/define/RealCallInstrumentation.java | 11 ++++----
.../src/main/resources/skywalking-plugin.def | 18 +++-----------
.../{okhttp-3.x-plugin => okhttp-common}/pom.xml | 22 ++++++++++++----
.../okhttp/common}/AsyncCallInterceptor.java | 7 +++---
.../plugin/okhttp/common}/EnhanceRequiredInfo.java | 2 +-
.../plugin/okhttp/common}/EnqueueInterceptor.java | 5 ++--
.../okhttp/common}/OnFailureInterceptor.java | 5 ++--
.../okhttp/common}/OnResponseInterceptor.java | 5 ++--
.../plugin/okhttp/common}/RealCallInterceptor.java | 13 +++++-----
apm-sniffer/apm-sdk-plugin/pom.xml | 2 ++
.../setup/service-agent/java-agent/Plugin-list.md | 1 +
.../service-agent/java-agent/Supported-list.md | 2 +-
.../scenarios/okhttp-scenario/support-version.list | 8 +++++-
24 files changed, 155 insertions(+), 73 deletions(-)
diff --git a/CHANGES.md b/CHANGES.md
index d76142a..c6bc4d6 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -22,6 +22,7 @@ Release Notes.
* fix a bug that spring-mvc set an error endpoint name if the controller class
annotation implements an interface.
* Add an optional agent plugin to support mybatis.
* Add `spring-cloud-gateway-3.x` optional plugin.
+* Add `okhttp-4.x` plugin.
#### OAP-Backend
* BugFix: filter invalid Envoy access logs whose socket address is empty.
diff --git a/apm-sniffer/apm-sdk-plugin/okhttp-3.x-plugin/pom.xml
b/apm-sniffer/apm-sdk-plugin/okhttp-3.x-plugin/pom.xml
index ee59cc3..784e29f 100644
--- a/apm-sniffer/apm-sdk-plugin/okhttp-3.x-plugin/pom.xml
+++ b/apm-sniffer/apm-sdk-plugin/okhttp-3.x-plugin/pom.xml
@@ -40,5 +40,11 @@
<version>${okhttp.version}</version>
<scope>provided</scope>
</dependency>
+ <dependency>
+ <groupId>org.apache.skywalking</groupId>
+ <artifactId>apm-okhttp-common</artifactId>
+ <version>${project.version}</version>
+ <scope>provided</scope>
+ </dependency>
</dependencies>
</project>
diff --git
a/apm-sniffer/apm-sdk-plugin/okhttp-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/okhttp/v3/define/AbstractOkhttpInstrumentation.java
b/apm-sniffer/apm-sdk-plugin/okhttp-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/okhttp/v3/define/AbstractOkhttpInstrumentation.java
new file mode 100644
index 0000000..d3df0ac
--- /dev/null
+++
b/apm-sniffer/apm-sdk-plugin/okhttp-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/okhttp/v3/define/AbstractOkhttpInstrumentation.java
@@ -0,0 +1,29 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.skywalking.apm.plugin.okhttp.v3.define;
+
+import
org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine;
+
+public abstract class AbstractOkhttpInstrumentation extends
ClassInstanceMethodsEnhancePluginDefine {
+ public static final String WITHNESS_CLASSES = "okhttp3.RealCall";
+
+ @Override
+ protected final String[] witnessClasses() {
+ return new String[] {WITHNESS_CLASSES};
+ }
+}
diff --git
a/apm-sniffer/apm-sdk-plugin/okhttp-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/okhttp/v3/define/AsyncCallInstrumentation.java
b/apm-sniffer/apm-sdk-plugin/okhttp-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/okhttp/v3/define/AsyncCallInstrumentation.java
index 0bcf20e..9c9303a 100644
---
a/apm-sniffer/apm-sdk-plugin/okhttp-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/okhttp/v3/define/AsyncCallInstrumentation.java
+++
b/apm-sniffer/apm-sdk-plugin/okhttp-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/okhttp/v3/define/AsyncCallInstrumentation.java
@@ -22,14 +22,13 @@ import net.bytebuddy.description.method.MethodDescription;
import net.bytebuddy.matcher.ElementMatcher;
import
org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint;
import
org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint;
-import
org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine;
import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch;
import static net.bytebuddy.matcher.ElementMatchers.any;
import static net.bytebuddy.matcher.ElementMatchers.named;
import static
org.apache.skywalking.apm.agent.core.plugin.match.NameMatch.byName;
-public class AsyncCallInstrumentation extends
ClassInstanceMethodsEnhancePluginDefine {
+public class AsyncCallInstrumentation extends AbstractOkhttpInstrumentation {
@Override
public ConstructorInterceptPoint[] getConstructorsInterceptPoints() {
@@ -42,7 +41,7 @@ public class AsyncCallInstrumentation extends
ClassInstanceMethodsEnhancePluginD
@Override
public String getConstructorInterceptor() {
- return
"org.apache.skywalking.apm.plugin.okhttp.v3.AsyncCallInterceptor";
+ return
"org.apache.skywalking.apm.plugin.okhttp.common.AsyncCallInterceptor";
}
}
};
@@ -59,7 +58,7 @@ public class AsyncCallInstrumentation extends
ClassInstanceMethodsEnhancePluginD
@Override
public String getMethodsInterceptor() {
- return
"org.apache.skywalking.apm.plugin.okhttp.v3.AsyncCallInterceptor";
+ return
"org.apache.skywalking.apm.plugin.okhttp.common.AsyncCallInterceptor";
}
@Override
diff --git
a/apm-sniffer/apm-sdk-plugin/okhttp-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/okhttp/v3/define/CallbackInstrumentation.java
b/apm-sniffer/apm-sdk-plugin/okhttp-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/okhttp/v3/define/CallbackInstrumentation.java
index a245548..ec75293 100644
---
a/apm-sniffer/apm-sdk-plugin/okhttp-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/okhttp/v3/define/CallbackInstrumentation.java
+++
b/apm-sniffer/apm-sdk-plugin/okhttp-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/okhttp/v3/define/CallbackInstrumentation.java
@@ -22,13 +22,12 @@ import net.bytebuddy.description.method.MethodDescription;
import net.bytebuddy.matcher.ElementMatcher;
import
org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint;
import
org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint;
-import
org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine;
import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch;
import static net.bytebuddy.matcher.ElementMatchers.named;
import static
org.apache.skywalking.apm.agent.core.plugin.match.HierarchyMatch.byHierarchyMatch;
-public class CallbackInstrumentation extends
ClassInstanceMethodsEnhancePluginDefine {
+public class CallbackInstrumentation extends AbstractOkhttpInstrumentation {
@Override
public ConstructorInterceptPoint[] getConstructorsInterceptPoints() {
return new ConstructorInterceptPoint[0];
@@ -45,7 +44,7 @@ public class CallbackInstrumentation extends
ClassInstanceMethodsEnhancePluginDe
@Override
public String getMethodsInterceptor() {
- return
"org.apache.skywalking.apm.plugin.okhttp.v3.OnFailureInterceptor";
+ return
"org.apache.skywalking.apm.plugin.okhttp.common.OnFailureInterceptor";
}
@Override
@@ -61,7 +60,7 @@ public class CallbackInstrumentation extends
ClassInstanceMethodsEnhancePluginDe
@Override
public String getMethodsInterceptor() {
- return
"org.apache.skywalking.apm.plugin.okhttp.v3.OnResponseInterceptor";
+ return
"org.apache.skywalking.apm.plugin.okhttp.common.OnResponseInterceptor";
}
@Override
diff --git
a/apm-sniffer/apm-sdk-plugin/okhttp-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/okhttp/v3/define/RealCallInstrumentation.java
b/apm-sniffer/apm-sdk-plugin/okhttp-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/okhttp/v3/define/RealCallInstrumentation.java
index 7644d9b..0658359 100644
---
a/apm-sniffer/apm-sdk-plugin/okhttp-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/okhttp/v3/define/RealCallInstrumentation.java
+++
b/apm-sniffer/apm-sdk-plugin/okhttp-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/okhttp/v3/define/RealCallInstrumentation.java
@@ -22,7 +22,6 @@ import net.bytebuddy.description.method.MethodDescription;
import net.bytebuddy.matcher.ElementMatcher;
import
org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint;
import
org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint;
-import
org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine;
import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch;
import org.apache.skywalking.apm.agent.core.plugin.match.NameMatch;
@@ -30,7 +29,7 @@ import static net.bytebuddy.matcher.ElementMatchers.any;
import static net.bytebuddy.matcher.ElementMatchers.named;
import static net.bytebuddy.matcher.ElementMatchers.takesArguments;
-public class RealCallInstrumentation extends
ClassInstanceMethodsEnhancePluginDefine {
+public class RealCallInstrumentation extends AbstractOkhttpInstrumentation {
/**
* Enhance class.
@@ -40,7 +39,7 @@ public class RealCallInstrumentation extends
ClassInstanceMethodsEnhancePluginDe
/**
* Intercept class.
*/
- private static final String INTERCEPT_CLASS =
"org.apache.skywalking.apm.plugin.okhttp.v3.RealCallInterceptor";
+ private static final String INTERCEPT_CLASS =
"org.apache.skywalking.apm.plugin.okhttp.common.RealCallInterceptor";
@Override
protected ClassMatch enhanceClass() {
@@ -91,7 +90,7 @@ public class RealCallInstrumentation extends
ClassInstanceMethodsEnhancePluginDe
@Override
public String getMethodsInterceptor() {
- return
"org.apache.skywalking.apm.plugin.okhttp.v3.EnqueueInterceptor";
+ return
"org.apache.skywalking.apm.plugin.okhttp.common.EnqueueInterceptor";
}
@Override
diff --git
a/apm-sniffer/apm-sdk-plugin/okhttp-3.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/okhttp/v3/RealCallInterceptorTest.java
b/apm-sniffer/apm-sdk-plugin/okhttp-3.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/okhttp/v3/RealCallInterceptorTest.java
index cc6caae..c7b4dc3 100644
---
a/apm-sniffer/apm-sdk-plugin/okhttp-3.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/okhttp/v3/RealCallInterceptorTest.java
+++
b/apm-sniffer/apm-sdk-plugin/okhttp-3.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/okhttp/v3/RealCallInterceptorTest.java
@@ -25,6 +25,7 @@ import okhttp3.Response;
import org.apache.skywalking.apm.agent.test.tools.SegmentStorage;
import org.apache.skywalking.apm.agent.test.tools.SegmentStoragePoint;
import org.apache.skywalking.apm.agent.test.tools.SpanAssert;
+import org.apache.skywalking.apm.plugin.okhttp.common.RealCallInterceptor;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
diff --git a/apm-sniffer/apm-sdk-plugin/okhttp-3.x-plugin/pom.xml
b/apm-sniffer/apm-sdk-plugin/okhttp-4.x-plugin/pom.xml
similarity index 69%
copy from apm-sniffer/apm-sdk-plugin/okhttp-3.x-plugin/pom.xml
copy to apm-sniffer/apm-sdk-plugin/okhttp-4.x-plugin/pom.xml
index ee59cc3..8a39e18 100644
--- a/apm-sniffer/apm-sdk-plugin/okhttp-3.x-plugin/pom.xml
+++ b/apm-sniffer/apm-sdk-plugin/okhttp-4.x-plugin/pom.xml
@@ -17,7 +17,9 @@
~
-->
-<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<groupId>org.apache.skywalking</groupId>
<artifactId>apm-sdk-plugin</artifactId>
@@ -25,12 +27,12 @@
</parent>
<modelVersion>4.0.0</modelVersion>
- <artifactId>apm-okhttp-3.x-plugin</artifactId>
- <name>okhttp-3.x-plugin</name>
+ <artifactId>apm-okhttp-4.x-plugin</artifactId>
+ <name>okhttp-4.x-plugin</name>
<packaging>jar</packaging>
<properties>
- <okhttp.version>3.7.0</okhttp.version>
+ <okhttp.version>4.9.0</okhttp.version>
</properties>
<dependencies>
@@ -40,5 +42,11 @@
<version>${okhttp.version}</version>
<scope>provided</scope>
</dependency>
+ <dependency>
+ <groupId>org.apache.skywalking</groupId>
+ <artifactId>apm-okhttp-common</artifactId>
+ <version>${project.version}</version>
+ <scope>provided</scope>
+ </dependency>
</dependencies>
-</project>
+</project>
\ No newline at end of file
diff --git
a/apm-sniffer/apm-sdk-plugin/okhttp-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/okhttp/v4/define/AbstractOkhttpInstrumentation.java
b/apm-sniffer/apm-sdk-plugin/okhttp-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/okhttp/v4/define/AbstractOkhttpInstrumentation.java
new file mode 100644
index 0000000..2796d78
--- /dev/null
+++
b/apm-sniffer/apm-sdk-plugin/okhttp-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/okhttp/v4/define/AbstractOkhttpInstrumentation.java
@@ -0,0 +1,29 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.skywalking.apm.plugin.okhttp.v4.define;
+
+import
org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine;
+
+public abstract class AbstractOkhttpInstrumentation extends
ClassInstanceMethodsEnhancePluginDefine {
+ public static final String WITHNESS_CLASSES =
"okhttp3.internal.connection.RealCall";
+
+ @Override
+ protected final String[] witnessClasses() {
+ return new String[] {WITHNESS_CLASSES};
+ }
+}
diff --git
a/apm-sniffer/apm-sdk-plugin/okhttp-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/okhttp/v3/define/AsyncCallInstrumentation.java
b/apm-sniffer/apm-sdk-plugin/okhttp-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/okhttp/v4/define/AsyncCallInstrumentation.java
similarity index 86%
copy from
apm-sniffer/apm-sdk-plugin/okhttp-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/okhttp/v3/define/AsyncCallInstrumentation.java
copy to
apm-sniffer/apm-sdk-plugin/okhttp-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/okhttp/v4/define/AsyncCallInstrumentation.java
index 0bcf20e..25ac4c3 100644
---
a/apm-sniffer/apm-sdk-plugin/okhttp-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/okhttp/v3/define/AsyncCallInstrumentation.java
+++
b/apm-sniffer/apm-sdk-plugin/okhttp-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/okhttp/v4/define/AsyncCallInstrumentation.java
@@ -16,20 +16,19 @@
*
*/
-package org.apache.skywalking.apm.plugin.okhttp.v3.define;
+package org.apache.skywalking.apm.plugin.okhttp.v4.define;
import net.bytebuddy.description.method.MethodDescription;
import net.bytebuddy.matcher.ElementMatcher;
import
org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint;
import
org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint;
-import
org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine;
import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch;
import static net.bytebuddy.matcher.ElementMatchers.any;
import static net.bytebuddy.matcher.ElementMatchers.named;
import static
org.apache.skywalking.apm.agent.core.plugin.match.NameMatch.byName;
-public class AsyncCallInstrumentation extends
ClassInstanceMethodsEnhancePluginDefine {
+public class AsyncCallInstrumentation extends AbstractOkhttpInstrumentation {
@Override
public ConstructorInterceptPoint[] getConstructorsInterceptPoints() {
@@ -42,7 +41,7 @@ public class AsyncCallInstrumentation extends
ClassInstanceMethodsEnhancePluginD
@Override
public String getConstructorInterceptor() {
- return
"org.apache.skywalking.apm.plugin.okhttp.v3.AsyncCallInterceptor";
+ return
"org.apache.skywalking.apm.plugin.okhttp.common.AsyncCallInterceptor";
}
}
};
@@ -54,12 +53,12 @@ public class AsyncCallInstrumentation extends
ClassInstanceMethodsEnhancePluginD
new InstanceMethodsInterceptPoint() {
@Override
public ElementMatcher<MethodDescription> getMethodsMatcher() {
- return named("execute");
+ return named("run");
}
@Override
public String getMethodsInterceptor() {
- return
"org.apache.skywalking.apm.plugin.okhttp.v3.AsyncCallInterceptor";
+ return
"org.apache.skywalking.apm.plugin.okhttp.common.AsyncCallInterceptor";
}
@Override
@@ -72,6 +71,6 @@ public class AsyncCallInstrumentation extends
ClassInstanceMethodsEnhancePluginD
@Override
protected ClassMatch enhanceClass() {
- return byName("okhttp3.RealCall$AsyncCall");
+ return byName("okhttp3.internal.connection.RealCall$AsyncCall");
}
}
diff --git
a/apm-sniffer/apm-sdk-plugin/okhttp-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/okhttp/v3/define/CallbackInstrumentation.java
b/apm-sniffer/apm-sdk-plugin/okhttp-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/okhttp/v4/define/CallbackInstrumentation.java
similarity index 89%
copy from
apm-sniffer/apm-sdk-plugin/okhttp-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/okhttp/v3/define/CallbackInstrumentation.java
copy to
apm-sniffer/apm-sdk-plugin/okhttp-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/okhttp/v4/define/CallbackInstrumentation.java
index a245548..0dca638 100644
---
a/apm-sniffer/apm-sdk-plugin/okhttp-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/okhttp/v3/define/CallbackInstrumentation.java
+++
b/apm-sniffer/apm-sdk-plugin/okhttp-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/okhttp/v4/define/CallbackInstrumentation.java
@@ -16,19 +16,18 @@
*
*/
-package org.apache.skywalking.apm.plugin.okhttp.v3.define;
+package org.apache.skywalking.apm.plugin.okhttp.v4.define;
import net.bytebuddy.description.method.MethodDescription;
import net.bytebuddy.matcher.ElementMatcher;
import
org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint;
import
org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint;
-import
org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine;
import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch;
import static net.bytebuddy.matcher.ElementMatchers.named;
import static
org.apache.skywalking.apm.agent.core.plugin.match.HierarchyMatch.byHierarchyMatch;
-public class CallbackInstrumentation extends
ClassInstanceMethodsEnhancePluginDefine {
+public class CallbackInstrumentation extends AbstractOkhttpInstrumentation {
@Override
public ConstructorInterceptPoint[] getConstructorsInterceptPoints() {
return new ConstructorInterceptPoint[0];
@@ -45,7 +44,7 @@ public class CallbackInstrumentation extends
ClassInstanceMethodsEnhancePluginDe
@Override
public String getMethodsInterceptor() {
- return
"org.apache.skywalking.apm.plugin.okhttp.v3.OnFailureInterceptor";
+ return
"org.apache.skywalking.apm.plugin.okhttp.common.OnFailureInterceptor";
}
@Override
@@ -61,7 +60,7 @@ public class CallbackInstrumentation extends
ClassInstanceMethodsEnhancePluginDe
@Override
public String getMethodsInterceptor() {
- return
"org.apache.skywalking.apm.plugin.okhttp.v3.OnResponseInterceptor";
+ return
"org.apache.skywalking.apm.plugin.okhttp.common.OnResponseInterceptor";
}
@Override
diff --git
a/apm-sniffer/apm-sdk-plugin/okhttp-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/okhttp/v3/define/RealCallInstrumentation.java
b/apm-sniffer/apm-sdk-plugin/okhttp-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/okhttp/v4/define/RealCallInstrumentation.java
similarity index 89%
copy from
apm-sniffer/apm-sdk-plugin/okhttp-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/okhttp/v3/define/RealCallInstrumentation.java
copy to
apm-sniffer/apm-sdk-plugin/okhttp-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/okhttp/v4/define/RealCallInstrumentation.java
index 7644d9b..ea97358 100644
---
a/apm-sniffer/apm-sdk-plugin/okhttp-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/okhttp/v3/define/RealCallInstrumentation.java
+++
b/apm-sniffer/apm-sdk-plugin/okhttp-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/okhttp/v4/define/RealCallInstrumentation.java
@@ -16,13 +16,12 @@
*
*/
-package org.apache.skywalking.apm.plugin.okhttp.v3.define;
+package org.apache.skywalking.apm.plugin.okhttp.v4.define;
import net.bytebuddy.description.method.MethodDescription;
import net.bytebuddy.matcher.ElementMatcher;
import
org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint;
import
org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint;
-import
org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine;
import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch;
import org.apache.skywalking.apm.agent.core.plugin.match.NameMatch;
@@ -30,17 +29,17 @@ import static net.bytebuddy.matcher.ElementMatchers.any;
import static net.bytebuddy.matcher.ElementMatchers.named;
import static net.bytebuddy.matcher.ElementMatchers.takesArguments;
-public class RealCallInstrumentation extends
ClassInstanceMethodsEnhancePluginDefine {
+public class RealCallInstrumentation extends AbstractOkhttpInstrumentation {
/**
* Enhance class.
*/
- private static final String ENHANCE_CLASS = "okhttp3.RealCall";
+ private static final String ENHANCE_CLASS =
"okhttp3.internal.connection.RealCall";
/**
* Intercept class.
*/
- private static final String INTERCEPT_CLASS =
"org.apache.skywalking.apm.plugin.okhttp.v3.RealCallInterceptor";
+ private static final String INTERCEPT_CLASS =
"org.apache.skywalking.apm.plugin.okhttp.common.RealCallInterceptor";
@Override
protected ClassMatch enhanceClass() {
@@ -91,7 +90,7 @@ public class RealCallInstrumentation extends
ClassInstanceMethodsEnhancePluginDe
@Override
public String getMethodsInterceptor() {
- return
"org.apache.skywalking.apm.plugin.okhttp.v3.EnqueueInterceptor";
+ return
"org.apache.skywalking.apm.plugin.okhttp.common.EnqueueInterceptor";
}
@Override
diff --git a/test/plugin/scenarios/okhttp-scenario/support-version.list
b/apm-sniffer/apm-sdk-plugin/okhttp-4.x-plugin/src/main/resources/skywalking-plugin.def
similarity index 75%
copy from test/plugin/scenarios/okhttp-scenario/support-version.list
copy to
apm-sniffer/apm-sdk-plugin/okhttp-4.x-plugin/src/main/resources/skywalking-plugin.def
index cd7736b..2da0dec 100644
--- a/test/plugin/scenarios/okhttp-scenario/support-version.list
+++
b/apm-sniffer/apm-sdk-plugin/okhttp-4.x-plugin/src/main/resources/skywalking-plugin.def
@@ -14,18 +14,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-3.0.1
-3.1.2
-3.2.0
-3.3.1
-3.4.2
-3.5.0
-3.6.0
-3.7.0
-3.8.1
-3.9.1
-3.10.0
-3.11.0
-3.12.6
-3.13.1
-3.14.4
\ No newline at end of file
+okhttp-4.x=org.apache.skywalking.apm.plugin.okhttp.v4.define.RealCallInstrumentation
+okhttp-4.x=org.apache.skywalking.apm.plugin.okhttp.v4.define.CallbackInstrumentation
+okhttp-4.x=org.apache.skywalking.apm.plugin.okhttp.v4.define.AsyncCallInstrumentation
diff --git a/apm-sniffer/apm-sdk-plugin/okhttp-3.x-plugin/pom.xml
b/apm-sniffer/apm-sdk-plugin/okhttp-common/pom.xml
similarity index 73%
copy from apm-sniffer/apm-sdk-plugin/okhttp-3.x-plugin/pom.xml
copy to apm-sniffer/apm-sdk-plugin/okhttp-common/pom.xml
index ee59cc3..638b210 100644
--- a/apm-sniffer/apm-sdk-plugin/okhttp-3.x-plugin/pom.xml
+++ b/apm-sniffer/apm-sdk-plugin/okhttp-common/pom.xml
@@ -17,18 +17,22 @@
~
-->
-<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
- <groupId>org.apache.skywalking</groupId>
<artifactId>apm-sdk-plugin</artifactId>
+ <groupId>org.apache.skywalking</groupId>
<version>8.6.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
- <artifactId>apm-okhttp-3.x-plugin</artifactId>
- <name>okhttp-3.x-plugin</name>
+ <artifactId>apm-okhttp-common</artifactId>
<packaging>jar</packaging>
+ <name>okhttp-common</name>
+ <url>http://maven.apache.org</url>
+
<properties>
<okhttp.version>3.7.0</okhttp.version>
</properties>
@@ -41,4 +45,12 @@
<scope>provided</scope>
</dependency>
</dependencies>
-</project>
+
+ <build>
+ <plugins>
+ <plugin>
+ <artifactId>maven-deploy-plugin</artifactId>
+ </plugin>
+ </plugins>
+ </build>
+</project>
\ No newline at end of file
diff --git
a/apm-sniffer/apm-sdk-plugin/okhttp-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/okhttp/v3/AsyncCallInterceptor.java
b/apm-sniffer/apm-sdk-plugin/okhttp-common/src/main/java/org/apache/skywalking/apm/plugin/okhttp/common/AsyncCallInterceptor.java
similarity index 98%
rename from
apm-sniffer/apm-sdk-plugin/okhttp-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/okhttp/v3/AsyncCallInterceptor.java
rename to
apm-sniffer/apm-sdk-plugin/okhttp-common/src/main/java/org/apache/skywalking/apm/plugin/okhttp/common/AsyncCallInterceptor.java
index 452b5ba..7565692 100644
---
a/apm-sniffer/apm-sdk-plugin/okhttp-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/okhttp/v3/AsyncCallInterceptor.java
+++
b/apm-sniffer/apm-sdk-plugin/okhttp-common/src/main/java/org/apache/skywalking/apm/plugin/okhttp/common/AsyncCallInterceptor.java
@@ -16,10 +16,8 @@
*
*/
-package org.apache.skywalking.apm.plugin.okhttp.v3;
+package org.apache.skywalking.apm.plugin.okhttp.common;
-import java.lang.reflect.Field;
-import java.lang.reflect.Method;
import okhttp3.Headers;
import okhttp3.HttpUrl;
import okhttp3.Request;
@@ -35,6 +33,9 @@ import
org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceM
import
org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult;
import org.apache.skywalking.apm.network.trace.component.ComponentsDefine;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+
/**
* {@link AsyncCallInterceptor} get the `EnhanceRequiredInfo` instance from
`SkyWalkingDynamicField` and then put it
* into `AsyncCall` instance when the `AsyncCall` constructor called.
diff --git
a/apm-sniffer/apm-sdk-plugin/okhttp-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/okhttp/v3/EnhanceRequiredInfo.java
b/apm-sniffer/apm-sdk-plugin/okhttp-common/src/main/java/org/apache/skywalking/apm/plugin/okhttp/common/EnhanceRequiredInfo.java
similarity index 96%
rename from
apm-sniffer/apm-sdk-plugin/okhttp-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/okhttp/v3/EnhanceRequiredInfo.java
rename to
apm-sniffer/apm-sdk-plugin/okhttp-common/src/main/java/org/apache/skywalking/apm/plugin/okhttp/common/EnhanceRequiredInfo.java
index 25046cd..311cf1c 100644
---
a/apm-sniffer/apm-sdk-plugin/okhttp-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/okhttp/v3/EnhanceRequiredInfo.java
+++
b/apm-sniffer/apm-sdk-plugin/okhttp-common/src/main/java/org/apache/skywalking/apm/plugin/okhttp/common/EnhanceRequiredInfo.java
@@ -16,7 +16,7 @@
*
*/
-package org.apache.skywalking.apm.plugin.okhttp.v3;
+package org.apache.skywalking.apm.plugin.okhttp.common;
import org.apache.skywalking.apm.agent.core.context.ContextSnapshot;
import
org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance;
diff --git
a/apm-sniffer/apm-sdk-plugin/okhttp-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/okhttp/v3/EnqueueInterceptor.java
b/apm-sniffer/apm-sdk-plugin/okhttp-common/src/main/java/org/apache/skywalking/apm/plugin/okhttp/common/EnqueueInterceptor.java
similarity index 98%
rename from
apm-sniffer/apm-sdk-plugin/okhttp-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/okhttp/v3/EnqueueInterceptor.java
rename to
apm-sniffer/apm-sdk-plugin/okhttp-common/src/main/java/org/apache/skywalking/apm/plugin/okhttp/common/EnqueueInterceptor.java
index e4612a9..f6900a4 100644
---
a/apm-sniffer/apm-sdk-plugin/okhttp-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/okhttp/v3/EnqueueInterceptor.java
+++
b/apm-sniffer/apm-sdk-plugin/okhttp-common/src/main/java/org/apache/skywalking/apm/plugin/okhttp/common/EnqueueInterceptor.java
@@ -16,9 +16,8 @@
*
*/
-package org.apache.skywalking.apm.plugin.okhttp.v3;
+package org.apache.skywalking.apm.plugin.okhttp.common;
-import java.lang.reflect.Method;
import okhttp3.Request;
import org.apache.skywalking.apm.agent.core.context.ContextManager;
import
org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance;
@@ -26,6 +25,8 @@ import
org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceC
import
org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor;
import
org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult;
+import java.lang.reflect.Method;
+
/**
* {@link EnqueueInterceptor} create a local span and the prefix of the span
operation name is start with `Async` when
* the `enqueue` method called and also put the `ContextSnapshot` and
`RealCall` instance into the
diff --git
a/apm-sniffer/apm-sdk-plugin/okhttp-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/okhttp/v3/OnFailureInterceptor.java
b/apm-sniffer/apm-sdk-plugin/okhttp-common/src/main/java/org/apache/skywalking/apm/plugin/okhttp/common/OnFailureInterceptor.java
similarity index 97%
rename from
apm-sniffer/apm-sdk-plugin/okhttp-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/okhttp/v3/OnFailureInterceptor.java
rename to
apm-sniffer/apm-sdk-plugin/okhttp-common/src/main/java/org/apache/skywalking/apm/plugin/okhttp/common/OnFailureInterceptor.java
index be4b82d..8b38b4c 100644
---
a/apm-sniffer/apm-sdk-plugin/okhttp-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/okhttp/v3/OnFailureInterceptor.java
+++
b/apm-sniffer/apm-sdk-plugin/okhttp-common/src/main/java/org/apache/skywalking/apm/plugin/okhttp/common/OnFailureInterceptor.java
@@ -16,14 +16,15 @@
*
*/
-package org.apache.skywalking.apm.plugin.okhttp.v3;
+package org.apache.skywalking.apm.plugin.okhttp.common;
-import java.lang.reflect.Method;
import org.apache.skywalking.apm.agent.core.context.ContextManager;
import
org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance;
import
org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor;
import
org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult;
+import java.lang.reflect.Method;
+
public class OnFailureInterceptor implements InstanceMethodsAroundInterceptor {
@Override
public void beforeMethod(EnhancedInstance objInst, Method method, Object[]
allArguments, Class<?>[] argumentsTypes,
diff --git
a/apm-sniffer/apm-sdk-plugin/okhttp-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/okhttp/v3/OnResponseInterceptor.java
b/apm-sniffer/apm-sdk-plugin/okhttp-common/src/main/java/org/apache/skywalking/apm/plugin/okhttp/common/OnResponseInterceptor.java
similarity index 97%
rename from
apm-sniffer/apm-sdk-plugin/okhttp-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/okhttp/v3/OnResponseInterceptor.java
rename to
apm-sniffer/apm-sdk-plugin/okhttp-common/src/main/java/org/apache/skywalking/apm/plugin/okhttp/common/OnResponseInterceptor.java
index 4649d01..62728b3 100644
---
a/apm-sniffer/apm-sdk-plugin/okhttp-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/okhttp/v3/OnResponseInterceptor.java
+++
b/apm-sniffer/apm-sdk-plugin/okhttp-common/src/main/java/org/apache/skywalking/apm/plugin/okhttp/common/OnResponseInterceptor.java
@@ -16,15 +16,16 @@
*
*/
-package org.apache.skywalking.apm.plugin.okhttp.v3;
+package org.apache.skywalking.apm.plugin.okhttp.common;
-import java.lang.reflect.Method;
import okhttp3.Response;
import org.apache.skywalking.apm.agent.core.context.ContextManager;
import
org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance;
import
org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor;
import
org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult;
+import java.lang.reflect.Method;
+
/**
* {@link OnResponseInterceptor} validate the response code if it is great
equal than 400. if so. the transaction status
* chang to `error`, or do nothing.
diff --git
a/apm-sniffer/apm-sdk-plugin/okhttp-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/okhttp/v3/RealCallInterceptor.java
b/apm-sniffer/apm-sdk-plugin/okhttp-common/src/main/java/org/apache/skywalking/apm/plugin/okhttp/common/RealCallInterceptor.java
similarity index 93%
rename from
apm-sniffer/apm-sdk-plugin/okhttp-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/okhttp/v3/RealCallInterceptor.java
rename to
apm-sniffer/apm-sdk-plugin/okhttp-common/src/main/java/org/apache/skywalking/apm/plugin/okhttp/common/RealCallInterceptor.java
index b88f846..af3a169 100644
---
a/apm-sniffer/apm-sdk-plugin/okhttp-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/okhttp/v3/RealCallInterceptor.java
+++
b/apm-sniffer/apm-sdk-plugin/okhttp-common/src/main/java/org/apache/skywalking/apm/plugin/okhttp/common/RealCallInterceptor.java
@@ -16,10 +16,8 @@
*
*/
-package org.apache.skywalking.apm.plugin.okhttp.v3;
+package org.apache.skywalking.apm.plugin.okhttp.common;
-import java.lang.reflect.Field;
-import java.lang.reflect.Method;
import okhttp3.Headers;
import okhttp3.HttpUrl;
import okhttp3.Request;
@@ -36,6 +34,9 @@ import
org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceM
import
org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult;
import org.apache.skywalking.apm.network.trace.component.ComponentsDefine;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+
/**
* {@link RealCallInterceptor} intercept the synchronous http calls by the
discovery of okhttp.
*/
@@ -47,9 +48,9 @@ public class RealCallInterceptor implements
InstanceMethodsAroundInterceptor, In
}
/**
- * Get the {@link okhttp3.Request} from {@link EnhancedInstance}, then
create {@link AbstractSpan} and set host,
- * port, kind, component, url from {@link okhttp3.Request}. Through the
reflection of the way, set the http header
- * of context data into {@link okhttp3.Request#headers}.
+ * Get the {@link Request} from {@link EnhancedInstance}, then create
{@link AbstractSpan} and set host,
+ * port, kind, component, url from {@link Request}. Through the reflection
of the way, set the http header
+ * of context data into {@link Request#headers}.
*
* @param result change this result, if you want to truncate the method.
*/
diff --git a/apm-sniffer/apm-sdk-plugin/pom.xml
b/apm-sniffer/apm-sdk-plugin/pom.xml
index 57464ed..36fbf91 100644
--- a/apm-sniffer/apm-sdk-plugin/pom.xml
+++ b/apm-sniffer/apm-sdk-plugin/pom.xml
@@ -39,6 +39,8 @@
<module>mongodb-4.x-plugin</module>
<module>feign-default-http-9.x-plugin</module>
<module>okhttp-3.x-plugin</module>
+ <module>okhttp-4.x-plugin</module>
+ <module>okhttp-common</module>
<module>spring-plugins</module>
<module>struts2-2.x-plugin</module>
<module>nutz-plugins</module>
diff --git a/docs/en/setup/service-agent/java-agent/Plugin-list.md
b/docs/en/setup/service-agent/java-agent/Plugin-list.md
index a29d325..43618d1 100644
--- a/docs/en/setup/service-agent/java-agent/Plugin-list.md
+++ b/docs/en/setup/service-agent/java-agent/Plugin-list.md
@@ -54,6 +54,7 @@
- nutz-http-1.x
- nutz-mvc-annotation-1.x
- okhttp-3.x
+- okhttp-4.x
- play-2.x
- postgresql-8.x
- pulsar
diff --git a/docs/en/setup/service-agent/java-agent/Supported-list.md
b/docs/en/setup/service-agent/java-agent/Supported-list.md
index e5a9501..625a566 100644
--- a/docs/en/setup/service-agent/java-agent/Supported-list.md
+++ b/docs/en/setup/service-agent/java-agent/Supported-list.md
@@ -22,7 +22,7 @@ metrics based on the tracing data.
* HTTP Client
* [Feign](https://github.com/OpenFeign/feign) 9.x
* [Netflix Spring Cloud
Feign](https://github.com/spring-cloud/spring-cloud-openfeign) 1.1.x -> 2.x
- * [Okhttp](https://github.com/square/okhttp) 3.x
+ * [Okhttp](https://github.com/square/okhttp) 3.x -> 4.x
* [Apache httpcomponent HttpClient](http://hc.apache.org/) 2.0 -> 3.1, 4.2,
4.3
* [Spring RestTemplete](https://github.com/spring-projects/spring-framework)
4.x
* [Jetty Client](http://www.eclipse.org/jetty/) 9
diff --git a/test/plugin/scenarios/okhttp-scenario/support-version.list
b/test/plugin/scenarios/okhttp-scenario/support-version.list
index cd7736b..061f665 100644
--- a/test/plugin/scenarios/okhttp-scenario/support-version.list
+++ b/test/plugin/scenarios/okhttp-scenario/support-version.list
@@ -28,4 +28,10 @@
3.11.0
3.12.6
3.13.1
-3.14.4
\ No newline at end of file
+3.14.4
+4.5.0
+4.6.0
+4.7.0
+4.8.0
+4.9.0
+4.9.1
\ No newline at end of file