提交 62f21330 编写于 作者: B Brandon Fergerson

impl USE_QUALIFIED_NAME_AS_ENDPOINT_NAME

上级 eb19715f
...@@ -163,5 +163,19 @@ public class Config { ...@@ -163,5 +163,19 @@ public class Config {
*/ */
public static boolean TRACE_DSL = false; 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;
}
} }
} }
...@@ -21,6 +21,7 @@ package org.apache.skywalking.apm.plugin.spring.mvc.commons.interceptor; ...@@ -21,6 +21,7 @@ package org.apache.skywalking.apm.plugin.spring.mvc.commons.interceptor;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; 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.CarrierItem;
import org.apache.skywalking.apm.agent.core.context.ContextCarrier; 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.ContextManager;
...@@ -56,12 +57,18 @@ public abstract class AbstractMethodInterceptor implements InstanceMethodsAround ...@@ -56,12 +57,18 @@ public abstract class AbstractMethodInterceptor implements InstanceMethodsAround
return; return;
} }
EnhanceRequireObjectCache pathMappingCache = (EnhanceRequireObjectCache)objInst.getSkyWalkingDynamicField(); String operationName;
String requestURL = pathMappingCache.findPathMapping(method); if (Config.Plugin.SpringMVC.USE_QUALIFIED_NAME_AS_ENDPOINT_NAME) {
if (requestURL == null) { operationName = getFullyQualifiedMethodName(method);
requestURL = getRequestURL(method); } else {
pathMappingCache.addPathMapping(method, requestURL); EnhanceRequireObjectCache pathMappingCache = (EnhanceRequireObjectCache)objInst.getSkyWalkingDynamicField();
requestURL = pathMappingCache.findPathMapping(method); 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); HttpServletRequest request = (HttpServletRequest)ContextManager.getRuntimeContext().get(REQUEST_KEY_IN_RUNTIME_CONTEXT);
...@@ -73,7 +80,7 @@ public abstract class AbstractMethodInterceptor implements InstanceMethodsAround ...@@ -73,7 +80,7 @@ public abstract class AbstractMethodInterceptor implements InstanceMethodsAround
next.setHeadValue(request.getHeader(next.getHeadKey())); 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.URL.set(span, request.getRequestURL().toString());
Tags.HTTP.METHOD.set(span, request.getMethod()); Tags.HTTP.METHOD.set(span, request.getMethod());
span.setComponent(ComponentsDefine.SPRING_MVC_ANNOTATION); span.setComponent(ComponentsDefine.SPRING_MVC_ANNOTATION);
...@@ -116,4 +123,17 @@ public abstract class AbstractMethodInterceptor implements InstanceMethodsAround ...@@ -116,4 +123,17 @@ public abstract class AbstractMethodInterceptor implements InstanceMethodsAround
Class<?>[] argumentsTypes, Throwable t) { Class<?>[] argumentsTypes, Throwable t) {
ContextManager.activeSpan().errorOccurred().log(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();
}
} }
...@@ -16,7 +16,6 @@ ...@@ -16,7 +16,6 @@
* *
*/ */
package org.apache.skywalking.apm.plugin.spring.mvc.commons.interceptor; package org.apache.skywalking.apm.plugin.spring.mvc.commons.interceptor;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
...@@ -25,20 +24,30 @@ import java.lang.reflect.Method; ...@@ -25,20 +24,30 @@ import java.lang.reflect.Method;
/** /**
* The <code>RequestMappingMethodInterceptor</code> only use the first mapping value. * The <code>RequestMappingMethodInterceptor</code> only use the first mapping value.
* it will inteceptor with <code>@RequestMapping</code> * it will interceptor with <code>@RequestMapping</code>
* *
* @author clevertension * @author clevertension
*/ */
public class RequestMappingMethodInterceptor extends AbstractMethodInterceptor { public class RequestMappingMethodInterceptor extends AbstractMethodInterceptor {
@Override @Override
public String getRequestURL(Method method) { public String getRequestURL(Method method) {
String requestURL = ""; StringBuilder requestURL = new StringBuilder();
RequestMapping methodRequestMapping = method.getAnnotation(RequestMapping.class); RequestMapping methodRequestMapping = method.getAnnotation(RequestMapping.class);
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("}");
}
if (methodRequestMapping.value().length > 0) { if (methodRequestMapping.value().length > 0) {
requestURL = methodRequestMapping.value()[0]; requestURL.append(methodRequestMapping.value()[0]);
} else if (methodRequestMapping.path().length > 0) { } else if (methodRequestMapping.path().length > 0) {
requestURL = methodRequestMapping.path()[0]; requestURL.append(methodRequestMapping.path()[0]);
} }
return requestURL; return requestURL.toString();
} }
} }
...@@ -15,14 +15,13 @@ ...@@ -15,14 +15,13 @@
* limitations under the License. * limitations under the License.
*/ */
package org.apache.skywalking.apm.plugin.spring.webflux.v5; package org.apache.skywalking.apm.plugin.spring.webflux.v5;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
/** /**
* The <code>RequestMappingMethodInterceptor</code> only use the first mapping value. it will inteceptor with * The <code>RequestMappingMethodInterceptor</code> only use the first mapping value. it will interceptor with
* <code>@RequestMapping</code> * <code>@RequestMapping</code>
* *
* @author clevertension * @author clevertension
...@@ -30,13 +29,23 @@ import org.springframework.web.bind.annotation.RequestMapping; ...@@ -30,13 +29,23 @@ import org.springframework.web.bind.annotation.RequestMapping;
public class RequestMappingMethodInterceptor extends AbstractMethodInterceptor { public class RequestMappingMethodInterceptor extends AbstractMethodInterceptor {
@Override @Override
public String getRequestURL(Method method) { public String getRequestURL(Method method) {
String requestURL = ""; StringBuilder requestURL = new StringBuilder();
RequestMapping methodRequestMapping = method.getAnnotation(RequestMapping.class); RequestMapping methodRequestMapping = method.getAnnotation(RequestMapping.class);
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("}");
}
if (methodRequestMapping.value().length > 0) { if (methodRequestMapping.value().length > 0) {
requestURL = methodRequestMapping.value()[0]; requestURL.append(methodRequestMapping.value()[0]);
} else if (methodRequestMapping.path().length > 0) { } else if (methodRequestMapping.path().length > 0) {
requestURL = methodRequestMapping.path()[0]; requestURL.append(methodRequestMapping.path()[0]);
} }
return requestURL; return requestURL.toString();
} }
} }
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
package org.apache.skywalking.apm.toolkit.activation.trace; package org.apache.skywalking.apm.toolkit.activation.trace;
import java.lang.reflect.Method; 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.toolkit.trace.Trace;
import org.apache.skywalking.apm.agent.core.context.ContextManager; import org.apache.skywalking.apm.agent.core.context.ContextManager;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance;
...@@ -39,7 +40,7 @@ public class TraceAnnotationMethodInterceptor implements InstanceMethodsAroundIn ...@@ -39,7 +40,7 @@ public class TraceAnnotationMethodInterceptor implements InstanceMethodsAroundIn
MethodInterceptResult result) throws Throwable { MethodInterceptResult result) throws Throwable {
Trace trace = method.getAnnotation(Trace.class); Trace trace = method.getAnnotation(Trace.class);
String operationName = trace.operationName(); String operationName = trace.operationName();
if (operationName.length() == 0) { if (operationName.length() == 0 || Config.Plugin.Toolkit.USE_QUALIFIED_NAME_AS_ENDPOINT_NAME) {
operationName = generateOperationName(method); operationName = generateOperationName(method);
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册