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);
}