moved accepted method types to beginning of url
This commit is contained in:
parent
9a1518a652
commit
257af0bda7
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -73,4 +73,9 @@ public class RestMappingMethodInterceptor extends AbstractMethodInterceptor {
|
|||
}
|
||||
return requestURL;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAcceptedMethodTypes(Method method) {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -74,4 +74,9 @@ public class RestMappingMethodInterceptor extends AbstractMethodInterceptor {
|
|||
}
|
||||
return requestURL;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAcceptedMethodTypes(Method method) {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue