diff --git a/CHANGES.md b/CHANGES.md index d76142aa232779df4560f79b251655bb1e2e36fa..c6bc4d69bdf0cfa51098cd11fa6acf76a2caeae8 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 ee59cc3d6036024d8af47085cd4ebac5b038f4ff..784e29f7817140d8f3a71134e6fdee8ce9320b50 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 @@ ${okhttp.version} provided + + org.apache.skywalking + apm-okhttp-common + ${project.version} + provided + 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 0000000000000000000000000000000000000000..d3df0ac5f8b756b565b4e34cd1ac15bf522afdcd --- /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 0bcf20ece9ea04493c4bfa9915af82df8ce94252..9c9303ad88065ee227015510ab9595bb99a71929 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 a2455489672aa1766eb9d57bfabb69b03435350a..ec75293e82113fd7d3a85456ef3a631947dc5e9c 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 7644d9b4c1f8dc1ee57851e15519458bf4d4b834..0658359b3d94437eb99fc139d2bc9d534380c567 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 cc6caaeb4894cde656baf6821e66644b20fc0046..c7b4dc3c9829bafd8c043ece3582c6f1aa380c2a 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-4.x-plugin/pom.xml b/apm-sniffer/apm-sdk-plugin/okhttp-4.x-plugin/pom.xml new file mode 100644 index 0000000000000000000000000000000000000000..8a39e18f0eba2a188f6a69f52f5f0d9b7b2c12ef --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/okhttp-4.x-plugin/pom.xml @@ -0,0 +1,52 @@ + + + + + + org.apache.skywalking + apm-sdk-plugin + 8.6.0-SNAPSHOT + + 4.0.0 + + apm-okhttp-4.x-plugin + okhttp-4.x-plugin + jar + + + 4.9.0 + + + + + com.squareup.okhttp3 + okhttp + ${okhttp.version} + provided + + + org.apache.skywalking + apm-okhttp-common + ${project.version} + provided + + + \ 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 0000000000000000000000000000000000000000..2796d786be7925382171ec1ddbec37bf49a8bf68 --- /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-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/okhttp/v4/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 new file mode 100644 index 0000000000000000000000000000000000000000..25ac4c3c8da9047fe12d70dac59e3d90b71d57f3 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/okhttp-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/okhttp/v4/define/AsyncCallInstrumentation.java @@ -0,0 +1,76 @@ +/* + * 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 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.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 AbstractOkhttpInstrumentation { + + @Override + public ConstructorInterceptPoint[] getConstructorsInterceptPoints() { + return new ConstructorInterceptPoint[] { + new ConstructorInterceptPoint() { + @Override + public ElementMatcher getConstructorMatcher() { + return any(); + } + + @Override + public String getConstructorInterceptor() { + return "org.apache.skywalking.apm.plugin.okhttp.common.AsyncCallInterceptor"; + } + } + }; + } + + @Override + public InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { + return new InstanceMethodsInterceptPoint[] { + new InstanceMethodsInterceptPoint() { + @Override + public ElementMatcher getMethodsMatcher() { + return named("run"); + } + + @Override + public String getMethodsInterceptor() { + return "org.apache.skywalking.apm.plugin.okhttp.common.AsyncCallInterceptor"; + } + + @Override + public boolean isOverrideArgs() { + return false; + } + } + }; + } + + @Override + protected ClassMatch enhanceClass() { + return byName("okhttp3.internal.connection.RealCall$AsyncCall"); + } +} diff --git a/apm-sniffer/apm-sdk-plugin/okhttp-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/okhttp/v4/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 new file mode 100644 index 0000000000000000000000000000000000000000..0dca638b80e338b2cbc3dfe4695140030a20ad49 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/okhttp-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/okhttp/v4/define/CallbackInstrumentation.java @@ -0,0 +1,78 @@ +/* + * 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 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.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 AbstractOkhttpInstrumentation { + @Override + public ConstructorInterceptPoint[] getConstructorsInterceptPoints() { + return new ConstructorInterceptPoint[0]; + } + + @Override + public InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { + return new InstanceMethodsInterceptPoint[] { + new InstanceMethodsInterceptPoint() { + @Override + public ElementMatcher getMethodsMatcher() { + return named("onFailure"); + } + + @Override + public String getMethodsInterceptor() { + return "org.apache.skywalking.apm.plugin.okhttp.common.OnFailureInterceptor"; + } + + @Override + public boolean isOverrideArgs() { + return false; + } + }, + new InstanceMethodsInterceptPoint() { + @Override + public ElementMatcher getMethodsMatcher() { + return named("onResponse"); + } + + @Override + public String getMethodsInterceptor() { + return "org.apache.skywalking.apm.plugin.okhttp.common.OnResponseInterceptor"; + } + + @Override + public boolean isOverrideArgs() { + return false; + } + } + }; + } + + @Override + protected ClassMatch enhanceClass() { + return byHierarchyMatch(new String[] {"okhttp3.Callback"}); + } +} diff --git a/apm-sniffer/apm-sdk-plugin/okhttp-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/okhttp/v4/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 new file mode 100644 index 0000000000000000000000000000000000000000..ea97358b1865f892ad8f4e6f9870053cc4725c76 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/okhttp-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/okhttp/v4/define/RealCallInstrumentation.java @@ -0,0 +1,103 @@ +/* + * 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 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.match.ClassMatch; +import org.apache.skywalking.apm.agent.core.plugin.match.NameMatch; + +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 AbstractOkhttpInstrumentation { + + /** + * Enhance class. + */ + private static final String ENHANCE_CLASS = "okhttp3.internal.connection.RealCall"; + + /** + * Intercept class. + */ + private static final String INTERCEPT_CLASS = "org.apache.skywalking.apm.plugin.okhttp.common.RealCallInterceptor"; + + @Override + protected ClassMatch enhanceClass() { + return NameMatch.byName(ENHANCE_CLASS); + } + + @Override + public ConstructorInterceptPoint[] getConstructorsInterceptPoints() { + return new ConstructorInterceptPoint[] { + new ConstructorInterceptPoint() { + @Override + public ElementMatcher getConstructorMatcher() { + return any(); + } + + @Override + public String getConstructorInterceptor() { + return INTERCEPT_CLASS; + } + } + }; + } + + @Override + public InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { + return new InstanceMethodsInterceptPoint[] { + new InstanceMethodsInterceptPoint() { + @Override + public ElementMatcher getMethodsMatcher() { + return named("execute"); + } + + @Override + public String getMethodsInterceptor() { + return INTERCEPT_CLASS; + } + + @Override + public boolean isOverrideArgs() { + return false; + } + }, + new InstanceMethodsInterceptPoint() { + @Override + public ElementMatcher getMethodsMatcher() { + return named("enqueue").and(takesArguments(1)); + } + + @Override + public String getMethodsInterceptor() { + return "org.apache.skywalking.apm.plugin.okhttp.common.EnqueueInterceptor"; + } + + @Override + public boolean isOverrideArgs() { + return false; + } + } + }; + } +} diff --git a/apm-sniffer/apm-sdk-plugin/okhttp-4.x-plugin/src/main/resources/skywalking-plugin.def b/apm-sniffer/apm-sdk-plugin/okhttp-4.x-plugin/src/main/resources/skywalking-plugin.def new file mode 100644 index 0000000000000000000000000000000000000000..2da0decf3fac049efa53387702394a7bb3740ef3 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/okhttp-4.x-plugin/src/main/resources/skywalking-plugin.def @@ -0,0 +1,19 @@ +# 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. + +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-common/pom.xml b/apm-sniffer/apm-sdk-plugin/okhttp-common/pom.xml new file mode 100644 index 0000000000000000000000000000000000000000..638b21081b5439fa483f8afa77b9680c0b287d99 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/okhttp-common/pom.xml @@ -0,0 +1,56 @@ + + + + + + apm-sdk-plugin + org.apache.skywalking + 8.6.0-SNAPSHOT + + 4.0.0 + + apm-okhttp-common + jar + + okhttp-common + http://maven.apache.org + + + 3.7.0 + + + + + com.squareup.okhttp3 + okhttp + ${okhttp.version} + provided + + + + + + + maven-deploy-plugin + + + + \ 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 452b5ba4638b5b069504432547fb13448636ffa2..75656920c2f574fc73e24ed65d6205f4f1c42a82 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 25046cd48623407104652acf55f3a911ed266052..311cf1cc1ef4d637e2eece1479f230b41070ff32 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 e4612a97dc651e475f87b9a1aca473a6ec724b78..f6900a4cf56a8e51ec8f920a5b738cdcbbd09b92 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 be4b82df19aac6453f4f593e6cfa6f105179b74e..8b38b4c8dbe1db1caa4cf700f772916bfd46eb46 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 4649d016b8acb0c63e1780ab4cf26304a6b80f27..62728b3647e49db4d3a1c3271135c3b04b5cfdf0 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 b88f846233ee6749dd8a520331d1814ceefc25af..af3a169d96c5d6b55f80fa1f4c59407f4ea6a015 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 57464edad0c1c67460c83f7e31be0719d904e1a4..36fbf91a659cdc3dc30a14b5f16eb070da2edaab 100644 --- a/apm-sniffer/apm-sdk-plugin/pom.xml +++ b/apm-sniffer/apm-sdk-plugin/pom.xml @@ -39,6 +39,8 @@ mongodb-4.x-plugin feign-default-http-9.x-plugin okhttp-3.x-plugin + okhttp-4.x-plugin + okhttp-common spring-plugins struts2-2.x-plugin nutz-plugins 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 a29d325572490c95c27a266872dadd5567134334..43618d1b6585555cd56f104ef44198e89d766b9a 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 e5a9501f2bfb61560dbc2476e8f9617d1325f594..625a5662b23c867696c325c920426307a096008a 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 cd7736b31c97dbd1a3f4a31de01b7a05a22ca330..061f66549ab161887c88e264ae7554d3255048ce 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