From 68376fb50504f02a72b85ff211c96be62b01f134 Mon Sep 17 00:00:00 2001 From: Brandon Fergerson Date: Mon, 11 Mar 2019 22:14:19 -0600 Subject: [PATCH 01/12] 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 From 62f21330adb7123d2ec5aa19287a5dcc2266b594 Mon Sep 17 00:00:00 2001 From: Brandon Fergerson Date: Tue, 12 Mar 2019 18:14:44 -0600 Subject: [PATCH 02/12] impl USE_QUALIFIED_NAME_AS_ENDPOINT_NAME --- .../apm/agent/core/conf/Config.java | 14 ++++++++ .../AbstractMethodInterceptor.java | 34 +++++++++++++++---- .../RequestMappingMethodInterceptor.java | 25 +++++++++----- .../v5/RequestMappingMethodInterceptor.java | 25 +++++++++----- .../TraceAnnotationMethodInterceptor.java | 3 +- 5 files changed, 77 insertions(+), 24 deletions(-) diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/conf/Config.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/conf/Config.java index 1791eb6bf..86f294ada 100644 --- a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/conf/Config.java +++ b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/conf/Config.java @@ -163,5 +163,19 @@ public class Config { */ public static boolean TRACE_DSL = false; } + + public static class SpringMVC { + /** + * If true, the fully qualified method name will be used as the endpoint name instead of the request URL, default is false. + */ + public static boolean USE_QUALIFIED_NAME_AS_ENDPOINT_NAME = false; + } + + public static class Toolkit { + /** + * If true, the fully qualified method name will be used as the endpoint name instead of the operation name, default is false. + */ + public static boolean USE_QUALIFIED_NAME_AS_ENDPOINT_NAME = false; + } } } diff --git a/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-commons/src/main/java/org/apache/skywalking/apm/plugin/spring/mvc/commons/interceptor/AbstractMethodInterceptor.java b/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-commons/src/main/java/org/apache/skywalking/apm/plugin/spring/mvc/commons/interceptor/AbstractMethodInterceptor.java index b2cb54afe..bb00062fb 100644 --- a/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-commons/src/main/java/org/apache/skywalking/apm/plugin/spring/mvc/commons/interceptor/AbstractMethodInterceptor.java +++ b/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-commons/src/main/java/org/apache/skywalking/apm/plugin/spring/mvc/commons/interceptor/AbstractMethodInterceptor.java @@ -21,6 +21,7 @@ package org.apache.skywalking.apm.plugin.spring.mvc.commons.interceptor; import java.lang.reflect.Method; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import org.apache.skywalking.apm.agent.core.conf.Config; 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; @@ -56,12 +57,18 @@ public abstract class AbstractMethodInterceptor implements InstanceMethodsAround return; } - EnhanceRequireObjectCache pathMappingCache = (EnhanceRequireObjectCache)objInst.getSkyWalkingDynamicField(); - String requestURL = pathMappingCache.findPathMapping(method); - if (requestURL == null) { - requestURL = getRequestURL(method); - pathMappingCache.addPathMapping(method, requestURL); - requestURL = pathMappingCache.findPathMapping(method); + String operationName; + if (Config.Plugin.SpringMVC.USE_QUALIFIED_NAME_AS_ENDPOINT_NAME) { + operationName = getFullyQualifiedMethodName(method); + } else { + EnhanceRequireObjectCache pathMappingCache = (EnhanceRequireObjectCache)objInst.getSkyWalkingDynamicField(); + String requestURL = pathMappingCache.findPathMapping(method); + if (requestURL == null) { + requestURL = getRequestURL(method); + pathMappingCache.addPathMapping(method, requestURL); + requestURL = pathMappingCache.findPathMapping(method); + } + operationName = requestURL; } HttpServletRequest request = (HttpServletRequest)ContextManager.getRuntimeContext().get(REQUEST_KEY_IN_RUNTIME_CONTEXT); @@ -73,7 +80,7 @@ public abstract class AbstractMethodInterceptor implements InstanceMethodsAround next.setHeadValue(request.getHeader(next.getHeadKey())); } - AbstractSpan span = ContextManager.createEntrySpan(requestURL, contextCarrier); + AbstractSpan span = ContextManager.createEntrySpan(operationName, contextCarrier); Tags.URL.set(span, request.getRequestURL().toString()); Tags.HTTP.METHOD.set(span, request.getMethod()); span.setComponent(ComponentsDefine.SPRING_MVC_ANNOTATION); @@ -116,4 +123,17 @@ public abstract class AbstractMethodInterceptor implements InstanceMethodsAround Class[] argumentsTypes, Throwable t) { ContextManager.activeSpan().errorOccurred().log(t); } + + public static String getFullyQualifiedMethodName(Method method) { + StringBuilder operationName = new StringBuilder(method.getDeclaringClass().getName() + "." + method.getName() + "("); + Class[] parameterTypes = method.getParameterTypes(); + for (int i = 0; i < parameterTypes.length; i++) { + operationName.append(parameterTypes[i].getName()); + if (i < (parameterTypes.length - 1)) { + operationName.append(","); + } + } + operationName.append(")"); + return operationName.toString(); + } } diff --git a/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-commons/src/main/java/org/apache/skywalking/apm/plugin/spring/mvc/commons/interceptor/RequestMappingMethodInterceptor.java b/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-commons/src/main/java/org/apache/skywalking/apm/plugin/spring/mvc/commons/interceptor/RequestMappingMethodInterceptor.java index 1dd6b7748..fad198d62 100644 --- a/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-commons/src/main/java/org/apache/skywalking/apm/plugin/spring/mvc/commons/interceptor/RequestMappingMethodInterceptor.java +++ b/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-commons/src/main/java/org/apache/skywalking/apm/plugin/spring/mvc/commons/interceptor/RequestMappingMethodInterceptor.java @@ -16,7 +16,6 @@ * */ - package org.apache.skywalking.apm.plugin.spring.mvc.commons.interceptor; import org.springframework.web.bind.annotation.RequestMapping; @@ -25,20 +24,30 @@ import java.lang.reflect.Method; /** * The RequestMappingMethodInterceptor only use the first mapping value. - * it will inteceptor with @RequestMapping + * it will interceptor with @RequestMapping * * @author clevertension */ public class RequestMappingMethodInterceptor extends AbstractMethodInterceptor { @Override public String getRequestURL(Method method) { - String requestURL = ""; + StringBuilder requestURL = new StringBuilder(); RequestMapping methodRequestMapping = method.getAnnotation(RequestMapping.class); - if (methodRequestMapping.value().length > 0) { - requestURL = methodRequestMapping.value()[0]; - } else if (methodRequestMapping.path().length > 0) { - requestURL = methodRequestMapping.path()[0]; + if (methodRequestMapping.method().length > 0) { + requestURL.append("{"); + for (int i = 0; i < methodRequestMapping.method().length; i++) { + requestURL.append(methodRequestMapping.method()[i].toString()); + if (methodRequestMapping.method().length > (i + 1)) { + requestURL.append(","); + } + } + requestURL = new StringBuilder("}"); } - return requestURL; + if (methodRequestMapping.value().length > 0) { + requestURL.append(methodRequestMapping.value()[0]); + } else if (methodRequestMapping.path().length > 0) { + requestURL.append(methodRequestMapping.path()[0]); + } + return requestURL.toString(); } } diff --git a/apm-sniffer/apm-sdk-plugin/spring-plugins/webflux-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/webflux/v5/RequestMappingMethodInterceptor.java b/apm-sniffer/apm-sdk-plugin/spring-plugins/webflux-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/webflux/v5/RequestMappingMethodInterceptor.java index 3bace06ce..230e72044 100644 --- a/apm-sniffer/apm-sdk-plugin/spring-plugins/webflux-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/webflux/v5/RequestMappingMethodInterceptor.java +++ b/apm-sniffer/apm-sdk-plugin/spring-plugins/webflux-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/webflux/v5/RequestMappingMethodInterceptor.java @@ -15,14 +15,13 @@ * limitations under the License. */ - package org.apache.skywalking.apm.plugin.spring.webflux.v5; import java.lang.reflect.Method; import org.springframework.web.bind.annotation.RequestMapping; /** - * The RequestMappingMethodInterceptor only use the first mapping value. it will inteceptor with + * The RequestMappingMethodInterceptor only use the first mapping value. it will interceptor with * @RequestMapping * * @author clevertension @@ -30,13 +29,23 @@ import org.springframework.web.bind.annotation.RequestMapping; public class RequestMappingMethodInterceptor extends AbstractMethodInterceptor { @Override public String getRequestURL(Method method) { - String requestURL = ""; + StringBuilder requestURL = new StringBuilder(); RequestMapping methodRequestMapping = method.getAnnotation(RequestMapping.class); - if (methodRequestMapping.value().length > 0) { - requestURL = methodRequestMapping.value()[0]; - } else if (methodRequestMapping.path().length > 0) { - requestURL = methodRequestMapping.path()[0]; + if (methodRequestMapping.method().length > 0) { + requestURL.append("{"); + for (int i = 0; i < methodRequestMapping.method().length; i++) { + requestURL.append(methodRequestMapping.method()[i].toString()); + if (methodRequestMapping.method().length > (i + 1)) { + requestURL.append(","); + } + } + requestURL = new StringBuilder("}"); } - return requestURL; + if (methodRequestMapping.value().length > 0) { + requestURL.append(methodRequestMapping.value()[0]); + } else if (methodRequestMapping.path().length > 0) { + requestURL.append(methodRequestMapping.path()[0]); + } + return requestURL.toString(); } } diff --git a/apm-sniffer/apm-toolkit-activation/apm-toolkit-trace-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/trace/TraceAnnotationMethodInterceptor.java b/apm-sniffer/apm-toolkit-activation/apm-toolkit-trace-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/trace/TraceAnnotationMethodInterceptor.java index dd5d992ae..2dcb345bf 100644 --- a/apm-sniffer/apm-toolkit-activation/apm-toolkit-trace-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/trace/TraceAnnotationMethodInterceptor.java +++ b/apm-sniffer/apm-toolkit-activation/apm-toolkit-trace-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/trace/TraceAnnotationMethodInterceptor.java @@ -20,6 +20,7 @@ package org.apache.skywalking.apm.toolkit.activation.trace; import java.lang.reflect.Method; +import org.apache.skywalking.apm.agent.core.conf.Config; import org.apache.skywalking.apm.toolkit.trace.Trace; import org.apache.skywalking.apm.agent.core.context.ContextManager; import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; @@ -39,7 +40,7 @@ public class TraceAnnotationMethodInterceptor implements InstanceMethodsAroundIn MethodInterceptResult result) throws Throwable { Trace trace = method.getAnnotation(Trace.class); String operationName = trace.operationName(); - if (operationName.length() == 0) { + if (operationName.length() == 0 || Config.Plugin.Toolkit.USE_QUALIFIED_NAME_AS_ENDPOINT_NAME) { operationName = generateOperationName(method); } From 7e3133136f2f2cc69707eb2735c1b3ad4a2a6ba3 Mon Sep 17 00:00:00 2001 From: Brandon Fergerson Date: Tue, 12 Mar 2019 22:45:47 -0600 Subject: [PATCH 03/12] add to docs --- docs/en/setup/service-agent/java-agent/README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/en/setup/service-agent/java-agent/README.md b/docs/en/setup/service-agent/java-agent/README.md index 85df6900b..2fb62793c 100644 --- a/docs/en/setup/service-agent/java-agent/README.md +++ b/docs/en/setup/service-agent/java-agent/README.md @@ -80,6 +80,8 @@ property key | Description | Default | `dictionary.endpoint_name_buffer_size`|The buffer size of endpoint names and peer|`1000 * 10000`| `plugin.mongodb.trace_param`|If true, trace all the parameters in MongoDB access, default is false. Only trace the operation, not include parameters.|`false`| `plugin.elasticsearch.trace_dsl`|If true, trace all the DSL(Domain Specific Language) in ElasticSearch access, default is false.|`false`| +`plugin.springmvc.use_qualified_name_as_endpoint_name`|If true, the fully qualified method name will be used as the endpoint name instead of the request URL, default is false.|`false`| +`plugin.toolit.use_qualified_name_as_endpoint_name`|If true, the fully qualified method name will be used as the endpoint name instead of the operation name, default is false.|`false`| ## Optional Plugins Java agent plugins are all pluggable. Optional plugins could be provided in `optional-plugins` folder under agent or 3rd party repositores. From 2a31e5c6605d7685200ce9cf07703e5304c2c783 Mon Sep 17 00:00:00 2001 From: Brandon Fergerson Date: Tue, 12 Mar 2019 22:55:41 -0600 Subject: [PATCH 04/12] fix merge --- .../java/org/apache/skywalking/apm/agent/core/conf/Config.java | 1 + 1 file changed, 1 insertion(+) diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/conf/Config.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/conf/Config.java index 19f18bcaa..9104c1cb9 100644 --- a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/conf/Config.java +++ b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/conf/Config.java @@ -193,4 +193,5 @@ public class Config { */ public static boolean USE_QUALIFIED_NAME_AS_ENDPOINT_NAME = false; } + } } From 2493865a92cb655699d39f0bf6bf6c89d5db5479 Mon Sep 17 00:00:00 2001 From: Brandon Fergerson Date: Tue, 12 Mar 2019 22:56:41 -0600 Subject: [PATCH 05/12] use MethodUtil --- .../interceptor/AbstractMethodInterceptor.java | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-commons/src/main/java/org/apache/skywalking/apm/plugin/spring/mvc/commons/interceptor/AbstractMethodInterceptor.java b/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-commons/src/main/java/org/apache/skywalking/apm/plugin/spring/mvc/commons/interceptor/AbstractMethodInterceptor.java index bb00062fb..64748a265 100644 --- a/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-commons/src/main/java/org/apache/skywalking/apm/plugin/spring/mvc/commons/interceptor/AbstractMethodInterceptor.java +++ b/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-commons/src/main/java/org/apache/skywalking/apm/plugin/spring/mvc/commons/interceptor/AbstractMethodInterceptor.java @@ -31,6 +31,7 @@ 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.agent.core.util.MethodUtil; import org.apache.skywalking.apm.network.trace.component.ComponentsDefine; import org.apache.skywalking.apm.plugin.spring.mvc.commons.EnhanceRequireObjectCache; @@ -59,7 +60,7 @@ public abstract class AbstractMethodInterceptor implements InstanceMethodsAround String operationName; if (Config.Plugin.SpringMVC.USE_QUALIFIED_NAME_AS_ENDPOINT_NAME) { - operationName = getFullyQualifiedMethodName(method); + operationName = MethodUtil.generateOperationName(method); } else { EnhanceRequireObjectCache pathMappingCache = (EnhanceRequireObjectCache)objInst.getSkyWalkingDynamicField(); String requestURL = pathMappingCache.findPathMapping(method); @@ -123,17 +124,4 @@ public abstract class AbstractMethodInterceptor implements InstanceMethodsAround Class[] argumentsTypes, Throwable t) { ContextManager.activeSpan().errorOccurred().log(t); } - - public static String getFullyQualifiedMethodName(Method method) { - StringBuilder operationName = new StringBuilder(method.getDeclaringClass().getName() + "." + method.getName() + "("); - Class[] parameterTypes = method.getParameterTypes(); - for (int i = 0; i < parameterTypes.length; i++) { - operationName.append(parameterTypes[i].getName()); - if (i < (parameterTypes.length - 1)) { - operationName.append(","); - } - } - operationName.append(")"); - return operationName.toString(); - } } From a2df0e0e3de50c076612bb127e30ffa0622a27b4 Mon Sep 17 00:00:00 2001 From: Brandon Fergerson Date: Tue, 12 Mar 2019 23:00:06 -0600 Subject: [PATCH 06/12] didn't mean to commit with this PR --- .../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 | 3 - .../test/resources/component-libraries.yml | 3 - .../main/resources/component-libraries.yml | 3 - 15 files changed, 1 insertion(+), 602 deletions(-) delete mode 100644 apm-sniffer/apm-sdk-plugin/vertx-3.x-plugin/pom.xml delete mode 100644 apm-sniffer/apm-sdk-plugin/vertx-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/vertx3/HttpClientRequestImplDoHandleResponseInterceptor.java delete mode 100644 apm-sniffer/apm-sdk-plugin/vertx-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/vertx3/HttpClientRequestImplEndInterceptor.java delete mode 100644 apm-sniffer/apm-sdk-plugin/vertx-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/vertx3/HttpServerRequestImplDoEndInterceptor.java delete mode 100644 apm-sniffer/apm-sdk-plugin/vertx-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/vertx3/HttpServerResponseImplEndInterceptor.java delete mode 100644 apm-sniffer/apm-sdk-plugin/vertx-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/vertx3/define/HttpClientRequestImplDoHandleResponseInstrumentation.java delete mode 100644 apm-sniffer/apm-sdk-plugin/vertx-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/vertx3/define/HttpClientRequestImplEndInstrumentation.java delete mode 100644 apm-sniffer/apm-sdk-plugin/vertx-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/vertx3/define/HttpServerRequestImplDoEndInstrumentation.java delete mode 100644 apm-sniffer/apm-sdk-plugin/vertx-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/vertx3/define/HttpServerResponseImplEndInstrumentation.java delete 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 2a3116148..ce9cb5f62 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,8 +114,6 @@ 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; @@ -125,7 +123,7 @@ public class ComponentsDefine { } public ComponentsDefine() { - components = new String[60]; + components = new String[59]; addComponent(TOMCAT); addComponent(HTTPCLIENT); addComponent(DUBBO); @@ -169,7 +167,6 @@ 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 2fbe7f9f4..63e97a71e 100644 --- a/apm-sniffer/apm-sdk-plugin/pom.xml +++ b/apm-sniffer/apm-sdk-plugin/pom.xml @@ -67,7 +67,6 @@ 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 deleted file mode 100644 index 7946e70c8..000000000 --- a/apm-sniffer/apm-sdk-plugin/vertx-3.x-plugin/pom.xml +++ /dev/null @@ -1,51 +0,0 @@ - - - - - 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 deleted file mode 100644 index 0ee78bdb2..000000000 --- a/apm-sniffer/apm-sdk-plugin/vertx-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/vertx3/HttpClientRequestImplDoHandleResponseInterceptor.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.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 deleted file mode 100644 index 92e74c293..000000000 --- a/apm-sniffer/apm-sdk-plugin/vertx-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/vertx3/HttpClientRequestImplEndInterceptor.java +++ /dev/null @@ -1,65 +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.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 deleted file mode 100644 index 0c9695f69..000000000 --- a/apm-sniffer/apm-sdk-plugin/vertx-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/vertx3/HttpServerRequestImplDoEndInterceptor.java +++ /dev/null @@ -1,66 +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.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 deleted file mode 100644 index 1d745de05..000000000 --- a/apm-sniffer/apm-sdk-plugin/vertx-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/vertx3/HttpServerResponseImplEndInterceptor.java +++ /dev/null @@ -1,59 +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.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 deleted file mode 100644 index b6c2bde7d..000000000 --- a/apm-sniffer/apm-sdk-plugin/vertx-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/vertx3/define/HttpClientRequestImplDoHandleResponseInstrumentation.java +++ /dev/null @@ -1,69 +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.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 deleted file mode 100644 index eea87462d..000000000 --- a/apm-sniffer/apm-sdk-plugin/vertx-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/vertx3/define/HttpClientRequestImplEndInstrumentation.java +++ /dev/null @@ -1,69 +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.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 deleted file mode 100644 index f085e949e..000000000 --- a/apm-sniffer/apm-sdk-plugin/vertx-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/vertx3/define/HttpServerRequestImplDoEndInstrumentation.java +++ /dev/null @@ -1,69 +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.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 deleted file mode 100644 index 98c15c0cc..000000000 --- a/apm-sniffer/apm-sdk-plugin/vertx-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/vertx3/define/HttpServerResponseImplEndInstrumentation.java +++ /dev/null @@ -1,69 +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.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 deleted file mode 100644 index 72c8c9687..000000000 --- a/apm-sniffer/apm-sdk-plugin/vertx-3.x-plugin/src/main/resources/skywalking-plugin.def +++ /dev/null @@ -1,20 +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. - -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 01c104ddd..08944dbcb 100644 --- a/docker/config/component-libraries.yml +++ b/docker/config/component-libraries.yml @@ -204,9 +204,6 @@ 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 6141aeb6b..587c08ba2 100644 --- a/oap-server/server-core/src/test/resources/component-libraries.yml +++ b/oap-server/server-core/src/test/resources/component-libraries.yml @@ -186,9 +186,6 @@ 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 71150e670..2eaf1cacb 100644 --- a/oap-server/server-starter/src/main/resources/component-libraries.yml +++ b/oap-server/server-starter/src/main/resources/component-libraries.yml @@ -204,9 +204,6 @@ Lettuce: Zookeeper: id: 58 languages: Java -Vertx: - id: 59 - languages: Java # .NET/.NET Core components # [3000, 4000) for C#/.NET only From 7322ea86a6054af8ee26543ab23c57dc036d3c91 Mon Sep 17 00:00:00 2001 From: Brandon Fergerson Date: Wed, 13 Mar 2019 08:17:11 -0600 Subject: [PATCH 07/12] updated to operation name --- .../org/apache/skywalking/apm/agent/core/conf/Config.java | 4 ++-- .../activation/trace/TraceAnnotationMethodInterceptor.java | 2 +- docs/en/setup/service-agent/java-agent/README.md | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/conf/Config.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/conf/Config.java index 9104c1cb9..2553cca84 100644 --- a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/conf/Config.java +++ b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/conf/Config.java @@ -189,9 +189,9 @@ public class Config { public static class Toolkit { /** - * If true, the fully qualified method name will be used as the endpoint name instead of the operation name, default is false. + * If true, the fully qualified method name will be used as the operation name instead of the given operation name, default is false. */ - public static boolean USE_QUALIFIED_NAME_AS_ENDPOINT_NAME = false; + public static boolean USE_QUALIFIED_NAME_AS_OPERATION_NAME = false; } } } diff --git a/apm-sniffer/apm-toolkit-activation/apm-toolkit-trace-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/trace/TraceAnnotationMethodInterceptor.java b/apm-sniffer/apm-toolkit-activation/apm-toolkit-trace-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/trace/TraceAnnotationMethodInterceptor.java index b84c053a1..ca82248ec 100644 --- a/apm-sniffer/apm-toolkit-activation/apm-toolkit-trace-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/trace/TraceAnnotationMethodInterceptor.java +++ b/apm-sniffer/apm-toolkit-activation/apm-toolkit-trace-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/trace/TraceAnnotationMethodInterceptor.java @@ -41,7 +41,7 @@ public class TraceAnnotationMethodInterceptor implements InstanceMethodsAroundIn MethodInterceptResult result) throws Throwable { Trace trace = method.getAnnotation(Trace.class); String operationName = trace.operationName(); - if (operationName.length() == 0 || Config.Plugin.Toolkit.USE_QUALIFIED_NAME_AS_ENDPOINT_NAME) { + if (operationName.length() == 0 || Config.Plugin.Toolkit.USE_QUALIFIED_NAME_AS_OPERATION_NAME) { operationName = MethodUtil.generateOperationName(method); } diff --git a/docs/en/setup/service-agent/java-agent/README.md b/docs/en/setup/service-agent/java-agent/README.md index 51c1622a1..d79e9bb5c 100644 --- a/docs/en/setup/service-agent/java-agent/README.md +++ b/docs/en/setup/service-agent/java-agent/README.md @@ -25,7 +25,7 @@ The agent release dist is included in Apache [official release](http://skywalkin - Start your application. ## Supported middlewares, frameworks and libraries -SkyWalking agent has supported various middlewares, framdworks and libraries. +SkyWalking agent has supported various middlewares, frameworks and libraries. Read [supported list](Supported-list.md) to get them and supported version. If the plugin is in **Optional²** catalog, go to [optional plugins](#optional-plugins) section to learn how to active it. @@ -81,7 +81,7 @@ property key | Description | Default | `plugin.mongodb.trace_param`|If true, trace all the parameters in MongoDB access, default is false. Only trace the operation, not include parameters.|`false`| `plugin.elasticsearch.trace_dsl`|If true, trace all the DSL(Domain Specific Language) in ElasticSearch access, default is false.|`false`| `plugin.springmvc.use_qualified_name_as_endpoint_name`|If true, the fully qualified method name will be used as the endpoint name instead of the request URL, default is false.|`false`| -`plugin.toolit.use_qualified_name_as_endpoint_name`|If true, the fully qualified method name will be used as the endpoint name instead of the operation name, default is false.|`false`| +`plugin.toolit.use_qualified_name_as_operation_name`|If true, the fully qualified method name will be used as the operation name instead of the given operation name, default is false.|`false`| ## Optional Plugins Java agent plugins are all pluggable. Optional plugins could be provided in `optional-plugins` folder under agent or 3rd party repositores. From 65692887f29a596c644cf64d3a1a563ee1c554df Mon Sep 17 00:00:00 2001 From: Brandon Fergerson Date: Sat, 16 Mar 2019 20:12:05 -0600 Subject: [PATCH 08/12] meant to append --- .../commons/interceptor/RequestMappingMethodInterceptor.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-commons/src/main/java/org/apache/skywalking/apm/plugin/spring/mvc/commons/interceptor/RequestMappingMethodInterceptor.java b/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-commons/src/main/java/org/apache/skywalking/apm/plugin/spring/mvc/commons/interceptor/RequestMappingMethodInterceptor.java index fad198d62..c45a38786 100644 --- a/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-commons/src/main/java/org/apache/skywalking/apm/plugin/spring/mvc/commons/interceptor/RequestMappingMethodInterceptor.java +++ b/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-commons/src/main/java/org/apache/skywalking/apm/plugin/spring/mvc/commons/interceptor/RequestMappingMethodInterceptor.java @@ -41,7 +41,7 @@ public class RequestMappingMethodInterceptor extends AbstractMethodInterceptor { requestURL.append(","); } } - requestURL = new StringBuilder("}"); + requestURL.append("}"); } if (methodRequestMapping.value().length > 0) { requestURL.append(methodRequestMapping.value()[0]); From fe9f81bc1b6d40cc0875c25954832d46b8e954ab Mon Sep 17 00:00:00 2001 From: Brandon Fergerson Date: Sat, 16 Mar 2019 20:14:24 -0600 Subject: [PATCH 09/12] meant to append --- .../spring/webflux/v5/RequestMappingMethodInterceptor.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apm-sniffer/apm-sdk-plugin/spring-plugins/webflux-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/webflux/v5/RequestMappingMethodInterceptor.java b/apm-sniffer/apm-sdk-plugin/spring-plugins/webflux-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/webflux/v5/RequestMappingMethodInterceptor.java index 230e72044..17d5697e1 100644 --- a/apm-sniffer/apm-sdk-plugin/spring-plugins/webflux-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/webflux/v5/RequestMappingMethodInterceptor.java +++ b/apm-sniffer/apm-sdk-plugin/spring-plugins/webflux-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/webflux/v5/RequestMappingMethodInterceptor.java @@ -39,7 +39,7 @@ public class RequestMappingMethodInterceptor extends AbstractMethodInterceptor { requestURL.append(","); } } - requestURL = new StringBuilder("}"); + requestURL.append("}"); } if (methodRequestMapping.value().length > 0) { requestURL.append(methodRequestMapping.value()[0]); From 257af0bda77eddeaef578604a4a35d29db3a2944 Mon Sep 17 00:00:00 2001 From: Brandon Fergerson Date: Sun, 17 Mar 2019 10:29:42 -0600 Subject: [PATCH 10/12] moved accepted method types to beginning of url --- .../AbstractMethodInterceptor.java | 3 +- .../RequestMappingMethodInterceptor.java | 29 ++++++++++++------- .../RestMappingMethodInterceptor.java | 5 ++++ .../webflux/v5/AbstractMethodInterceptor.java | 7 +++-- .../v5/RequestMappingMethodInterceptor.java | 29 ++++++++++++------- .../v5/RestMappingMethodInterceptor.java | 5 ++++ 6 files changed, 52 insertions(+), 26 deletions(-) diff --git a/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-commons/src/main/java/org/apache/skywalking/apm/plugin/spring/mvc/commons/interceptor/AbstractMethodInterceptor.java b/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-commons/src/main/java/org/apache/skywalking/apm/plugin/spring/mvc/commons/interceptor/AbstractMethodInterceptor.java index 64748a265..8c200113d 100644 --- a/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-commons/src/main/java/org/apache/skywalking/apm/plugin/spring/mvc/commons/interceptor/AbstractMethodInterceptor.java +++ b/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-commons/src/main/java/org/apache/skywalking/apm/plugin/spring/mvc/commons/interceptor/AbstractMethodInterceptor.java @@ -44,6 +44,7 @@ import static org.apache.skywalking.apm.plugin.spring.mvc.commons.Constants.RESP */ public abstract class AbstractMethodInterceptor implements InstanceMethodsAroundInterceptor { public abstract String getRequestURL(Method method); + public abstract String getAcceptedMethodTypes(Method method); @Override public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, @@ -67,7 +68,7 @@ public abstract class AbstractMethodInterceptor implements InstanceMethodsAround if (requestURL == null) { requestURL = getRequestURL(method); pathMappingCache.addPathMapping(method, requestURL); - requestURL = pathMappingCache.findPathMapping(method); + requestURL = getAcceptedMethodTypes(method) + pathMappingCache.findPathMapping(method); } operationName = requestURL; } diff --git a/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-commons/src/main/java/org/apache/skywalking/apm/plugin/spring/mvc/commons/interceptor/RequestMappingMethodInterceptor.java b/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-commons/src/main/java/org/apache/skywalking/apm/plugin/spring/mvc/commons/interceptor/RequestMappingMethodInterceptor.java index c45a38786..38f939717 100644 --- a/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-commons/src/main/java/org/apache/skywalking/apm/plugin/spring/mvc/commons/interceptor/RequestMappingMethodInterceptor.java +++ b/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-commons/src/main/java/org/apache/skywalking/apm/plugin/spring/mvc/commons/interceptor/RequestMappingMethodInterceptor.java @@ -31,23 +31,30 @@ import java.lang.reflect.Method; public class RequestMappingMethodInterceptor extends AbstractMethodInterceptor { @Override public String getRequestURL(Method method) { - StringBuilder requestURL = new StringBuilder(); + String requestURL = ""; RequestMapping methodRequestMapping = method.getAnnotation(RequestMapping.class); + if (methodRequestMapping.value().length > 0) { + requestURL = methodRequestMapping.value()[0]; + } else if (methodRequestMapping.path().length > 0) { + requestURL = methodRequestMapping.path()[0]; + } + return requestURL; + } + + @Override + public String getAcceptedMethodTypes(Method method) { + RequestMapping methodRequestMapping = method.getAnnotation(RequestMapping.class); + StringBuilder methodTypes = new StringBuilder(); if (methodRequestMapping.method().length > 0) { - requestURL.append("{"); + methodTypes.append("{"); for (int i = 0; i < methodRequestMapping.method().length; i++) { - requestURL.append(methodRequestMapping.method()[i].toString()); + methodTypes.append(methodRequestMapping.method()[i].toString()); if (methodRequestMapping.method().length > (i + 1)) { - requestURL.append(","); + methodTypes.append(","); } } - requestURL.append("}"); + methodTypes.append("}"); } - if (methodRequestMapping.value().length > 0) { - requestURL.append(methodRequestMapping.value()[0]); - } else if (methodRequestMapping.path().length > 0) { - requestURL.append(methodRequestMapping.path()[0]); - } - return requestURL.toString(); + return methodTypes.toString(); } } diff --git a/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-commons/src/main/java/org/apache/skywalking/apm/plugin/spring/mvc/commons/interceptor/RestMappingMethodInterceptor.java b/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-commons/src/main/java/org/apache/skywalking/apm/plugin/spring/mvc/commons/interceptor/RestMappingMethodInterceptor.java index 5cea58d0d..cfadb4e5f 100644 --- a/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-commons/src/main/java/org/apache/skywalking/apm/plugin/spring/mvc/commons/interceptor/RestMappingMethodInterceptor.java +++ b/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-commons/src/main/java/org/apache/skywalking/apm/plugin/spring/mvc/commons/interceptor/RestMappingMethodInterceptor.java @@ -73,4 +73,9 @@ public class RestMappingMethodInterceptor extends AbstractMethodInterceptor { } return requestURL; } + + @Override + public String getAcceptedMethodTypes(Method method) { + return ""; + } } diff --git a/apm-sniffer/apm-sdk-plugin/spring-plugins/webflux-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/webflux/v5/AbstractMethodInterceptor.java b/apm-sniffer/apm-sdk-plugin/spring-plugins/webflux-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/webflux/v5/AbstractMethodInterceptor.java index da9dae605..43baad9ed 100644 --- a/apm-sniffer/apm-sdk-plugin/spring-plugins/webflux-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/webflux/v5/AbstractMethodInterceptor.java +++ b/apm-sniffer/apm-sdk-plugin/spring-plugins/webflux-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/webflux/v5/AbstractMethodInterceptor.java @@ -35,10 +35,11 @@ import static org.apache.skywalking.apm.plugin.spring.mvc.commons.Constants.FORW import static org.apache.skywalking.apm.plugin.spring.mvc.commons.Constants.WEBFLUX_REQUEST_KEY; /** - * the abstract method inteceptor + * the abstract method interceptor */ public abstract class AbstractMethodInterceptor implements InstanceMethodsAroundInterceptor { public abstract String getRequestURL(Method method); + public abstract String getAcceptedMethodTypes(Method method); @Override public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, @@ -58,7 +59,7 @@ public abstract class AbstractMethodInterceptor implements InstanceMethodsAround if (requestURL == null) { requestURL = getRequestURL(method); pathMappingCache.addPathMapping(method, requestURL); - requestURL = pathMappingCache.findPathMapping(method); + requestURL = getAcceptedMethodTypes(method) + pathMappingCache.findPathMapping(method); } HttpRequest request = (HttpRequest)ContextManager.getRuntimeContext().get(WEBFLUX_REQUEST_KEY); @@ -71,7 +72,7 @@ public abstract class AbstractMethodInterceptor implements InstanceMethodsAround } AbstractSpan span = ContextManager.createEntrySpan(requestURL, contextCarrier); - Tags.URL.set(span, request.uri().toString()); + Tags.URL.set(span, request.uri()); Tags.HTTP.METHOD.set(span, request.method().name()); span.setComponent(ComponentsDefine.SPRING_MVC_ANNOTATION); SpanLayer.asHttp(span); diff --git a/apm-sniffer/apm-sdk-plugin/spring-plugins/webflux-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/webflux/v5/RequestMappingMethodInterceptor.java b/apm-sniffer/apm-sdk-plugin/spring-plugins/webflux-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/webflux/v5/RequestMappingMethodInterceptor.java index 17d5697e1..e79372be5 100644 --- a/apm-sniffer/apm-sdk-plugin/spring-plugins/webflux-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/webflux/v5/RequestMappingMethodInterceptor.java +++ b/apm-sniffer/apm-sdk-plugin/spring-plugins/webflux-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/webflux/v5/RequestMappingMethodInterceptor.java @@ -29,23 +29,30 @@ import org.springframework.web.bind.annotation.RequestMapping; public class RequestMappingMethodInterceptor extends AbstractMethodInterceptor { @Override public String getRequestURL(Method method) { - StringBuilder requestURL = new StringBuilder(); + String requestURL = ""; RequestMapping methodRequestMapping = method.getAnnotation(RequestMapping.class); + if (methodRequestMapping.value().length > 0) { + requestURL = methodRequestMapping.value()[0]; + } else if (methodRequestMapping.path().length > 0) { + requestURL = methodRequestMapping.path()[0]; + } + return requestURL; + } + + @Override + public String getAcceptedMethodTypes(Method method) { + RequestMapping methodRequestMapping = method.getAnnotation(RequestMapping.class); + StringBuilder methodTypes = new StringBuilder(); if (methodRequestMapping.method().length > 0) { - requestURL.append("{"); + methodTypes.append("{"); for (int i = 0; i < methodRequestMapping.method().length; i++) { - requestURL.append(methodRequestMapping.method()[i].toString()); + methodTypes.append(methodRequestMapping.method()[i].toString()); if (methodRequestMapping.method().length > (i + 1)) { - requestURL.append(","); + methodTypes.append(","); } } - requestURL.append("}"); + methodTypes.append("}"); } - if (methodRequestMapping.value().length > 0) { - requestURL.append(methodRequestMapping.value()[0]); - } else if (methodRequestMapping.path().length > 0) { - requestURL.append(methodRequestMapping.path()[0]); - } - return requestURL.toString(); + return methodTypes.toString(); } } diff --git a/apm-sniffer/apm-sdk-plugin/spring-plugins/webflux-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/webflux/v5/RestMappingMethodInterceptor.java b/apm-sniffer/apm-sdk-plugin/spring-plugins/webflux-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/webflux/v5/RestMappingMethodInterceptor.java index 064671c27..3526ff4d2 100644 --- a/apm-sniffer/apm-sdk-plugin/spring-plugins/webflux-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/webflux/v5/RestMappingMethodInterceptor.java +++ b/apm-sniffer/apm-sdk-plugin/spring-plugins/webflux-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/webflux/v5/RestMappingMethodInterceptor.java @@ -74,4 +74,9 @@ public class RestMappingMethodInterceptor extends AbstractMethodInterceptor { } return requestURL; } + + @Override + public String getAcceptedMethodTypes(Method method) { + return ""; + } } From ffb6a1bde2fd442125fbdca2b23e9ca54021afec Mon Sep 17 00:00:00 2001 From: Brandon Fergerson Date: Sun, 17 Mar 2019 10:31:02 -0600 Subject: [PATCH 11/12] spelling --- .../mvc/commons/interceptor/AbstractMethodInterceptor.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-commons/src/main/java/org/apache/skywalking/apm/plugin/spring/mvc/commons/interceptor/AbstractMethodInterceptor.java b/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-commons/src/main/java/org/apache/skywalking/apm/plugin/spring/mvc/commons/interceptor/AbstractMethodInterceptor.java index 8c200113d..0561ff847 100644 --- a/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-commons/src/main/java/org/apache/skywalking/apm/plugin/spring/mvc/commons/interceptor/AbstractMethodInterceptor.java +++ b/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-commons/src/main/java/org/apache/skywalking/apm/plugin/spring/mvc/commons/interceptor/AbstractMethodInterceptor.java @@ -40,7 +40,7 @@ import static org.apache.skywalking.apm.plugin.spring.mvc.commons.Constants.REQU import static org.apache.skywalking.apm.plugin.spring.mvc.commons.Constants.RESPONSE_KEY_IN_RUNTIME_CONTEXT; /** - * the abstract method inteceptor + * the abstract method interceptor */ public abstract class AbstractMethodInterceptor implements InstanceMethodsAroundInterceptor { public abstract String getRequestURL(Method method); From 6a6cbaa1b50bab43dc5f3be30e7608a1e5431466 Mon Sep 17 00:00:00 2001 From: Brandon Fergerson Date: Sun, 17 Mar 2019 10:31:58 -0600 Subject: [PATCH 12/12] formatting/spelling --- .../mvc/commons/interceptor/RestMappingMethodInterceptor.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-commons/src/main/java/org/apache/skywalking/apm/plugin/spring/mvc/commons/interceptor/RestMappingMethodInterceptor.java b/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-commons/src/main/java/org/apache/skywalking/apm/plugin/spring/mvc/commons/interceptor/RestMappingMethodInterceptor.java index cfadb4e5f..086e05950 100644 --- a/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-commons/src/main/java/org/apache/skywalking/apm/plugin/spring/mvc/commons/interceptor/RestMappingMethodInterceptor.java +++ b/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-commons/src/main/java/org/apache/skywalking/apm/plugin/spring/mvc/commons/interceptor/RestMappingMethodInterceptor.java @@ -16,7 +16,6 @@ * */ - package org.apache.skywalking.apm.plugin.spring.mvc.commons.interceptor; import org.springframework.web.bind.annotation.*; @@ -25,7 +24,7 @@ import java.lang.reflect.Method; /** * The RestMappingMethodInterceptor only use the first mapping value. - * it will inteceptor with + * it will interceptor with * @GetMapping, @PostMapping, @PutMapping * @DeleteMapping, @PatchMapping *