From 0e43088ea851f1d0bbdee4ca756fecf6535f6575 Mon Sep 17 00:00:00 2001 From: yanfch Date: Tue, 14 May 2019 10:36:09 +0800 Subject: [PATCH 01/10] feat(agent sdk): resteasy plugin --- .../trace/component/ComponentsDefine.java | 5 +- apm-sniffer/apm-sdk-plugin/pom.xml | 1 + .../apm-sdk-plugin/resteasy-plugin/pom.xml | 26 +++ .../resteasy-server-3.x-plugin/pom.xml | 30 +++ ...nchronousDeliveryExceptionInterceptor.java | 33 ++++ .../AsynchronousDeliveryInterceptor.java | 32 ++++ ...ynchronousResponseInjectorInterceptor.java | 31 ++++ ...hronousDispatcherExceptionInterceptor.java | 35 ++++ .../SynchronousDispatcherInterceptor.java | 56 ++++++ ...ronousResponseInjectorInstrumentation.java | 53 ++++++ .../SynchronousDispatcherInstrumentation.java | 106 +++++++++++ .../src/main/resources/skywalking-plugin.def | 18 ++ .../resteasy/v3/server/AssertTools.java | 32 ++++ .../AsynchronousDeliveryInterceptorTest.java | 160 ++++++++++++++++ .../SynchronousDispatcherInterceptorTest.java | 174 ++++++++++++++++++ .../main/resources/component-libraries.yml | 3 + 16 files changed, 794 insertions(+), 1 deletion(-) create mode 100644 apm-sniffer/apm-sdk-plugin/resteasy-plugin/pom.xml create mode 100644 apm-sniffer/apm-sdk-plugin/resteasy-plugin/resteasy-server-3.x-plugin/pom.xml create mode 100644 apm-sniffer/apm-sdk-plugin/resteasy-plugin/resteasy-server-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/resteasy/v3/server/AsynchronousDeliveryExceptionInterceptor.java create mode 100644 apm-sniffer/apm-sdk-plugin/resteasy-plugin/resteasy-server-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/resteasy/v3/server/AsynchronousDeliveryInterceptor.java create mode 100644 apm-sniffer/apm-sdk-plugin/resteasy-plugin/resteasy-server-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/resteasy/v3/server/AsynchronousResponseInjectorInterceptor.java create mode 100644 apm-sniffer/apm-sdk-plugin/resteasy-plugin/resteasy-server-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/resteasy/v3/server/SynchronousDispatcherExceptionInterceptor.java create mode 100644 apm-sniffer/apm-sdk-plugin/resteasy-plugin/resteasy-server-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/resteasy/v3/server/SynchronousDispatcherInterceptor.java create mode 100644 apm-sniffer/apm-sdk-plugin/resteasy-plugin/resteasy-server-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/resteasy/v3/server/define/AsynchronousResponseInjectorInstrumentation.java create mode 100644 apm-sniffer/apm-sdk-plugin/resteasy-plugin/resteasy-server-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/resteasy/v3/server/define/SynchronousDispatcherInstrumentation.java create mode 100644 apm-sniffer/apm-sdk-plugin/resteasy-plugin/resteasy-server-3.x-plugin/src/main/resources/skywalking-plugin.def create mode 100644 apm-sniffer/apm-sdk-plugin/resteasy-plugin/resteasy-server-3.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/resteasy/v3/server/AssertTools.java create mode 100644 apm-sniffer/apm-sdk-plugin/resteasy-plugin/resteasy-server-3.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/resteasy/v3/server/AsynchronousDeliveryInterceptorTest.java create mode 100644 apm-sniffer/apm-sdk-plugin/resteasy-plugin/resteasy-server-3.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/resteasy/v3/server/SynchronousDispatcherInterceptorTest.java diff --git a/apm-protocol/apm-network/src/main/java/org/apache/skywalking/apm/network/trace/component/ComponentsDefine.java b/apm-protocol/apm-network/src/main/java/org/apache/skywalking/apm/network/trace/component/ComponentsDefine.java index 2a3116148669..951f0f831721 100644 --- a/apm-protocol/apm-network/src/main/java/org/apache/skywalking/apm/network/trace/component/ComponentsDefine.java +++ b/apm-protocol/apm-network/src/main/java/org/apache/skywalking/apm/network/trace/component/ComponentsDefine.java @@ -116,6 +116,8 @@ public class ComponentsDefine { public static final OfficialComponent VERTX = new OfficialComponent(59, "Vert.x"); + public static final OfficialComponent RESTEASY = new OfficialComponent(60, "RESTEasy"); + private static ComponentsDefine INSTANCE = new ComponentsDefine(); private String[] components; @@ -125,7 +127,7 @@ public static ComponentsDefine getInstance() { } public ComponentsDefine() { - components = new String[60]; + components = new String[61]; addComponent(TOMCAT); addComponent(HTTPCLIENT); addComponent(DUBBO); @@ -170,6 +172,7 @@ public ComponentsDefine() { addComponent(LETTUCE); addComponent(ZOOKEEPER); addComponent(VERTX); + addComponent(RESTEASY); } private void addComponent(OfficialComponent component) { diff --git a/apm-sniffer/apm-sdk-plugin/pom.xml b/apm-sniffer/apm-sdk-plugin/pom.xml index ff5904e88c47..8678c3a9e971 100644 --- a/apm-sniffer/apm-sdk-plugin/pom.xml +++ b/apm-sniffer/apm-sdk-plugin/pom.xml @@ -70,6 +70,7 @@ dubbo-2.7.x-plugin dubbo-2.7.x-conflict-patch vertx-plugins + resteasy-plugin pom diff --git a/apm-sniffer/apm-sdk-plugin/resteasy-plugin/pom.xml b/apm-sniffer/apm-sdk-plugin/resteasy-plugin/pom.xml new file mode 100644 index 000000000000..46be6584d578 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/resteasy-plugin/pom.xml @@ -0,0 +1,26 @@ + + + 4.0.0 + + org.apache.skywalking + apm-sdk-plugin + 6.2.0-SNAPSHOT + + + resteasy-plugin + + resteasy-server-3.x-plugin + + + pom + + resteasy-plugin + http://maven.apache.org + + + UTF-8 + /.. + + \ No newline at end of file diff --git a/apm-sniffer/apm-sdk-plugin/resteasy-plugin/resteasy-server-3.x-plugin/pom.xml b/apm-sniffer/apm-sdk-plugin/resteasy-plugin/resteasy-server-3.x-plugin/pom.xml new file mode 100644 index 000000000000..8c4eef981596 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/resteasy-plugin/resteasy-server-3.x-plugin/pom.xml @@ -0,0 +1,30 @@ + + + 4.0.0 + + resteasy-plugin + org.apache.skywalking + 6.2.0-SNAPSHOT + + + resteasy-server-3.x-plugin + jar + + apm-resteasy-server-3.x-plugin + http://maven.apache.org + + + 3.1.0.Final + + + + + org.jboss.resteasy + resteasy-jaxrs + ${resteasy.version} + provided + + + \ No newline at end of file diff --git a/apm-sniffer/apm-sdk-plugin/resteasy-plugin/resteasy-server-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/resteasy/v3/server/AsynchronousDeliveryExceptionInterceptor.java b/apm-sniffer/apm-sdk-plugin/resteasy-plugin/resteasy-server-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/resteasy/v3/server/AsynchronousDeliveryExceptionInterceptor.java new file mode 100644 index 000000000000..8740f34fbc47 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/resteasy-plugin/resteasy-server-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/resteasy/v3/server/AsynchronousDeliveryExceptionInterceptor.java @@ -0,0 +1,33 @@ +package org.apache.skywalking.apm.plugin.resteasy.v3.server; + +import org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan; +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; + +/** + * @author yan-fucheng + */ +public class AsynchronousDeliveryExceptionInterceptor implements InstanceMethodsAroundInterceptor { + + @Override + public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, + MethodInterceptResult result) throws Throwable { + ((AbstractSpan) objInst.getSkyWalkingDynamicField()).errorOccurred().log((Throwable) allArguments[2]); + } + + @Override + public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, + Object ret) throws Throwable { + ((AbstractSpan) objInst.getSkyWalkingDynamicField()).asyncFinish(); + return ret; + } + + @Override + public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, + Class[] argumentsTypes, Throwable t) { + ((AbstractSpan) objInst.getSkyWalkingDynamicField()).errorOccurred().log(t); + } +} diff --git a/apm-sniffer/apm-sdk-plugin/resteasy-plugin/resteasy-server-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/resteasy/v3/server/AsynchronousDeliveryInterceptor.java b/apm-sniffer/apm-sdk-plugin/resteasy-plugin/resteasy-server-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/resteasy/v3/server/AsynchronousDeliveryInterceptor.java new file mode 100644 index 000000000000..8fd5cb57d352 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/resteasy-plugin/resteasy-server-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/resteasy/v3/server/AsynchronousDeliveryInterceptor.java @@ -0,0 +1,32 @@ +package org.apache.skywalking.apm.plugin.resteasy.v3.server; + +import org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan; +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; + +/** + * @author yan-fucheng + */ +public class AsynchronousDeliveryInterceptor implements InstanceMethodsAroundInterceptor { + + @Override + public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, + MethodInterceptResult result) throws Throwable { + } + + @Override + public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, + Object ret) throws Throwable { + ((AbstractSpan) objInst.getSkyWalkingDynamicField()).asyncFinish(); + return ret; + } + + @Override + public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, + Class[] argumentsTypes, Throwable t) { + ((AbstractSpan) objInst.getSkyWalkingDynamicField()).errorOccurred().log(t); + } +} diff --git a/apm-sniffer/apm-sdk-plugin/resteasy-plugin/resteasy-server-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/resteasy/v3/server/AsynchronousResponseInjectorInterceptor.java b/apm-sniffer/apm-sdk-plugin/resteasy-plugin/resteasy-server-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/resteasy/v3/server/AsynchronousResponseInjectorInterceptor.java new file mode 100644 index 000000000000..38738ff48c39 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/resteasy-plugin/resteasy-server-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/resteasy/v3/server/AsynchronousResponseInjectorInterceptor.java @@ -0,0 +1,31 @@ +package org.apache.skywalking.apm.plugin.resteasy.v3.server; + +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; + +/** + * @author yan-fucheng + */ +public class AsynchronousResponseInjectorInterceptor implements InstanceMethodsAroundInterceptor { + + @Override + public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, + MethodInterceptResult result) throws Throwable { + ContextManager.activeSpan().prepareForAsync(); + } + + @Override + public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, + Object ret) throws Throwable { + return ret; + } + + @Override + public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, + Class[] argumentsTypes, Throwable t) { + } +} diff --git a/apm-sniffer/apm-sdk-plugin/resteasy-plugin/resteasy-server-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/resteasy/v3/server/SynchronousDispatcherExceptionInterceptor.java b/apm-sniffer/apm-sdk-plugin/resteasy-plugin/resteasy-server-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/resteasy/v3/server/SynchronousDispatcherExceptionInterceptor.java new file mode 100644 index 000000000000..3de1b392ef6d --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/resteasy-plugin/resteasy-server-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/resteasy/v3/server/SynchronousDispatcherExceptionInterceptor.java @@ -0,0 +1,35 @@ +package org.apache.skywalking.apm.plugin.resteasy.v3.server; + +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 org.jboss.resteasy.spi.HttpRequest; + +import java.lang.reflect.Method; + +/** + * @author yan-fucheng + */ +public class SynchronousDispatcherExceptionInterceptor implements InstanceMethodsAroundInterceptor { + + @Override + public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, + MethodInterceptResult result) throws Throwable { + if (ContextManager.isActive() && !((HttpRequest) allArguments[0]).getAsyncContext().isSuspended()) { + ContextManager.activeSpan().errorOccurred().log((Throwable)allArguments[2]); + } + } + + @Override + public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, + Object ret) throws Throwable { + return ret; + } + + @Override + public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, + Class[] argumentsTypes, Throwable t) { + ContextManager.activeSpan().errorOccurred().log(t); + } +} diff --git a/apm-sniffer/apm-sdk-plugin/resteasy-plugin/resteasy-server-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/resteasy/v3/server/SynchronousDispatcherInterceptor.java b/apm-sniffer/apm-sdk-plugin/resteasy-plugin/resteasy-server-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/resteasy/v3/server/SynchronousDispatcherInterceptor.java new file mode 100644 index 000000000000..e080535ee0a0 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/resteasy-plugin/resteasy-server-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/resteasy/v3/server/SynchronousDispatcherInterceptor.java @@ -0,0 +1,56 @@ +package org.apache.skywalking.apm.plugin.resteasy.v3.server; + +import org.apache.skywalking.apm.agent.core.context.CarrierItem; +import org.apache.skywalking.apm.agent.core.context.ContextCarrier; +import org.apache.skywalking.apm.agent.core.context.ContextManager; +import org.apache.skywalking.apm.agent.core.context.tag.Tags; +import org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan; +import org.apache.skywalking.apm.agent.core.context.trace.SpanLayer; +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 org.apache.skywalking.apm.network.trace.component.ComponentsDefine; +import org.jboss.resteasy.spi.HttpRequest; + +import java.lang.reflect.Method; + +/** + * @author yan-fucheng + */ +public class SynchronousDispatcherInterceptor implements InstanceMethodsAroundInterceptor { + + @Override + public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, + MethodInterceptResult result) throws Throwable { + HttpRequest request = (HttpRequest) allArguments[0]; + if (request != null) { + ContextCarrier contextCarrier = new ContextCarrier(); + CarrierItem next = contextCarrier.items(); + while (next.hasNext()) { + next = next.next(); + next.setHeadValue(request.getHttpHeaders().getHeaderString(next.getHeadKey())); + } + + AbstractSpan span = ContextManager.createEntrySpan(request.getUri().getPath(), contextCarrier); + Tags.URL.set(span, request.getUri().getRequestUri().toString()); + Tags.HTTP.METHOD.set(span, request.getHttpMethod()); + span.setComponent(ComponentsDefine.RESTEASY); + SpanLayer.asHttp(span); + + objInst.setSkyWalkingDynamicField(span); + } + } + + @Override + public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, + Object ret) throws Throwable { + ContextManager.stopSpan(); + return ret; + } + + @Override + public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, + Class[] argumentsTypes, Throwable t) { + ContextManager.activeSpan().errorOccurred().log(t); + } +} diff --git a/apm-sniffer/apm-sdk-plugin/resteasy-plugin/resteasy-server-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/resteasy/v3/server/define/AsynchronousResponseInjectorInstrumentation.java b/apm-sniffer/apm-sdk-plugin/resteasy-plugin/resteasy-server-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/resteasy/v3/server/define/AsynchronousResponseInjectorInstrumentation.java new file mode 100644 index 000000000000..27577139877b --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/resteasy-plugin/resteasy-server-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/resteasy/v3/server/define/AsynchronousResponseInjectorInstrumentation.java @@ -0,0 +1,53 @@ +package org.apache.skywalking.apm.plugin.resteasy.v3.server.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; + +import static net.bytebuddy.matcher.ElementMatchers.named; +import static net.bytebuddy.matcher.ElementMatchers.takesArguments; + +/** + * @author yan-fucheng + */ +public class AsynchronousResponseInjectorInstrumentation extends ClassInstanceMethodsEnhancePluginDefine { + + private static final String ENHANCE_CLASS = "org.jboss.resteasy.core.AsynchronousResponseInjector"; + private static final String ASYNC_INJECT_INTERCEPT_CLASS = "org.apache.skywalking.apm.plugin.resteasy.v3.server.AsynchronousResponseInjectorInterceptor"; + + @Override + protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() { + return null; + } + + @Override + protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { + return new InstanceMethodsInterceptPoint[] { + new InstanceMethodsInterceptPoint() { + @Override + public ElementMatcher getMethodsMatcher() { + return named("inject").and(takesArguments(2)); + } + + @Override + public String getMethodsInterceptor() { + return ASYNC_INJECT_INTERCEPT_CLASS; + } + + @Override + public boolean isOverrideArgs() { + return false; + } + } + }; + } + + @Override + protected ClassMatch enhanceClass() { + return NameMatch.byName(ENHANCE_CLASS); + } +} diff --git a/apm-sniffer/apm-sdk-plugin/resteasy-plugin/resteasy-server-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/resteasy/v3/server/define/SynchronousDispatcherInstrumentation.java b/apm-sniffer/apm-sdk-plugin/resteasy-plugin/resteasy-server-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/resteasy/v3/server/define/SynchronousDispatcherInstrumentation.java new file mode 100644 index 000000000000..e894227a05f3 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/resteasy-plugin/resteasy-server-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/resteasy/v3/server/define/SynchronousDispatcherInstrumentation.java @@ -0,0 +1,106 @@ +package org.apache.skywalking.apm.plugin.resteasy.v3.server.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; + +import static net.bytebuddy.matcher.ElementMatchers.named; +import static net.bytebuddy.matcher.ElementMatchers.takesArguments; + +/** + * @author yan-fucheng + */ +public class SynchronousDispatcherInstrumentation extends ClassInstanceMethodsEnhancePluginDefine { + + private static final String ENHANCE_CLASS = "org.jboss.resteasy.core.SynchronousDispatcher"; + + private static final String INVOKE_INTERCEPT_CLASS = "org.apache.skywalking.apm.plugin.resteasy.v3.server.SynchronousDispatcherInterceptor"; + private static final String INVOKE_EXCEPTION_INTERCEPT_CLASS = "org.apache.skywalking.apm.plugin.resteasy.v3.server.SynchronousDispatcherExceptionInterceptor"; + + private static final String ASYNC_DELIVERY_INTERCEPT_CLASS = "org.apache.skywalking.apm.plugin.resteasy.v3.server.AsynchronousDeliveryInterceptor"; + private static final String ASYNC_DELIVERY_EXCEPTION_INTERCEPT_CLASS = "org.apache.skywalking.apm.plugin.resteasy.v3.server.AsynchronousDeliveryExceptionInterceptor"; + + @Override + protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() { + return null; + } + + @Override + protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { + return new InstanceMethodsInterceptPoint[] { + new InstanceMethodsInterceptPoint() { + @Override + public ElementMatcher getMethodsMatcher() { + return named("invoke").and(takesArguments(3)); + } + + @Override + public String getMethodsInterceptor() { + return INVOKE_INTERCEPT_CLASS; + } + + @Override + public boolean isOverrideArgs() { + return false; + } + }, + new InstanceMethodsInterceptPoint() { + @Override + public ElementMatcher getMethodsMatcher() { + return named("writeException").and(takesArguments(3)); + } + + @Override + public String getMethodsInterceptor() { + return INVOKE_EXCEPTION_INTERCEPT_CLASS; + } + + @Override + public boolean isOverrideArgs() { + return false; + } + }, + new InstanceMethodsInterceptPoint() { + @Override + public ElementMatcher getMethodsMatcher() { + return named("asynchronousDelivery").and(takesArguments(3)); + } + + @Override + public String getMethodsInterceptor() { + return ASYNC_DELIVERY_INTERCEPT_CLASS; + } + + @Override + public boolean isOverrideArgs() { + return false; + } + }, + new InstanceMethodsInterceptPoint() { + @Override + public ElementMatcher getMethodsMatcher() { + return named("asynchronousExceptionDelivery").and(takesArguments(3)); + } + + @Override + public String getMethodsInterceptor() { + return ASYNC_DELIVERY_EXCEPTION_INTERCEPT_CLASS; + } + + @Override + public boolean isOverrideArgs() { + return false; + } + } + }; + } + + @Override + protected ClassMatch enhanceClass() { + return NameMatch.byName(ENHANCE_CLASS); + } +} diff --git a/apm-sniffer/apm-sdk-plugin/resteasy-plugin/resteasy-server-3.x-plugin/src/main/resources/skywalking-plugin.def b/apm-sniffer/apm-sdk-plugin/resteasy-plugin/resteasy-server-3.x-plugin/src/main/resources/skywalking-plugin.def new file mode 100644 index 000000000000..13c2429aac1d --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/resteasy-plugin/resteasy-server-3.x-plugin/src/main/resources/skywalking-plugin.def @@ -0,0 +1,18 @@ +# 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. + +resteasy-server-3.x=org.apache.skywalking.apm.plugin.resteasy.v3.server.define.SynchronousDispatcherInstrumentation +resteasy-server-3.x=org.apache.skywalking.apm.plugin.resteasy.v3.server.define.AsynchronousResponseInjectorInstrumentation \ No newline at end of file diff --git a/apm-sniffer/apm-sdk-plugin/resteasy-plugin/resteasy-server-3.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/resteasy/v3/server/AssertTools.java b/apm-sniffer/apm-sdk-plugin/resteasy-plugin/resteasy-server-3.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/resteasy/v3/server/AssertTools.java new file mode 100644 index 000000000000..257b88336491 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/resteasy-plugin/resteasy-server-3.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/resteasy/v3/server/AssertTools.java @@ -0,0 +1,32 @@ +package org.apache.skywalking.apm.plugin.resteasy.v3.server; + +import org.apache.skywalking.apm.agent.core.context.trace.AbstractTracingSpan; +import org.apache.skywalking.apm.agent.core.context.trace.SpanLayer; +import org.apache.skywalking.apm.agent.core.context.trace.TraceSegmentRef; +import org.apache.skywalking.apm.agent.test.helper.SegmentRefHelper; +import org.apache.skywalking.apm.agent.test.tools.SpanAssert; +import org.apache.skywalking.apm.network.trace.component.ComponentsDefine; + +import static org.apache.skywalking.apm.agent.test.tools.SpanAssert.assertComponent; +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.MatcherAssert.assertThat; + +/** + * @author yan-fucheng + */ +class AssertTools { + + static void assertTraceSegmentRef(TraceSegmentRef ref) { + assertThat(SegmentRefHelper.getEntryServiceInstanceId(ref), is(1)); + assertThat(SegmentRefHelper.getSpanId(ref), is(3)); + assertThat(SegmentRefHelper.getTraceSegmentId(ref).toString(), is("1.234.111")); + } + + static void assertHttpSpan(AbstractTracingSpan span) { + assertThat(span.getOperationName(), is("/test/testRequestURL")); + assertComponent(span, ComponentsDefine.RESTEASY); + SpanAssert.assertTag(span, 0, "http://localhost:8080/test/testRequestURL"); + assertThat(span.isEntry(), is(true)); + SpanAssert.assertLayer(span, SpanLayer.HTTP); + } +} diff --git a/apm-sniffer/apm-sdk-plugin/resteasy-plugin/resteasy-server-3.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/resteasy/v3/server/AsynchronousDeliveryInterceptorTest.java b/apm-sniffer/apm-sdk-plugin/resteasy-plugin/resteasy-server-3.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/resteasy/v3/server/AsynchronousDeliveryInterceptorTest.java new file mode 100644 index 000000000000..71e3bab71108 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/resteasy-plugin/resteasy-server-3.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/resteasy/v3/server/AsynchronousDeliveryInterceptorTest.java @@ -0,0 +1,160 @@ +package org.apache.skywalking.apm.plugin.resteasy.v3.server; + +import org.apache.skywalking.apm.agent.core.context.trace.AbstractTracingSpan; +import org.apache.skywalking.apm.agent.core.context.trace.LogDataEntity; +import org.apache.skywalking.apm.agent.core.context.trace.TraceSegment; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; +import org.apache.skywalking.apm.agent.test.helper.SegmentHelper; +import org.apache.skywalking.apm.agent.test.helper.SpanHelper; +import org.apache.skywalking.apm.agent.test.tools.*; +import org.jboss.resteasy.core.ResourceInvoker; +import org.jboss.resteasy.specimpl.MultivaluedMapImpl; +import org.jboss.resteasy.specimpl.ResteasyHttpHeaders; +import org.jboss.resteasy.spi.HttpRequest; +import org.jboss.resteasy.spi.HttpResponse; +import org.jboss.resteasy.spi.ResteasyAsynchronousContext; +import org.jboss.resteasy.spi.ResteasyUriInfo; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.powermock.modules.junit4.PowerMockRunner; +import org.powermock.modules.junit4.PowerMockRunnerDelegate; + +import java.net.URI; +import java.net.URISyntaxException; +import java.util.List; + +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.mockito.Mockito.when; + +/** + * @author yan-fucheng + */ +@RunWith(PowerMockRunner.class) +@PowerMockRunnerDelegate(TracingSegmentRunner.class) +public class AsynchronousDeliveryInterceptorTest { + + private SynchronousDispatcherInterceptor synchronousDispatcherInterceptor; + private SynchronousDispatcherExceptionInterceptor synchronousDispatcherExceptionInterceptor; + + private AsynchronousResponseInjectorInterceptor asynchronousResponseInjectorInterceptor; + private AsynchronousDeliveryInterceptor asynchronousDeliveryInterceptor; + private AsynchronousDeliveryExceptionInterceptor asynchronousDeliveryExceptionInterceptor; + + @SegmentStoragePoint + private SegmentStorage segmentStorage; + + @Rule + public AgentServiceRule serviceRule = new AgentServiceRule(); + + @Mock + HttpRequest request; + + @Mock + HttpResponse response; + + @Mock + ResourceInvoker resourceInvoker; + + @Mock + private MethodInterceptResult methodInterceptResult; + + @Mock + private ResteasyAsynchronousContext resteasyAsynchronousContext; + + private EnhancedInstance enhancedInstance = new EnhancedInstance() { + + private Object object; + + @Override + public Object getSkyWalkingDynamicField() { + return object; + } + + @Override public void setSkyWalkingDynamicField(Object value) { + this.object = value; + } + }; + + private Object[] arguments; + private Class[] argumentType; + + private Object[] exceptionArguments; + private Class[] exceptionArgumentType; + + @Before + public void setup() throws URISyntaxException { + synchronousDispatcherInterceptor = new SynchronousDispatcherInterceptor(); + synchronousDispatcherExceptionInterceptor = new SynchronousDispatcherExceptionInterceptor(); + + asynchronousResponseInjectorInterceptor = new AsynchronousResponseInjectorInterceptor(); + asynchronousDeliveryInterceptor = new AsynchronousDeliveryInterceptor(); + asynchronousDeliveryExceptionInterceptor = new AsynchronousDeliveryExceptionInterceptor(); + + when(request.getUri()).thenReturn(new ResteasyUriInfo(new URI("http://localhost:8080/test/testRequestURL"))); + when(request.getHttpHeaders()).thenReturn(new ResteasyHttpHeaders(new MultivaluedMapImpl())); + when(response.getStatus()).thenReturn(200); + when(request.getAsyncContext()).thenReturn(resteasyAsynchronousContext); + when(request.getAsyncContext().isSuspended()).thenReturn(true); + arguments = new Object[] {request, response, resourceInvoker}; + argumentType = new Class[] {request.getClass(), response.getClass(), resourceInvoker.getClass()}; + + exceptionArguments = new Object[] {request, response, new RuntimeException()}; + exceptionArgumentType = new Class[] {request.getClass(), response.getClass(), new RuntimeException().getClass()}; + } + + @Test + public void testWithoutSerializedContextData() throws Throwable { + synchronousDispatcherInterceptor.beforeMethod(enhancedInstance, null, arguments, argumentType, methodInterceptResult); + asynchronousResponseInjectorInterceptor.beforeMethod(enhancedInstance, null, new Object[] {request, response}, argumentType, methodInterceptResult); + synchronousDispatcherInterceptor.afterMethod(enhancedInstance, null, arguments, argumentType, null); + asynchronousDeliveryInterceptor.afterMethod(enhancedInstance, null, arguments, argumentType, null); + + assertThat(segmentStorage.getTraceSegments().size(), is(1)); + TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0); + List spans = SegmentHelper.getSpans(traceSegment); + AssertTools.assertHttpSpan(spans.get(0)); + } + + @Test + public void testWithMainThreadOccurException() throws Throwable { + synchronousDispatcherInterceptor.beforeMethod(enhancedInstance, null, arguments, argumentType, methodInterceptResult); + asynchronousResponseInjectorInterceptor.beforeMethod(enhancedInstance, null, new Object[] {request, response}, argumentType, methodInterceptResult); + asynchronousDeliveryExceptionInterceptor.beforeMethod(enhancedInstance, null, exceptionArguments, exceptionArgumentType, null); + synchronousDispatcherExceptionInterceptor.beforeMethod(enhancedInstance, null, exceptionArguments, exceptionArgumentType, null); + asynchronousDeliveryExceptionInterceptor.afterMethod(enhancedInstance, null, exceptionArguments, exceptionArgumentType, null); + synchronousDispatcherInterceptor.afterMethod(enhancedInstance, null, arguments, argumentType, null); + + assertThat(segmentStorage.getTraceSegments().size(), is(1)); + TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0); + List spans = SegmentHelper.getSpans(traceSegment); + + AssertTools.assertHttpSpan(spans.get(0)); + List logDataEntities = SpanHelper.getLogs(spans.get(0)); + assertThat(logDataEntities.size(), is(1)); + SpanAssert.assertException(logDataEntities.get(0), RuntimeException.class); + } + + @Test + public void testWithAsyncThreadOccurException() throws Throwable { + synchronousDispatcherInterceptor.beforeMethod(enhancedInstance, null, arguments, argumentType, methodInterceptResult); + asynchronousResponseInjectorInterceptor.beforeMethod(enhancedInstance, null, new Object[] {request, response}, argumentType, methodInterceptResult); + synchronousDispatcherInterceptor.afterMethod(enhancedInstance, null, arguments, argumentType, null); + asynchronousDeliveryExceptionInterceptor.beforeMethod(enhancedInstance, null, exceptionArguments, exceptionArgumentType, null); + synchronousDispatcherExceptionInterceptor.beforeMethod(enhancedInstance, null, exceptionArguments, exceptionArgumentType, null); + asynchronousDeliveryExceptionInterceptor.afterMethod(enhancedInstance, null, exceptionArguments, exceptionArgumentType, null); + + assertThat(segmentStorage.getTraceSegments().size(), is(1)); + TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0); + List spans = SegmentHelper.getSpans(traceSegment); + + AssertTools.assertHttpSpan(spans.get(0)); + List logDataEntities = SpanHelper.getLogs(spans.get(0)); + assertThat(logDataEntities.size(), is(1)); + SpanAssert.assertException(logDataEntities.get(0), RuntimeException.class); + } +} diff --git a/apm-sniffer/apm-sdk-plugin/resteasy-plugin/resteasy-server-3.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/resteasy/v3/server/SynchronousDispatcherInterceptorTest.java b/apm-sniffer/apm-sdk-plugin/resteasy-plugin/resteasy-server-3.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/resteasy/v3/server/SynchronousDispatcherInterceptorTest.java new file mode 100644 index 000000000000..de8e112beec8 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/resteasy-plugin/resteasy-server-3.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/resteasy/v3/server/SynchronousDispatcherInterceptorTest.java @@ -0,0 +1,174 @@ +package org.apache.skywalking.apm.plugin.resteasy.v3.server; + +import org.apache.skywalking.apm.agent.core.conf.Config; +import org.apache.skywalking.apm.agent.core.context.SW3CarrierItem; +import org.apache.skywalking.apm.agent.core.context.SW6CarrierItem; +import org.apache.skywalking.apm.agent.core.context.trace.AbstractTracingSpan; +import org.apache.skywalking.apm.agent.core.context.trace.LogDataEntity; +import org.apache.skywalking.apm.agent.core.context.trace.TraceSegment; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; +import org.apache.skywalking.apm.agent.test.helper.SegmentHelper; +import org.apache.skywalking.apm.agent.test.helper.SpanHelper; +import org.apache.skywalking.apm.agent.test.tools.*; +import org.jboss.resteasy.core.ResourceInvoker; +import org.jboss.resteasy.specimpl.MultivaluedMapImpl; +import org.jboss.resteasy.specimpl.ResteasyHttpHeaders; +import org.jboss.resteasy.spi.HttpRequest; +import org.jboss.resteasy.spi.HttpResponse; +import org.jboss.resteasy.spi.ResteasyAsynchronousContext; +import org.jboss.resteasy.spi.ResteasyUriInfo; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.powermock.modules.junit4.PowerMockRunner; +import org.powermock.modules.junit4.PowerMockRunnerDelegate; + +import java.net.URI; +import java.net.URISyntaxException; +import java.util.List; + +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.mockito.Mockito.when; + +/** + * @author yan-fucheng + */ +@RunWith(PowerMockRunner.class) +@PowerMockRunnerDelegate(TracingSegmentRunner.class) +public class SynchronousDispatcherInterceptorTest { + + private SynchronousDispatcherInterceptor synchronousDispatcherInterceptor; + private SynchronousDispatcherExceptionInterceptor exceptionInterceptor; + + @SegmentStoragePoint + private SegmentStorage segmentStorage; + + @Rule + public AgentServiceRule serviceRule = new AgentServiceRule(); + + @Mock + HttpRequest request; + + @Mock + HttpResponse response; + + @Mock + ResourceInvoker resourceInvoker; + + @Mock + private MethodInterceptResult methodInterceptResult; + + @Mock + private ResteasyAsynchronousContext resteasyAsynchronousContext; + + @Mock + EnhancedInstance enhancedInstance; + + private Object[] arguments; + private Class[] argumentType; + + private Object[] exceptionArguments; + private Class[] exceptionArgumentType; + + @Before + public void setup() throws URISyntaxException { + synchronousDispatcherInterceptor = new SynchronousDispatcherInterceptor(); + exceptionInterceptor = new SynchronousDispatcherExceptionInterceptor(); + when(request.getUri()).thenReturn(new ResteasyUriInfo(new URI("http://localhost:8080/test/testRequestURL"))); + when(request.getHttpHeaders()).thenReturn(new ResteasyHttpHeaders(new MultivaluedMapImpl())); + when(response.getStatus()).thenReturn(200); + when(request.getAsyncContext()).thenReturn(resteasyAsynchronousContext); + when(request.getAsyncContext().isSuspended()).thenReturn(false); + arguments = new Object[] {request, response, resourceInvoker}; + argumentType = new Class[] {request.getClass(), response.getClass(), resourceInvoker.getClass()}; + + exceptionArguments = new Object[] {request, response, new RuntimeException()}; + exceptionArgumentType = new Class[] {request.getClass(), response.getClass(), new RuntimeException().getClass()}; + } + + @Test + public void testWithoutSerializedContextData() throws Throwable { + synchronousDispatcherInterceptor.beforeMethod(enhancedInstance, null, arguments, argumentType, methodInterceptResult); + synchronousDispatcherInterceptor.afterMethod(enhancedInstance, null, arguments, argumentType, null); + + assertThat(segmentStorage.getTraceSegments().size(), is(1)); + TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0); + List spans = SegmentHelper.getSpans(traceSegment); + AssertTools.assertHttpSpan(spans.get(0)); + } + + @Test + public void testWithSW6SerializedContextData() throws Throwable { + MultivaluedMapImpl multivaluedMap = new MultivaluedMapImpl(); + multivaluedMap.putSingle(SW6CarrierItem.HEADER_NAME, "1-I0FRQSojQVFBKkV0MFdlMHRRTlFBKg==-MS4yMzQuMTEx-3-1-1-IzE5Mi4xNjguMS44OjE4MDAy-Iy9wb3J0YWwv-Iy90ZXN0RW50cnlTcGFu"); + when(request.getHttpHeaders()).thenReturn(new ResteasyHttpHeaders(multivaluedMap)); + + synchronousDispatcherInterceptor.beforeMethod(enhancedInstance, null, arguments, argumentType, methodInterceptResult); + synchronousDispatcherInterceptor.afterMethod(enhancedInstance, null, arguments, argumentType, null); + + assertThat(segmentStorage.getTraceSegments().size(), is(1)); + TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0); + List spans = SegmentHelper.getSpans(traceSegment); + + AssertTools.assertHttpSpan(spans.get(0)); + AssertTools.assertTraceSegmentRef(traceSegment.getRefs().get(0)); + } + + @Test + public void testWithSW3SerializedContextData() throws Throwable { + Config.Agent.ACTIVE_V1_HEADER = true; + Config.Agent.ACTIVE_V2_HEADER = false; + MultivaluedMapImpl multivaluedMap = new MultivaluedMapImpl(); + multivaluedMap.putSingle(SW3CarrierItem.HEADER_NAME, "1.234.111|3|1|1|#192.168.1.8:18002|#/portal/|#/testEntrySpan|#AQA*#AQA*Et0We0tQNQA*"); + when(request.getHttpHeaders()).thenReturn(new ResteasyHttpHeaders(multivaluedMap)); + + synchronousDispatcherInterceptor.beforeMethod(enhancedInstance, null, arguments, argumentType, methodInterceptResult); + synchronousDispatcherInterceptor.afterMethod(enhancedInstance, null, arguments, argumentType, null); + + Config.Agent.ACTIVE_V1_HEADER = false; + Config.Agent.ACTIVE_V2_HEADER = true; + + assertThat(segmentStorage.getTraceSegments().size(), is(1)); + TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0); + List spans = SegmentHelper.getSpans(traceSegment); + + AssertTools.assertHttpSpan(spans.get(0)); + AssertTools.assertTraceSegmentRef(traceSegment.getRefs().get(0)); + } + + @Test + public void testWithOccurException() throws Throwable { + synchronousDispatcherInterceptor.beforeMethod(enhancedInstance, null, arguments, argumentType, methodInterceptResult); + synchronousDispatcherInterceptor.handleMethodException(enhancedInstance, null, arguments, argumentType, new RuntimeException()); + synchronousDispatcherInterceptor.afterMethod(enhancedInstance, null, arguments, argumentType, null); + + assertThat(segmentStorage.getTraceSegments().size(), is(1)); + TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0); + List spans = SegmentHelper.getSpans(traceSegment); + + AssertTools.assertHttpSpan(spans.get(0)); + List logDataEntities = SpanHelper.getLogs(spans.get(0)); + assertThat(logDataEntities.size(), is(1)); + SpanAssert.assertException(logDataEntities.get(0), RuntimeException.class); + } + + @Test + public void testWithMainThreadOccurException() throws Throwable { + synchronousDispatcherInterceptor.beforeMethod(enhancedInstance, null, arguments, argumentType, methodInterceptResult); + exceptionInterceptor.beforeMethod(enhancedInstance, null, exceptionArguments, exceptionArgumentType, null); + synchronousDispatcherInterceptor.afterMethod(enhancedInstance, null, arguments, argumentType, null); + + assertThat(segmentStorage.getTraceSegments().size(), is(1)); + TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0); + List spans = SegmentHelper.getSpans(traceSegment); + + AssertTools.assertHttpSpan(spans.get(0)); + List logDataEntities = SpanHelper.getLogs(spans.get(0)); + assertThat(logDataEntities.size(), is(1)); + SpanAssert.assertException(logDataEntities.get(0), RuntimeException.class); + } +} diff --git a/oap-server/server-starter/src/main/resources/component-libraries.yml b/oap-server/server-starter/src/main/resources/component-libraries.yml index 8759266baeed..6b7296a0f0d3 100644 --- a/oap-server/server-starter/src/main/resources/component-libraries.yml +++ b/oap-server/server-starter/src/main/resources/component-libraries.yml @@ -207,6 +207,9 @@ Zookeeper: Vertx: id: 59 languages: Java +RESTEasy: + id: 60 + languages: Java # .NET/.NET Core components # [3000, 4000) for C#/.NET only From a20bc0c9bbe366e5171be23ad86d46b7e2856cf8 Mon Sep 17 00:00:00 2001 From: yanfch Date: Tue, 14 May 2019 19:48:25 +0800 Subject: [PATCH 02/10] fix(agent sdk): fix component define --- docker/config/component-libraries.yml | 3 +++ .../server-core/src/test/resources/component-libraries.yml | 3 +++ 2 files changed, 6 insertions(+) diff --git a/docker/config/component-libraries.yml b/docker/config/component-libraries.yml index 767e636491aa..3708910e7f58 100644 --- a/docker/config/component-libraries.yml +++ b/docker/config/component-libraries.yml @@ -207,6 +207,9 @@ Zookeeper: Vertx: id: 59 languages: Java +RESTEasy: + id: 60 + languages: Java # .NET/.NET Core components # [3000, 4000) for C#/.NET only diff --git a/oap-server/server-core/src/test/resources/component-libraries.yml b/oap-server/server-core/src/test/resources/component-libraries.yml index 86b97dd48359..13782b2aae88 100644 --- a/oap-server/server-core/src/test/resources/component-libraries.yml +++ b/oap-server/server-core/src/test/resources/component-libraries.yml @@ -189,6 +189,9 @@ Zookeeper: Vertx: id: 59 languages: Java +RESTEasy: + id: 60 + languages: Java # .NET/.NET Core components # [3000, 4000) for C#/.NET only From adef2cb844647f9ed5f9fb601952e7dce717a7bc Mon Sep 17 00:00:00 2001 From: yanfch Date: Tue, 14 May 2019 20:56:27 +0800 Subject: [PATCH 03/10] fix(agent sdk): fix file license --- ...ynchronousDeliveryExceptionInterceptor.java | 18 ++++++++++++++++++ .../AsynchronousDeliveryInterceptor.java | 18 ++++++++++++++++++ ...synchronousResponseInjectorInterceptor.java | 18 ++++++++++++++++++ ...chronousDispatcherExceptionInterceptor.java | 18 ++++++++++++++++++ .../SynchronousDispatcherInterceptor.java | 18 ++++++++++++++++++ ...hronousResponseInjectorInstrumentation.java | 18 ++++++++++++++++++ .../SynchronousDispatcherInstrumentation.java | 18 ++++++++++++++++++ .../plugin/resteasy/v3/server/AssertTools.java | 17 +++++++++++++++++ .../AsynchronousDeliveryInterceptorTest.java | 18 ++++++++++++++++++ .../SynchronousDispatcherInterceptorTest.java | 18 ++++++++++++++++++ 10 files changed, 179 insertions(+) diff --git a/apm-sniffer/apm-sdk-plugin/resteasy-plugin/resteasy-server-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/resteasy/v3/server/AsynchronousDeliveryExceptionInterceptor.java b/apm-sniffer/apm-sdk-plugin/resteasy-plugin/resteasy-server-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/resteasy/v3/server/AsynchronousDeliveryExceptionInterceptor.java index 8740f34fbc47..20ad2a2cb716 100644 --- a/apm-sniffer/apm-sdk-plugin/resteasy-plugin/resteasy-server-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/resteasy/v3/server/AsynchronousDeliveryExceptionInterceptor.java +++ b/apm-sniffer/apm-sdk-plugin/resteasy-plugin/resteasy-server-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/resteasy/v3/server/AsynchronousDeliveryExceptionInterceptor.java @@ -1,3 +1,21 @@ +/* + * 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.resteasy.v3.server; import org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan; diff --git a/apm-sniffer/apm-sdk-plugin/resteasy-plugin/resteasy-server-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/resteasy/v3/server/AsynchronousDeliveryInterceptor.java b/apm-sniffer/apm-sdk-plugin/resteasy-plugin/resteasy-server-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/resteasy/v3/server/AsynchronousDeliveryInterceptor.java index 8fd5cb57d352..4e79e889e61a 100644 --- a/apm-sniffer/apm-sdk-plugin/resteasy-plugin/resteasy-server-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/resteasy/v3/server/AsynchronousDeliveryInterceptor.java +++ b/apm-sniffer/apm-sdk-plugin/resteasy-plugin/resteasy-server-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/resteasy/v3/server/AsynchronousDeliveryInterceptor.java @@ -1,3 +1,21 @@ +/* + * 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.resteasy.v3.server; import org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan; diff --git a/apm-sniffer/apm-sdk-plugin/resteasy-plugin/resteasy-server-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/resteasy/v3/server/AsynchronousResponseInjectorInterceptor.java b/apm-sniffer/apm-sdk-plugin/resteasy-plugin/resteasy-server-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/resteasy/v3/server/AsynchronousResponseInjectorInterceptor.java index 38738ff48c39..cb585b3f3f1d 100644 --- a/apm-sniffer/apm-sdk-plugin/resteasy-plugin/resteasy-server-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/resteasy/v3/server/AsynchronousResponseInjectorInterceptor.java +++ b/apm-sniffer/apm-sdk-plugin/resteasy-plugin/resteasy-server-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/resteasy/v3/server/AsynchronousResponseInjectorInterceptor.java @@ -1,3 +1,21 @@ +/* + * 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.resteasy.v3.server; import org.apache.skywalking.apm.agent.core.context.ContextManager; diff --git a/apm-sniffer/apm-sdk-plugin/resteasy-plugin/resteasy-server-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/resteasy/v3/server/SynchronousDispatcherExceptionInterceptor.java b/apm-sniffer/apm-sdk-plugin/resteasy-plugin/resteasy-server-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/resteasy/v3/server/SynchronousDispatcherExceptionInterceptor.java index 3de1b392ef6d..5938716279e0 100644 --- a/apm-sniffer/apm-sdk-plugin/resteasy-plugin/resteasy-server-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/resteasy/v3/server/SynchronousDispatcherExceptionInterceptor.java +++ b/apm-sniffer/apm-sdk-plugin/resteasy-plugin/resteasy-server-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/resteasy/v3/server/SynchronousDispatcherExceptionInterceptor.java @@ -1,3 +1,21 @@ +/* + * 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.resteasy.v3.server; import org.apache.skywalking.apm.agent.core.context.ContextManager; diff --git a/apm-sniffer/apm-sdk-plugin/resteasy-plugin/resteasy-server-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/resteasy/v3/server/SynchronousDispatcherInterceptor.java b/apm-sniffer/apm-sdk-plugin/resteasy-plugin/resteasy-server-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/resteasy/v3/server/SynchronousDispatcherInterceptor.java index e080535ee0a0..e115c9b0c786 100644 --- a/apm-sniffer/apm-sdk-plugin/resteasy-plugin/resteasy-server-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/resteasy/v3/server/SynchronousDispatcherInterceptor.java +++ b/apm-sniffer/apm-sdk-plugin/resteasy-plugin/resteasy-server-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/resteasy/v3/server/SynchronousDispatcherInterceptor.java @@ -1,3 +1,21 @@ +/* + * 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.resteasy.v3.server; import org.apache.skywalking.apm.agent.core.context.CarrierItem; diff --git a/apm-sniffer/apm-sdk-plugin/resteasy-plugin/resteasy-server-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/resteasy/v3/server/define/AsynchronousResponseInjectorInstrumentation.java b/apm-sniffer/apm-sdk-plugin/resteasy-plugin/resteasy-server-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/resteasy/v3/server/define/AsynchronousResponseInjectorInstrumentation.java index 27577139877b..9428c204dfce 100644 --- a/apm-sniffer/apm-sdk-plugin/resteasy-plugin/resteasy-server-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/resteasy/v3/server/define/AsynchronousResponseInjectorInstrumentation.java +++ b/apm-sniffer/apm-sdk-plugin/resteasy-plugin/resteasy-server-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/resteasy/v3/server/define/AsynchronousResponseInjectorInstrumentation.java @@ -1,3 +1,21 @@ +/* + * 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.resteasy.v3.server.define; import net.bytebuddy.description.method.MethodDescription; diff --git a/apm-sniffer/apm-sdk-plugin/resteasy-plugin/resteasy-server-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/resteasy/v3/server/define/SynchronousDispatcherInstrumentation.java b/apm-sniffer/apm-sdk-plugin/resteasy-plugin/resteasy-server-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/resteasy/v3/server/define/SynchronousDispatcherInstrumentation.java index e894227a05f3..3ed012de3a2b 100644 --- a/apm-sniffer/apm-sdk-plugin/resteasy-plugin/resteasy-server-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/resteasy/v3/server/define/SynchronousDispatcherInstrumentation.java +++ b/apm-sniffer/apm-sdk-plugin/resteasy-plugin/resteasy-server-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/resteasy/v3/server/define/SynchronousDispatcherInstrumentation.java @@ -1,3 +1,21 @@ +/* + * 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.resteasy.v3.server.define; import net.bytebuddy.description.method.MethodDescription; diff --git a/apm-sniffer/apm-sdk-plugin/resteasy-plugin/resteasy-server-3.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/resteasy/v3/server/AssertTools.java b/apm-sniffer/apm-sdk-plugin/resteasy-plugin/resteasy-server-3.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/resteasy/v3/server/AssertTools.java index 257b88336491..20b2f65ea701 100644 --- a/apm-sniffer/apm-sdk-plugin/resteasy-plugin/resteasy-server-3.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/resteasy/v3/server/AssertTools.java +++ b/apm-sniffer/apm-sdk-plugin/resteasy-plugin/resteasy-server-3.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/resteasy/v3/server/AssertTools.java @@ -1,3 +1,20 @@ +/* + * 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.resteasy.v3.server; import org.apache.skywalking.apm.agent.core.context.trace.AbstractTracingSpan; diff --git a/apm-sniffer/apm-sdk-plugin/resteasy-plugin/resteasy-server-3.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/resteasy/v3/server/AsynchronousDeliveryInterceptorTest.java b/apm-sniffer/apm-sdk-plugin/resteasy-plugin/resteasy-server-3.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/resteasy/v3/server/AsynchronousDeliveryInterceptorTest.java index 71e3bab71108..7766812f349f 100644 --- a/apm-sniffer/apm-sdk-plugin/resteasy-plugin/resteasy-server-3.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/resteasy/v3/server/AsynchronousDeliveryInterceptorTest.java +++ b/apm-sniffer/apm-sdk-plugin/resteasy-plugin/resteasy-server-3.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/resteasy/v3/server/AsynchronousDeliveryInterceptorTest.java @@ -1,3 +1,21 @@ +/* + * 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.resteasy.v3.server; import org.apache.skywalking.apm.agent.core.context.trace.AbstractTracingSpan; diff --git a/apm-sniffer/apm-sdk-plugin/resteasy-plugin/resteasy-server-3.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/resteasy/v3/server/SynchronousDispatcherInterceptorTest.java b/apm-sniffer/apm-sdk-plugin/resteasy-plugin/resteasy-server-3.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/resteasy/v3/server/SynchronousDispatcherInterceptorTest.java index de8e112beec8..e583e0f4f79b 100644 --- a/apm-sniffer/apm-sdk-plugin/resteasy-plugin/resteasy-server-3.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/resteasy/v3/server/SynchronousDispatcherInterceptorTest.java +++ b/apm-sniffer/apm-sdk-plugin/resteasy-plugin/resteasy-server-3.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/resteasy/v3/server/SynchronousDispatcherInterceptorTest.java @@ -1,3 +1,21 @@ +/* + * 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.resteasy.v3.server; import org.apache.skywalking.apm.agent.core.conf.Config; From 89b805f09b7d762daf308b3eab7415df20582f06 Mon Sep 17 00:00:00 2001 From: yanfch Date: Tue, 14 May 2019 21:24:45 +0800 Subject: [PATCH 04/10] fix(agent sdk): fix file license --- .../resteasy-server-3.x-plugin/pom.xml | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/apm-sniffer/apm-sdk-plugin/resteasy-plugin/resteasy-server-3.x-plugin/pom.xml b/apm-sniffer/apm-sdk-plugin/resteasy-plugin/resteasy-server-3.x-plugin/pom.xml index 8c4eef981596..94756fd65840 100644 --- a/apm-sniffer/apm-sdk-plugin/resteasy-plugin/resteasy-server-3.x-plugin/pom.xml +++ b/apm-sniffer/apm-sdk-plugin/resteasy-plugin/resteasy-server-3.x-plugin/pom.xml @@ -1,4 +1,21 @@ + From 2b38dc0e4b88fd9f9a609d6e138ea935be43d7e5 Mon Sep 17 00:00:00 2001 From: yanfch Date: Tue, 14 May 2019 21:42:39 +0800 Subject: [PATCH 05/10] docs(agent sdk): add supported list --- docs/en/setup/service-agent/java-agent/Supported-list.md | 1 + 1 file changed, 1 insertion(+) 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 6621fbd941aa..911210f19f17 100644 --- a/docs/en/setup/service-agent/java-agent/Supported-list.md +++ b/docs/en/setup/service-agent/java-agent/Supported-list.md @@ -11,6 +11,7 @@ * [Jetty Server](http://www.eclipse.org/jetty/) 9 * [Spring Webflux](https://docs.spring.io/spring/docs/current/spring-framework-reference/web-reactive.html) 5.x * [Undertow](http://undertow.io/) 2.0.0.Final -> 2.0.13.Final + * [RESTEasy](https://resteasy.github.io/) 3.1.0.Final -> 3.7.0.Final * HTTP Client * [Feign](https://github.com/OpenFeign/feign) 9.x * [Netflix Spring Cloud Feign](https://github.com/spring-cloud/spring-cloud-netflix/tree/master/spring-cloud-starter-feign) 1.1.x, 1.2.x, 1.3.x From 2803cd9101214d48ae2160e46dc815e4f660fed0 Mon Sep 17 00:00:00 2001 From: yanfch Date: Wed, 15 May 2019 09:28:39 +0800 Subject: [PATCH 06/10] fix(agent sdk): fix file license --- .../apm-sdk-plugin/resteasy-plugin/pom.xml | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/apm-sniffer/apm-sdk-plugin/resteasy-plugin/pom.xml b/apm-sniffer/apm-sdk-plugin/resteasy-plugin/pom.xml index 46be6584d578..75862ebccc9a 100644 --- a/apm-sniffer/apm-sdk-plugin/resteasy-plugin/pom.xml +++ b/apm-sniffer/apm-sdk-plugin/resteasy-plugin/pom.xml @@ -1,4 +1,21 @@ + From 13ce4d5c69e0a2ae64a004948f8bf3a577e8dc8c Mon Sep 17 00:00:00 2001 From: yanfch Date: Wed, 15 May 2019 11:54:12 +0800 Subject: [PATCH 07/10] fix(agent sdk): fix response error tag --- .../AsynchronousDeliveryInterceptor.java | 10 +++++- .../SynchronousDispatcherInterceptor.java | 33 +++++++++++-------- 2 files changed, 28 insertions(+), 15 deletions(-) diff --git a/apm-sniffer/apm-sdk-plugin/resteasy-plugin/resteasy-server-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/resteasy/v3/server/AsynchronousDeliveryInterceptor.java b/apm-sniffer/apm-sdk-plugin/resteasy-plugin/resteasy-server-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/resteasy/v3/server/AsynchronousDeliveryInterceptor.java index 4e79e889e61a..89c49fac9a3c 100644 --- a/apm-sniffer/apm-sdk-plugin/resteasy-plugin/resteasy-server-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/resteasy/v3/server/AsynchronousDeliveryInterceptor.java +++ b/apm-sniffer/apm-sdk-plugin/resteasy-plugin/resteasy-server-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/resteasy/v3/server/AsynchronousDeliveryInterceptor.java @@ -18,10 +18,12 @@ package org.apache.skywalking.apm.plugin.resteasy.v3.server; +import org.apache.skywalking.apm.agent.core.context.tag.Tags; import org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan; 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 org.jboss.resteasy.spi.HttpResponse; import java.lang.reflect.Method; @@ -38,7 +40,13 @@ public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allAr @Override public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, Object ret) throws Throwable { - ((AbstractSpan) objInst.getSkyWalkingDynamicField()).asyncFinish(); + HttpResponse response = (HttpResponse) allArguments[1]; + AbstractSpan span = (AbstractSpan) objInst.getSkyWalkingDynamicField(); + if (response.getStatus() >= 400) { + span.errorOccurred(); + Tags.STATUS_CODE.set(span, Integer.toString(response.getStatus())); + } + span.asyncFinish(); return ret; } diff --git a/apm-sniffer/apm-sdk-plugin/resteasy-plugin/resteasy-server-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/resteasy/v3/server/SynchronousDispatcherInterceptor.java b/apm-sniffer/apm-sdk-plugin/resteasy-plugin/resteasy-server-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/resteasy/v3/server/SynchronousDispatcherInterceptor.java index e115c9b0c786..bd342378449d 100644 --- a/apm-sniffer/apm-sdk-plugin/resteasy-plugin/resteasy-server-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/resteasy/v3/server/SynchronousDispatcherInterceptor.java +++ b/apm-sniffer/apm-sdk-plugin/resteasy-plugin/resteasy-server-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/resteasy/v3/server/SynchronousDispatcherInterceptor.java @@ -29,6 +29,7 @@ import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; import org.apache.skywalking.apm.network.trace.component.ComponentsDefine; import org.jboss.resteasy.spi.HttpRequest; +import org.jboss.resteasy.spi.HttpResponse; import java.lang.reflect.Method; @@ -41,27 +42,31 @@ public class SynchronousDispatcherInterceptor implements InstanceMethodsAroundIn public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, MethodInterceptResult result) throws Throwable { HttpRequest request = (HttpRequest) allArguments[0]; - if (request != null) { - ContextCarrier contextCarrier = new ContextCarrier(); - CarrierItem next = contextCarrier.items(); - while (next.hasNext()) { - next = next.next(); - next.setHeadValue(request.getHttpHeaders().getHeaderString(next.getHeadKey())); - } - AbstractSpan span = ContextManager.createEntrySpan(request.getUri().getPath(), contextCarrier); - Tags.URL.set(span, request.getUri().getRequestUri().toString()); - Tags.HTTP.METHOD.set(span, request.getHttpMethod()); - span.setComponent(ComponentsDefine.RESTEASY); - SpanLayer.asHttp(span); - - objInst.setSkyWalkingDynamicField(span); + ContextCarrier contextCarrier = new ContextCarrier(); + CarrierItem next = contextCarrier.items(); + while (next.hasNext()) { + next = next.next(); + next.setHeadValue(request.getHttpHeaders().getHeaderString(next.getHeadKey())); } + + AbstractSpan span = ContextManager.createEntrySpan(request.getUri().getPath(), contextCarrier); + Tags.URL.set(span, request.getUri().getRequestUri().toString()); + Tags.HTTP.METHOD.set(span, request.getHttpMethod()); + span.setComponent(ComponentsDefine.RESTEASY); + SpanLayer.asHttp(span); + objInst.setSkyWalkingDynamicField(span); } @Override public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, Object ret) throws Throwable { + HttpResponse response = (HttpResponse) allArguments[1]; + AbstractSpan span = ContextManager.activeSpan(); + if (response.getStatus() >= 400) { + span.errorOccurred(); + Tags.STATUS_CODE.set(span, Integer.toString(response.getStatus())); + } ContextManager.stopSpan(); return ret; } From 043a21db7c59d0e667eabc45342737636724db26 Mon Sep 17 00:00:00 2001 From: yanfch Date: Wed, 15 May 2019 23:35:10 +0800 Subject: [PATCH 08/10] fix(agent sdk): fix --- .../server-core/src/test/resources/component-libraries.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/oap-server/server-core/src/test/resources/component-libraries.yml b/oap-server/server-core/src/test/resources/component-libraries.yml index ab47b7afa6db..d216b6b7fad7 100644 --- a/oap-server/server-core/src/test/resources/component-libraries.yml +++ b/oap-server/server-core/src/test/resources/component-libraries.yml @@ -193,7 +193,7 @@ ShardingSphere: id: 60 languages: Java RESTEasy: - id: 60 + id: 61 languages: Java # .NET/.NET Core components From 7b0c96d8647dfed98f2c0c3f891b044e37da4de8 Mon Sep 17 00:00:00 2001 From: yanfch Date: Fri, 17 May 2019 23:16:03 +0800 Subject: [PATCH 09/10] fix(agent sdk): adapter 3.5+ --- .../server/define/SynchronousDispatcherInstrumentation.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apm-sniffer/apm-sdk-plugin/resteasy-plugin/resteasy-server-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/resteasy/v3/server/define/SynchronousDispatcherInstrumentation.java b/apm-sniffer/apm-sdk-plugin/resteasy-plugin/resteasy-server-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/resteasy/v3/server/define/SynchronousDispatcherInstrumentation.java index 3ed012de3a2b..8344c0ea4caa 100644 --- a/apm-sniffer/apm-sdk-plugin/resteasy-plugin/resteasy-server-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/resteasy/v3/server/define/SynchronousDispatcherInstrumentation.java +++ b/apm-sniffer/apm-sdk-plugin/resteasy-plugin/resteasy-server-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/resteasy/v3/server/define/SynchronousDispatcherInstrumentation.java @@ -85,7 +85,7 @@ public boolean isOverrideArgs() { new InstanceMethodsInterceptPoint() { @Override public ElementMatcher getMethodsMatcher() { - return named("asynchronousDelivery").and(takesArguments(3)); + return named("asynchronousDelivery"); } @Override @@ -101,7 +101,7 @@ public boolean isOverrideArgs() { new InstanceMethodsInterceptPoint() { @Override public ElementMatcher getMethodsMatcher() { - return named("asynchronousExceptionDelivery").and(takesArguments(3)); + return named("asynchronousExceptionDelivery"); } @Override From 200c27d95ea41d3cbe7d77346a94da5525f9d224 Mon Sep 17 00:00:00 2001 From: yanfch Date: Wed, 22 May 2019 10:29:35 +0800 Subject: [PATCH 10/10] fix(agent sdk): remove unreasonable async handling --- ...nchronousDeliveryExceptionInterceptor.java | 51 ----- .../AsynchronousDeliveryInterceptor.java | 58 ------ ...ynchronousResponseInjectorInterceptor.java | 49 ----- .../SynchronousDispatcherInterceptor.java | 11 +- ...ronousResponseInjectorInstrumentation.java | 71 ------- .../SynchronousDispatcherInstrumentation.java | 35 ---- .../src/main/resources/skywalking-plugin.def | 3 +- .../AsynchronousDeliveryInterceptorTest.java | 178 ------------------ 8 files changed, 10 insertions(+), 446 deletions(-) delete mode 100644 apm-sniffer/apm-sdk-plugin/resteasy-plugin/resteasy-server-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/resteasy/v3/server/AsynchronousDeliveryExceptionInterceptor.java delete mode 100644 apm-sniffer/apm-sdk-plugin/resteasy-plugin/resteasy-server-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/resteasy/v3/server/AsynchronousDeliveryInterceptor.java delete mode 100644 apm-sniffer/apm-sdk-plugin/resteasy-plugin/resteasy-server-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/resteasy/v3/server/AsynchronousResponseInjectorInterceptor.java delete mode 100644 apm-sniffer/apm-sdk-plugin/resteasy-plugin/resteasy-server-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/resteasy/v3/server/define/AsynchronousResponseInjectorInstrumentation.java delete mode 100644 apm-sniffer/apm-sdk-plugin/resteasy-plugin/resteasy-server-3.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/resteasy/v3/server/AsynchronousDeliveryInterceptorTest.java diff --git a/apm-sniffer/apm-sdk-plugin/resteasy-plugin/resteasy-server-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/resteasy/v3/server/AsynchronousDeliveryExceptionInterceptor.java b/apm-sniffer/apm-sdk-plugin/resteasy-plugin/resteasy-server-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/resteasy/v3/server/AsynchronousDeliveryExceptionInterceptor.java deleted file mode 100644 index 20ad2a2cb716..000000000000 --- a/apm-sniffer/apm-sdk-plugin/resteasy-plugin/resteasy-server-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/resteasy/v3/server/AsynchronousDeliveryExceptionInterceptor.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * 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.resteasy.v3.server; - -import org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan; -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; - -/** - * @author yan-fucheng - */ -public class AsynchronousDeliveryExceptionInterceptor implements InstanceMethodsAroundInterceptor { - - @Override - public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, - MethodInterceptResult result) throws Throwable { - ((AbstractSpan) objInst.getSkyWalkingDynamicField()).errorOccurred().log((Throwable) allArguments[2]); - } - - @Override - public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, - Object ret) throws Throwable { - ((AbstractSpan) objInst.getSkyWalkingDynamicField()).asyncFinish(); - return ret; - } - - @Override - public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, - Class[] argumentsTypes, Throwable t) { - ((AbstractSpan) objInst.getSkyWalkingDynamicField()).errorOccurred().log(t); - } -} diff --git a/apm-sniffer/apm-sdk-plugin/resteasy-plugin/resteasy-server-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/resteasy/v3/server/AsynchronousDeliveryInterceptor.java b/apm-sniffer/apm-sdk-plugin/resteasy-plugin/resteasy-server-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/resteasy/v3/server/AsynchronousDeliveryInterceptor.java deleted file mode 100644 index 89c49fac9a3c..000000000000 --- a/apm-sniffer/apm-sdk-plugin/resteasy-plugin/resteasy-server-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/resteasy/v3/server/AsynchronousDeliveryInterceptor.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * 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.resteasy.v3.server; - -import org.apache.skywalking.apm.agent.core.context.tag.Tags; -import org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan; -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 org.jboss.resteasy.spi.HttpResponse; - -import java.lang.reflect.Method; - -/** - * @author yan-fucheng - */ -public class AsynchronousDeliveryInterceptor implements InstanceMethodsAroundInterceptor { - - @Override - public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, - MethodInterceptResult result) throws Throwable { - } - - @Override - public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, - Object ret) throws Throwable { - HttpResponse response = (HttpResponse) allArguments[1]; - AbstractSpan span = (AbstractSpan) objInst.getSkyWalkingDynamicField(); - if (response.getStatus() >= 400) { - span.errorOccurred(); - Tags.STATUS_CODE.set(span, Integer.toString(response.getStatus())); - } - span.asyncFinish(); - return ret; - } - - @Override - public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, - Class[] argumentsTypes, Throwable t) { - ((AbstractSpan) objInst.getSkyWalkingDynamicField()).errorOccurred().log(t); - } -} diff --git a/apm-sniffer/apm-sdk-plugin/resteasy-plugin/resteasy-server-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/resteasy/v3/server/AsynchronousResponseInjectorInterceptor.java b/apm-sniffer/apm-sdk-plugin/resteasy-plugin/resteasy-server-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/resteasy/v3/server/AsynchronousResponseInjectorInterceptor.java deleted file mode 100644 index cb585b3f3f1d..000000000000 --- a/apm-sniffer/apm-sdk-plugin/resteasy-plugin/resteasy-server-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/resteasy/v3/server/AsynchronousResponseInjectorInterceptor.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * 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.resteasy.v3.server; - -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; - -/** - * @author yan-fucheng - */ -public class AsynchronousResponseInjectorInterceptor implements InstanceMethodsAroundInterceptor { - - @Override - public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, - MethodInterceptResult result) throws Throwable { - ContextManager.activeSpan().prepareForAsync(); - } - - @Override - public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, - Object ret) throws Throwable { - return ret; - } - - @Override - public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, - Class[] argumentsTypes, Throwable t) { - } -} diff --git a/apm-sniffer/apm-sdk-plugin/resteasy-plugin/resteasy-server-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/resteasy/v3/server/SynchronousDispatcherInterceptor.java b/apm-sniffer/apm-sdk-plugin/resteasy-plugin/resteasy-server-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/resteasy/v3/server/SynchronousDispatcherInterceptor.java index bd342378449d..eec967395201 100644 --- a/apm-sniffer/apm-sdk-plugin/resteasy-plugin/resteasy-server-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/resteasy/v3/server/SynchronousDispatcherInterceptor.java +++ b/apm-sniffer/apm-sdk-plugin/resteasy-plugin/resteasy-server-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/resteasy/v3/server/SynchronousDispatcherInterceptor.java @@ -51,11 +51,10 @@ public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allAr } AbstractSpan span = ContextManager.createEntrySpan(request.getUri().getPath(), contextCarrier); - Tags.URL.set(span, request.getUri().getRequestUri().toString()); + Tags.URL.set(span, toPath(request.getUri().getRequestUri().toString())); Tags.HTTP.METHOD.set(span, request.getHttpMethod()); span.setComponent(ComponentsDefine.RESTEASY); SpanLayer.asHttp(span); - objInst.setSkyWalkingDynamicField(span); } @Override @@ -76,4 +75,12 @@ public void handleMethodException(EnhancedInstance objInst, Method method, Objec Class[] argumentsTypes, Throwable t) { ContextManager.activeSpan().errorOccurred().log(t); } + + private static String toPath(String uri) { + if (uri.contains("?")) { + return uri.substring(0, uri.indexOf("?")); + } else { + return uri; + } + } } diff --git a/apm-sniffer/apm-sdk-plugin/resteasy-plugin/resteasy-server-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/resteasy/v3/server/define/AsynchronousResponseInjectorInstrumentation.java b/apm-sniffer/apm-sdk-plugin/resteasy-plugin/resteasy-server-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/resteasy/v3/server/define/AsynchronousResponseInjectorInstrumentation.java deleted file mode 100644 index 9428c204dfce..000000000000 --- a/apm-sniffer/apm-sdk-plugin/resteasy-plugin/resteasy-server-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/resteasy/v3/server/define/AsynchronousResponseInjectorInstrumentation.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * 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.resteasy.v3.server.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; - -import static net.bytebuddy.matcher.ElementMatchers.named; -import static net.bytebuddy.matcher.ElementMatchers.takesArguments; - -/** - * @author yan-fucheng - */ -public class AsynchronousResponseInjectorInstrumentation extends ClassInstanceMethodsEnhancePluginDefine { - - private static final String ENHANCE_CLASS = "org.jboss.resteasy.core.AsynchronousResponseInjector"; - private static final String ASYNC_INJECT_INTERCEPT_CLASS = "org.apache.skywalking.apm.plugin.resteasy.v3.server.AsynchronousResponseInjectorInterceptor"; - - @Override - protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() { - return null; - } - - @Override - protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { - return new InstanceMethodsInterceptPoint[] { - new InstanceMethodsInterceptPoint() { - @Override - public ElementMatcher getMethodsMatcher() { - return named("inject").and(takesArguments(2)); - } - - @Override - public String getMethodsInterceptor() { - return ASYNC_INJECT_INTERCEPT_CLASS; - } - - @Override - public boolean isOverrideArgs() { - return false; - } - } - }; - } - - @Override - protected ClassMatch enhanceClass() { - return NameMatch.byName(ENHANCE_CLASS); - } -} diff --git a/apm-sniffer/apm-sdk-plugin/resteasy-plugin/resteasy-server-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/resteasy/v3/server/define/SynchronousDispatcherInstrumentation.java b/apm-sniffer/apm-sdk-plugin/resteasy-plugin/resteasy-server-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/resteasy/v3/server/define/SynchronousDispatcherInstrumentation.java index 8344c0ea4caa..f9678b476a2d 100644 --- a/apm-sniffer/apm-sdk-plugin/resteasy-plugin/resteasy-server-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/resteasy/v3/server/define/SynchronousDispatcherInstrumentation.java +++ b/apm-sniffer/apm-sdk-plugin/resteasy-plugin/resteasy-server-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/resteasy/v3/server/define/SynchronousDispatcherInstrumentation.java @@ -39,9 +39,6 @@ public class SynchronousDispatcherInstrumentation extends ClassInstanceMethodsEn private static final String INVOKE_INTERCEPT_CLASS = "org.apache.skywalking.apm.plugin.resteasy.v3.server.SynchronousDispatcherInterceptor"; private static final String INVOKE_EXCEPTION_INTERCEPT_CLASS = "org.apache.skywalking.apm.plugin.resteasy.v3.server.SynchronousDispatcherExceptionInterceptor"; - private static final String ASYNC_DELIVERY_INTERCEPT_CLASS = "org.apache.skywalking.apm.plugin.resteasy.v3.server.AsynchronousDeliveryInterceptor"; - private static final String ASYNC_DELIVERY_EXCEPTION_INTERCEPT_CLASS = "org.apache.skywalking.apm.plugin.resteasy.v3.server.AsynchronousDeliveryExceptionInterceptor"; - @Override protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() { return null; @@ -77,38 +74,6 @@ public String getMethodsInterceptor() { return INVOKE_EXCEPTION_INTERCEPT_CLASS; } - @Override - public boolean isOverrideArgs() { - return false; - } - }, - new InstanceMethodsInterceptPoint() { - @Override - public ElementMatcher getMethodsMatcher() { - return named("asynchronousDelivery"); - } - - @Override - public String getMethodsInterceptor() { - return ASYNC_DELIVERY_INTERCEPT_CLASS; - } - - @Override - public boolean isOverrideArgs() { - return false; - } - }, - new InstanceMethodsInterceptPoint() { - @Override - public ElementMatcher getMethodsMatcher() { - return named("asynchronousExceptionDelivery"); - } - - @Override - public String getMethodsInterceptor() { - return ASYNC_DELIVERY_EXCEPTION_INTERCEPT_CLASS; - } - @Override public boolean isOverrideArgs() { return false; diff --git a/apm-sniffer/apm-sdk-plugin/resteasy-plugin/resteasy-server-3.x-plugin/src/main/resources/skywalking-plugin.def b/apm-sniffer/apm-sdk-plugin/resteasy-plugin/resteasy-server-3.x-plugin/src/main/resources/skywalking-plugin.def index 13c2429aac1d..164c991bc2b5 100644 --- a/apm-sniffer/apm-sdk-plugin/resteasy-plugin/resteasy-server-3.x-plugin/src/main/resources/skywalking-plugin.def +++ b/apm-sniffer/apm-sdk-plugin/resteasy-plugin/resteasy-server-3.x-plugin/src/main/resources/skywalking-plugin.def @@ -14,5 +14,4 @@ # See the License for the specific language governing permissions and # limitations under the License. -resteasy-server-3.x=org.apache.skywalking.apm.plugin.resteasy.v3.server.define.SynchronousDispatcherInstrumentation -resteasy-server-3.x=org.apache.skywalking.apm.plugin.resteasy.v3.server.define.AsynchronousResponseInjectorInstrumentation \ No newline at end of file +resteasy-server-3.x=org.apache.skywalking.apm.plugin.resteasy.v3.server.define.SynchronousDispatcherInstrumentation \ No newline at end of file diff --git a/apm-sniffer/apm-sdk-plugin/resteasy-plugin/resteasy-server-3.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/resteasy/v3/server/AsynchronousDeliveryInterceptorTest.java b/apm-sniffer/apm-sdk-plugin/resteasy-plugin/resteasy-server-3.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/resteasy/v3/server/AsynchronousDeliveryInterceptorTest.java deleted file mode 100644 index 7766812f349f..000000000000 --- a/apm-sniffer/apm-sdk-plugin/resteasy-plugin/resteasy-server-3.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/resteasy/v3/server/AsynchronousDeliveryInterceptorTest.java +++ /dev/null @@ -1,178 +0,0 @@ -/* - * 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.resteasy.v3.server; - -import org.apache.skywalking.apm.agent.core.context.trace.AbstractTracingSpan; -import org.apache.skywalking.apm.agent.core.context.trace.LogDataEntity; -import org.apache.skywalking.apm.agent.core.context.trace.TraceSegment; -import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; -import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; -import org.apache.skywalking.apm.agent.test.helper.SegmentHelper; -import org.apache.skywalking.apm.agent.test.helper.SpanHelper; -import org.apache.skywalking.apm.agent.test.tools.*; -import org.jboss.resteasy.core.ResourceInvoker; -import org.jboss.resteasy.specimpl.MultivaluedMapImpl; -import org.jboss.resteasy.specimpl.ResteasyHttpHeaders; -import org.jboss.resteasy.spi.HttpRequest; -import org.jboss.resteasy.spi.HttpResponse; -import org.jboss.resteasy.spi.ResteasyAsynchronousContext; -import org.jboss.resteasy.spi.ResteasyUriInfo; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mock; -import org.powermock.modules.junit4.PowerMockRunner; -import org.powermock.modules.junit4.PowerMockRunnerDelegate; - -import java.net.URI; -import java.net.URISyntaxException; -import java.util.List; - -import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.mockito.Mockito.when; - -/** - * @author yan-fucheng - */ -@RunWith(PowerMockRunner.class) -@PowerMockRunnerDelegate(TracingSegmentRunner.class) -public class AsynchronousDeliveryInterceptorTest { - - private SynchronousDispatcherInterceptor synchronousDispatcherInterceptor; - private SynchronousDispatcherExceptionInterceptor synchronousDispatcherExceptionInterceptor; - - private AsynchronousResponseInjectorInterceptor asynchronousResponseInjectorInterceptor; - private AsynchronousDeliveryInterceptor asynchronousDeliveryInterceptor; - private AsynchronousDeliveryExceptionInterceptor asynchronousDeliveryExceptionInterceptor; - - @SegmentStoragePoint - private SegmentStorage segmentStorage; - - @Rule - public AgentServiceRule serviceRule = new AgentServiceRule(); - - @Mock - HttpRequest request; - - @Mock - HttpResponse response; - - @Mock - ResourceInvoker resourceInvoker; - - @Mock - private MethodInterceptResult methodInterceptResult; - - @Mock - private ResteasyAsynchronousContext resteasyAsynchronousContext; - - private EnhancedInstance enhancedInstance = new EnhancedInstance() { - - private Object object; - - @Override - public Object getSkyWalkingDynamicField() { - return object; - } - - @Override public void setSkyWalkingDynamicField(Object value) { - this.object = value; - } - }; - - private Object[] arguments; - private Class[] argumentType; - - private Object[] exceptionArguments; - private Class[] exceptionArgumentType; - - @Before - public void setup() throws URISyntaxException { - synchronousDispatcherInterceptor = new SynchronousDispatcherInterceptor(); - synchronousDispatcherExceptionInterceptor = new SynchronousDispatcherExceptionInterceptor(); - - asynchronousResponseInjectorInterceptor = new AsynchronousResponseInjectorInterceptor(); - asynchronousDeliveryInterceptor = new AsynchronousDeliveryInterceptor(); - asynchronousDeliveryExceptionInterceptor = new AsynchronousDeliveryExceptionInterceptor(); - - when(request.getUri()).thenReturn(new ResteasyUriInfo(new URI("http://localhost:8080/test/testRequestURL"))); - when(request.getHttpHeaders()).thenReturn(new ResteasyHttpHeaders(new MultivaluedMapImpl())); - when(response.getStatus()).thenReturn(200); - when(request.getAsyncContext()).thenReturn(resteasyAsynchronousContext); - when(request.getAsyncContext().isSuspended()).thenReturn(true); - arguments = new Object[] {request, response, resourceInvoker}; - argumentType = new Class[] {request.getClass(), response.getClass(), resourceInvoker.getClass()}; - - exceptionArguments = new Object[] {request, response, new RuntimeException()}; - exceptionArgumentType = new Class[] {request.getClass(), response.getClass(), new RuntimeException().getClass()}; - } - - @Test - public void testWithoutSerializedContextData() throws Throwable { - synchronousDispatcherInterceptor.beforeMethod(enhancedInstance, null, arguments, argumentType, methodInterceptResult); - asynchronousResponseInjectorInterceptor.beforeMethod(enhancedInstance, null, new Object[] {request, response}, argumentType, methodInterceptResult); - synchronousDispatcherInterceptor.afterMethod(enhancedInstance, null, arguments, argumentType, null); - asynchronousDeliveryInterceptor.afterMethod(enhancedInstance, null, arguments, argumentType, null); - - assertThat(segmentStorage.getTraceSegments().size(), is(1)); - TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0); - List spans = SegmentHelper.getSpans(traceSegment); - AssertTools.assertHttpSpan(spans.get(0)); - } - - @Test - public void testWithMainThreadOccurException() throws Throwable { - synchronousDispatcherInterceptor.beforeMethod(enhancedInstance, null, arguments, argumentType, methodInterceptResult); - asynchronousResponseInjectorInterceptor.beforeMethod(enhancedInstance, null, new Object[] {request, response}, argumentType, methodInterceptResult); - asynchronousDeliveryExceptionInterceptor.beforeMethod(enhancedInstance, null, exceptionArguments, exceptionArgumentType, null); - synchronousDispatcherExceptionInterceptor.beforeMethod(enhancedInstance, null, exceptionArguments, exceptionArgumentType, null); - asynchronousDeliveryExceptionInterceptor.afterMethod(enhancedInstance, null, exceptionArguments, exceptionArgumentType, null); - synchronousDispatcherInterceptor.afterMethod(enhancedInstance, null, arguments, argumentType, null); - - assertThat(segmentStorage.getTraceSegments().size(), is(1)); - TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0); - List spans = SegmentHelper.getSpans(traceSegment); - - AssertTools.assertHttpSpan(spans.get(0)); - List logDataEntities = SpanHelper.getLogs(spans.get(0)); - assertThat(logDataEntities.size(), is(1)); - SpanAssert.assertException(logDataEntities.get(0), RuntimeException.class); - } - - @Test - public void testWithAsyncThreadOccurException() throws Throwable { - synchronousDispatcherInterceptor.beforeMethod(enhancedInstance, null, arguments, argumentType, methodInterceptResult); - asynchronousResponseInjectorInterceptor.beforeMethod(enhancedInstance, null, new Object[] {request, response}, argumentType, methodInterceptResult); - synchronousDispatcherInterceptor.afterMethod(enhancedInstance, null, arguments, argumentType, null); - asynchronousDeliveryExceptionInterceptor.beforeMethod(enhancedInstance, null, exceptionArguments, exceptionArgumentType, null); - synchronousDispatcherExceptionInterceptor.beforeMethod(enhancedInstance, null, exceptionArguments, exceptionArgumentType, null); - asynchronousDeliveryExceptionInterceptor.afterMethod(enhancedInstance, null, exceptionArguments, exceptionArgumentType, null); - - assertThat(segmentStorage.getTraceSegments().size(), is(1)); - TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0); - List spans = SegmentHelper.getSpans(traceSegment); - - AssertTools.assertHttpSpan(spans.get(0)); - List logDataEntities = SpanHelper.getLogs(spans.get(0)); - assertThat(logDataEntities.size(), is(1)); - SpanAssert.assertException(logDataEntities.get(0), RuntimeException.class); - } -}