impl USE_QUALIFIED_NAME_AS_ENDPOINT_NAME
This commit is contained in:
parent
eb19715f99
commit
62f21330ad
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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 <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
|
||||
*/
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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 <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>
|
||||
*
|
||||
* @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();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue