From 68376fb50504f02a72b85ff211c96be62b01f134 Mon Sep 17 00:00:00 2001 From: Brandon Fergerson Date: Mon, 11 Mar 2019 22:14:19 -0600 Subject: [PATCH] vertx plugin work --- .../trace/component/ComponentsDefine.java | 5 +- apm-sniffer/apm-sdk-plugin/pom.xml | 1 + .../apm-sdk-plugin/vertx-3.x-plugin/pom.xml | 51 ++++++++++++++ ...equestImplDoHandleResponseInterceptor.java | 51 ++++++++++++++ .../HttpClientRequestImplEndInterceptor.java | 65 +++++++++++++++++ ...HttpServerRequestImplDoEndInterceptor.java | 66 ++++++++++++++++++ .../HttpServerResponseImplEndInterceptor.java | 59 ++++++++++++++++ ...stImplDoHandleResponseInstrumentation.java | 69 +++++++++++++++++++ ...tpClientRequestImplEndInstrumentation.java | 69 +++++++++++++++++++ ...ServerRequestImplDoEndInstrumentation.java | 69 +++++++++++++++++++ ...pServerResponseImplEndInstrumentation.java | 69 +++++++++++++++++++ .../src/main/resources/skywalking-plugin.def | 20 ++++++ docker/config/component-libraries.yml | 4 +- .../test/resources/component-libraries.yml | 3 + .../main/resources/component-libraries.yml | 4 +- 15 files changed, 602 insertions(+), 3 deletions(-) create mode 100644 apm-sniffer/apm-sdk-plugin/vertx-3.x-plugin/pom.xml create mode 100644 apm-sniffer/apm-sdk-plugin/vertx-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/vertx3/HttpClientRequestImplDoHandleResponseInterceptor.java create mode 100644 apm-sniffer/apm-sdk-plugin/vertx-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/vertx3/HttpClientRequestImplEndInterceptor.java create mode 100644 apm-sniffer/apm-sdk-plugin/vertx-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/vertx3/HttpServerRequestImplDoEndInterceptor.java create mode 100644 apm-sniffer/apm-sdk-plugin/vertx-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/vertx3/HttpServerResponseImplEndInterceptor.java create mode 100644 apm-sniffer/apm-sdk-plugin/vertx-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/vertx3/define/HttpClientRequestImplDoHandleResponseInstrumentation.java create mode 100644 apm-sniffer/apm-sdk-plugin/vertx-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/vertx3/define/HttpClientRequestImplEndInstrumentation.java create mode 100644 apm-sniffer/apm-sdk-plugin/vertx-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/vertx3/define/HttpServerRequestImplDoEndInstrumentation.java create mode 100644 apm-sniffer/apm-sdk-plugin/vertx-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/vertx3/define/HttpServerResponseImplEndInstrumentation.java create mode 100644 apm-sniffer/apm-sdk-plugin/vertx-3.x-plugin/src/main/resources/skywalking-plugin.def 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 ce9cb5f62..2a3116148 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 @@ -114,6 +114,8 @@ public class ComponentsDefine { public static final OfficialComponent ZOOKEEPER = new OfficialComponent(58, "Zookeeper"); + public static final OfficialComponent VERTX = new OfficialComponent(59, "Vert.x"); + private static ComponentsDefine INSTANCE = new ComponentsDefine(); private String[] components; @@ -123,7 +125,7 @@ public class ComponentsDefine { } public ComponentsDefine() { - components = new String[59]; + components = new String[60]; addComponent(TOMCAT); addComponent(HTTPCLIENT); addComponent(DUBBO); @@ -167,6 +169,7 @@ public class ComponentsDefine { addComponent(REDISSON); addComponent(LETTUCE); addComponent(ZOOKEEPER); + addComponent(VERTX); } private void addComponent(OfficialComponent component) { diff --git a/apm-sniffer/apm-sdk-plugin/pom.xml b/apm-sniffer/apm-sdk-plugin/pom.xml index 326e9034a..74db0868c 100644 --- a/apm-sniffer/apm-sdk-plugin/pom.xml +++ b/apm-sniffer/apm-sdk-plugin/pom.xml @@ -64,6 +64,7 @@ rabbitmq-5.x-plugin dubbo-conflict-patch canal-1.x-plugin + vertx-3.x-plugin pom diff --git a/apm-sniffer/apm-sdk-plugin/vertx-3.x-plugin/pom.xml b/apm-sniffer/apm-sdk-plugin/vertx-3.x-plugin/pom.xml new file mode 100644 index 000000000..7946e70c8 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/vertx-3.x-plugin/pom.xml @@ -0,0 +1,51 @@ + + + + + apm-sdk-plugin + org.apache.skywalking + 6.1.0-SNAPSHOT + + 4.0.0 + + apm-vertx-3.x-plugin + jar + + vertx-3.x-plugin + http://maven.apache.org + + + 3.6.3 + + + + + io.vertx + vertx-core + ${vertx.version} + provided + + + io.vertx + vertx-web + ${vertx.version} + provided + + + diff --git a/apm-sniffer/apm-sdk-plugin/vertx-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/vertx3/HttpClientRequestImplDoHandleResponseInterceptor.java b/apm-sniffer/apm-sdk-plugin/vertx-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/vertx3/HttpClientRequestImplDoHandleResponseInterceptor.java new file mode 100644 index 000000000..0ee78bdb2 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/vertx-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/vertx3/HttpClientRequestImplDoHandleResponseInterceptor.java @@ -0,0 +1,51 @@ +/* + * 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.vertx3; + +import org.apache.skywalking.apm.agent.core.context.ContextManager; +import org.apache.skywalking.apm.agent.core.context.ContextSnapshot; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; + +import java.lang.reflect.Method; + +public class HttpClientRequestImplDoHandleResponseInterceptor implements InstanceMethodsAroundInterceptor { + + @Override + @SuppressWarnings("unchecked") + public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, + MethodInterceptResult result) throws Throwable { + ContextSnapshot contextSnapshot = (ContextSnapshot) objInst.getSkyWalkingDynamicField(); + ContextManager.createLocalSpan("HttpClientRequestImplDoHandleResponseInterceptor-" + contextSnapshot.getParentOperationName()); + ContextManager.continued((ContextSnapshot) objInst.getSkyWalkingDynamicField()); + } + + @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/vertx-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/vertx3/HttpClientRequestImplEndInterceptor.java b/apm-sniffer/apm-sdk-plugin/vertx-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/vertx3/HttpClientRequestImplEndInterceptor.java new file mode 100644 index 000000000..92e74c293 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/vertx-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/vertx3/HttpClientRequestImplEndInterceptor.java @@ -0,0 +1,65 @@ +/* + * 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.vertx3; + +import io.vertx.core.http.HttpClientRequest; +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.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 java.lang.reflect.Method; + +public class HttpClientRequestImplEndInterceptor implements InstanceMethodsAroundInterceptor { + + @Override + @SuppressWarnings("unchecked") + public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, + MethodInterceptResult result) throws Throwable { + HttpClientRequest request = (HttpClientRequest) objInst; + ContextCarrier contextCarrier = new ContextCarrier(); + AbstractSpan span = ContextManager.createExitSpan(request.path(), contextCarrier, request.path()); + span.setComponent(ComponentsDefine.VERTX); + SpanLayer.asRPCFramework(span); + + CarrierItem next = contextCarrier.items(); + while (next.hasNext()) { + next = next.next(); + request.headers().add(next.getHeadKey(), next.getHeadValue()); + } + objInst.setSkyWalkingDynamicField(ContextManager.capture()); + } + + @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/vertx-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/vertx3/HttpServerRequestImplDoEndInterceptor.java b/apm-sniffer/apm-sdk-plugin/vertx-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/vertx3/HttpServerRequestImplDoEndInterceptor.java new file mode 100644 index 000000000..0c9695f69 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/vertx-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/vertx3/HttpServerRequestImplDoEndInterceptor.java @@ -0,0 +1,66 @@ +/* + * 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.vertx3; + +import io.vertx.core.http.HttpServerRequest; +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.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 java.lang.reflect.Method; + +public class HttpServerRequestImplDoEndInterceptor implements InstanceMethodsAroundInterceptor { + + @Override + @SuppressWarnings("unchecked") + public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, + MethodInterceptResult result) throws Throwable { + HttpServerRequest request = (HttpServerRequest) objInst; + ContextCarrier contextCarrier = new ContextCarrier(); + CarrierItem next = contextCarrier.items(); + while (next.hasNext()) { + next = next.next(); + next.setHeadValue(request.headers().get(next.getHeadKey())); + request.headers().remove(next.getHeadKey()); + } + + AbstractSpan span = ContextManager.createEntrySpan(request.path(), contextCarrier); + span.setComponent(ComponentsDefine.VERTX); + SpanLayer.asRPCFramework(span); + ((EnhancedInstance) request.response()).setSkyWalkingDynamicField(ContextManager.capture()); + } + + @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/vertx-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/vertx3/HttpServerResponseImplEndInterceptor.java b/apm-sniffer/apm-sdk-plugin/vertx-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/vertx3/HttpServerResponseImplEndInterceptor.java new file mode 100644 index 000000000..1d745de05 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/vertx-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/vertx3/HttpServerResponseImplEndInterceptor.java @@ -0,0 +1,59 @@ +/* + * 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.vertx3; + +import io.vertx.core.buffer.impl.BufferImpl; +import org.apache.skywalking.apm.agent.core.context.ContextManager; +import org.apache.skywalking.apm.agent.core.context.ContextSnapshot; +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.apache.skywalking.apm.network.trace.component.ComponentsDefine; + +import java.lang.reflect.Method; + +public class HttpServerResponseImplEndInterceptor implements InstanceMethodsAroundInterceptor { + + @Override + @SuppressWarnings("unchecked") + public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, + MethodInterceptResult result) throws Throwable { + if (allArguments[0] instanceof BufferImpl) { + ContextSnapshot contextSnapshot = (ContextSnapshot) objInst.getSkyWalkingDynamicField(); + AbstractSpan span = ContextManager.createLocalSpan("HttpServerResponseImplEndInterceptor-" + contextSnapshot.getParentOperationName()); + span.setComponent(ComponentsDefine.VERTX); + ContextManager.continued(contextSnapshot); + } + } + + @Override + public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, + Object ret) throws Throwable { + if (allArguments[0] instanceof BufferImpl) { + 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/vertx-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/vertx3/define/HttpClientRequestImplDoHandleResponseInstrumentation.java b/apm-sniffer/apm-sdk-plugin/vertx-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/vertx3/define/HttpClientRequestImplDoHandleResponseInstrumentation.java new file mode 100644 index 000000000..b6c2bde7d --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/vertx-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/vertx3/define/HttpClientRequestImplDoHandleResponseInstrumentation.java @@ -0,0 +1,69 @@ +/* + * 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.vertx3.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; + +/** + * {@link HttpClientRequestImplDoHandleResponseInstrumentation} enhance the doHandleResponse method + * in io.vertx.core.http.impl.HttpClientRequestImpl class by + * HttpClientRequestImplDoHandleResponseInterceptor class + * + * @author brandon.fergerson + */ +public class HttpClientRequestImplDoHandleResponseInstrumentation extends ClassInstanceMethodsEnhancePluginDefine { + + private static final String ENHANCE_CLASS = "io.vertx.core.http.impl.HttpClientRequestImpl"; + private static final String ENHANCE_METHOD = "doHandleResponse"; + private static final String INTERCEPT_CLASS = "org.apache.skywalking.apm.plugin.vertx3.HttpClientRequestImplDoHandleResponseInterceptor"; + + @Override protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() { + return new ConstructorInterceptPoint[0]; + } + + @Override protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { + return new InstanceMethodsInterceptPoint[] { + new InstanceMethodsInterceptPoint() { + @Override public ElementMatcher getMethodsMatcher() { + return named(ENHANCE_METHOD); + } + + @Override public String getMethodsInterceptor() { + return 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/vertx-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/vertx3/define/HttpClientRequestImplEndInstrumentation.java b/apm-sniffer/apm-sdk-plugin/vertx-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/vertx3/define/HttpClientRequestImplEndInstrumentation.java new file mode 100644 index 000000000..eea87462d --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/vertx-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/vertx3/define/HttpClientRequestImplEndInstrumentation.java @@ -0,0 +1,69 @@ +/* + * 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.vertx3.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; + +/** + * {@link HttpClientRequestImplEndInstrumentation} enhance the end method + * in io.vertx.core.http.impl.HttpClientRequestImpl class by + * HttpClientRequestImplEndInterceptor class + * + * @author brandon.fergerson + */ +public class HttpClientRequestImplEndInstrumentation extends ClassInstanceMethodsEnhancePluginDefine { + + private static final String ENHANCE_CLASS = "io.vertx.core.http.impl.HttpClientRequestImpl"; + private static final String ENHANCE_METHOD = "end"; + private static final String INTERCEPT_CLASS = "org.apache.skywalking.apm.plugin.vertx3.HttpClientRequestImplEndInterceptor"; + + @Override protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() { + return new ConstructorInterceptPoint[0]; + } + + @Override protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { + return new InstanceMethodsInterceptPoint[] { + new InstanceMethodsInterceptPoint() { + @Override public ElementMatcher getMethodsMatcher() { + return named(ENHANCE_METHOD); + } + + @Override public String getMethodsInterceptor() { + return 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/vertx-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/vertx3/define/HttpServerRequestImplDoEndInstrumentation.java b/apm-sniffer/apm-sdk-plugin/vertx-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/vertx3/define/HttpServerRequestImplDoEndInstrumentation.java new file mode 100644 index 000000000..f085e949e --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/vertx-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/vertx3/define/HttpServerRequestImplDoEndInstrumentation.java @@ -0,0 +1,69 @@ +/* + * 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.vertx3.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; + +/** + * {@link HttpServerRequestImplDoEndInstrumentation} enhance the doEnd method + * in io.vertx.core.http.impl.HttpServerRequestImpl class by + * HttpServerRequestImplDoEndInterceptor class + * + * @author brandon.fergerson + */ +public class HttpServerRequestImplDoEndInstrumentation extends ClassInstanceMethodsEnhancePluginDefine { + + private static final String ENHANCE_CLASS = "io.vertx.core.http.impl.HttpServerRequestImpl"; + private static final String ENHANCE_METHOD = "doEnd"; + private static final String INTERCEPT_CLASS = "org.apache.skywalking.apm.plugin.vertx3.HttpServerRequestImplDoEndInterceptor"; + + @Override protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() { + return new ConstructorInterceptPoint[0]; + } + + @Override protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { + return new InstanceMethodsInterceptPoint[] { + new InstanceMethodsInterceptPoint() { + @Override public ElementMatcher getMethodsMatcher() { + return named(ENHANCE_METHOD); + } + + @Override public String getMethodsInterceptor() { + return 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/vertx-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/vertx3/define/HttpServerResponseImplEndInstrumentation.java b/apm-sniffer/apm-sdk-plugin/vertx-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/vertx3/define/HttpServerResponseImplEndInstrumentation.java new file mode 100644 index 000000000..98c15c0cc --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/vertx-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/vertx3/define/HttpServerResponseImplEndInstrumentation.java @@ -0,0 +1,69 @@ +/* + * 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.vertx3.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; + +/** + * {@link HttpServerResponseImplEndInstrumentation} enhance the end method + * in io.vertx.core.http.impl.HttpServerResponseImpl class by + * HttpServerResponseImplEndInterceptor class + * + * @author brandon.fergerson + */ +public class HttpServerResponseImplEndInstrumentation extends ClassInstanceMethodsEnhancePluginDefine { + + private static final String ENHANCE_CLASS = "io.vertx.core.http.impl.HttpServerResponseImpl"; + private static final String ENHANCE_METHOD = "end"; + private static final String INTERCEPT_CLASS = "org.apache.skywalking.apm.plugin.vertx3.HttpServerResponseImplEndInterceptor"; + + @Override protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() { + return new ConstructorInterceptPoint[0]; + } + + @Override protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { + return new InstanceMethodsInterceptPoint[] { + new InstanceMethodsInterceptPoint() { + @Override public ElementMatcher getMethodsMatcher() { + return named(ENHANCE_METHOD); + } + + @Override public String getMethodsInterceptor() { + return 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/vertx-3.x-plugin/src/main/resources/skywalking-plugin.def b/apm-sniffer/apm-sdk-plugin/vertx-3.x-plugin/src/main/resources/skywalking-plugin.def new file mode 100644 index 000000000..72c8c9687 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/vertx-3.x-plugin/src/main/resources/skywalking-plugin.def @@ -0,0 +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. + +vertx-3.x=org.apache.skywalking.apm.plugin.vertx3.define.HttpClientRequestImplDoHandleResponseInstrumentation +vertx-3.x=org.apache.skywalking.apm.plugin.vertx3.define.HttpClientRequestImplEndInstrumentation +vertx-3.x=org.apache.skywalking.apm.plugin.vertx3.define.HttpServerRequestImplDoEndInstrumentation +vertx-3.x=org.apache.skywalking.apm.plugin.vertx3.define.HttpServerResponseImplEndInstrumentation diff --git a/docker/config/component-libraries.yml b/docker/config/component-libraries.yml index ff516c875..01c104ddd 100644 --- a/docker/config/component-libraries.yml +++ b/docker/config/component-libraries.yml @@ -204,7 +204,9 @@ Lettuce: Zookeeper: id: 58 languages: Java - +Vertx: + id: 59 + 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 587c08ba2..6141aeb6b 100644 --- a/oap-server/server-core/src/test/resources/component-libraries.yml +++ b/oap-server/server-core/src/test/resources/component-libraries.yml @@ -186,6 +186,9 @@ Lettuce: Zookeeper: id: 58 languages: Java +Vertx: + id: 59 + languages: Java # .NET/.NET Core components # [3000, 4000) for C#/.NET only 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 3d439fa42..71150e670 100644 --- a/oap-server/server-starter/src/main/resources/component-libraries.yml +++ b/oap-server/server-starter/src/main/resources/component-libraries.yml @@ -204,7 +204,9 @@ Lettuce: Zookeeper: id: 58 languages: Java - +Vertx: + id: 59 + languages: Java # .NET/.NET Core components # [3000, 4000) for C#/.NET only