Merge pull request #2353 from BFergerson/qualified-spring-mvc-endpoints
USE_QUALIFIED_NAME_AS_ENDPOINT_NAME configuration
This commit is contained in:
commit
c694a30c5f
|
|
@ -166,6 +166,7 @@ public class Config {
|
|||
*/
|
||||
public static boolean TRACE_DSL = false;
|
||||
}
|
||||
|
||||
public static class Customize {
|
||||
/**
|
||||
* Custom enhancement class configuration file path, recommended to use an absolute path.
|
||||
|
|
@ -178,5 +179,19 @@ public class Config {
|
|||
*/
|
||||
public static Map<String, Object> CONTEXT = new HashMap<String, Object>();
|
||||
}
|
||||
|
||||
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 operation name instead of the given operation name, default is false.
|
||||
*/
|
||||
public static boolean USE_QUALIFIED_NAME_AS_OPERATION_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;
|
||||
|
|
@ -30,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;
|
||||
|
||||
|
|
@ -38,10 +40,11 @@ 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);
|
||||
public abstract String getAcceptedMethodTypes(Method method);
|
||||
|
||||
@Override
|
||||
public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes,
|
||||
|
|
@ -56,12 +59,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 = MethodUtil.generateOperationName(method);
|
||||
} else {
|
||||
EnhanceRequireObjectCache pathMappingCache = (EnhanceRequireObjectCache)objInst.getSkyWalkingDynamicField();
|
||||
String requestURL = pathMappingCache.findPathMapping(method);
|
||||
if (requestURL == null) {
|
||||
requestURL = getRequestURL(method);
|
||||
pathMappingCache.addPathMapping(method, requestURL);
|
||||
requestURL = getAcceptedMethodTypes(method) + pathMappingCache.findPathMapping(method);
|
||||
}
|
||||
operationName = requestURL;
|
||||
}
|
||||
|
||||
HttpServletRequest request = (HttpServletRequest)ContextManager.getRuntimeContext().get(REQUEST_KEY_IN_RUNTIME_CONTEXT);
|
||||
|
|
@ -73,7 +82,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);
|
||||
|
|
|
|||
|
|
@ -16,7 +16,6 @@
|
|||
*
|
||||
*/
|
||||
|
||||
|
||||
package org.apache.skywalking.apm.plugin.spring.mvc.commons.interceptor;
|
||||
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
|
|
@ -25,7 +24,7 @@ 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
|
||||
*/
|
||||
|
|
@ -41,4 +40,21 @@ public class RequestMappingMethodInterceptor extends AbstractMethodInterceptor {
|
|||
}
|
||||
return requestURL;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAcceptedMethodTypes(Method method) {
|
||||
RequestMapping methodRequestMapping = method.getAnnotation(RequestMapping.class);
|
||||
StringBuilder methodTypes = new StringBuilder();
|
||||
if (methodRequestMapping.method().length > 0) {
|
||||
methodTypes.append("{");
|
||||
for (int i = 0; i < methodRequestMapping.method().length; i++) {
|
||||
methodTypes.append(methodRequestMapping.method()[i].toString());
|
||||
if (methodRequestMapping.method().length > (i + 1)) {
|
||||
methodTypes.append(",");
|
||||
}
|
||||
}
|
||||
methodTypes.append("}");
|
||||
}
|
||||
return methodTypes.toString();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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 <code>RestMappingMethodInterceptor</code> only use the first mapping value.
|
||||
* it will inteceptor with
|
||||
* it will interceptor with
|
||||
* <code>@GetMapping</code>, <code>@PostMapping</code>, <code>@PutMapping</code>
|
||||
* <code>@DeleteMapping</code>, <code>@PatchMapping</code>
|
||||
*
|
||||
|
|
@ -73,4 +72,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);
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
@ -39,4 +38,21 @@ public class RequestMappingMethodInterceptor extends AbstractMethodInterceptor {
|
|||
}
|
||||
return requestURL;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAcceptedMethodTypes(Method method) {
|
||||
RequestMapping methodRequestMapping = method.getAnnotation(RequestMapping.class);
|
||||
StringBuilder methodTypes = new StringBuilder();
|
||||
if (methodRequestMapping.method().length > 0) {
|
||||
methodTypes.append("{");
|
||||
for (int i = 0; i < methodRequestMapping.method().length; i++) {
|
||||
methodTypes.append(methodRequestMapping.method()[i].toString());
|
||||
if (methodRequestMapping.method().length > (i + 1)) {
|
||||
methodTypes.append(",");
|
||||
}
|
||||
}
|
||||
methodTypes.append("}");
|
||||
}
|
||||
return methodTypes.toString();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -74,4 +74,9 @@ public class RestMappingMethodInterceptor extends AbstractMethodInterceptor {
|
|||
}
|
||||
return requestURL;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAcceptedMethodTypes(Method method) {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
@ -40,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) {
|
||||
if (operationName.length() == 0 || Config.Plugin.Toolkit.USE_QUALIFIED_NAME_AS_OPERATION_NAME) {
|
||||
operationName = MethodUtil.generateOperationName(method);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -205,7 +205,6 @@ Zookeeper:
|
|||
id: 58
|
||||
languages: Java
|
||||
|
||||
|
||||
# .NET/.NET Core components
|
||||
# [3000, 4000) for C#/.NET only
|
||||
AspNetCore:
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
||||
|
|
@ -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_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.
|
||||
|
|
|
|||
|
|
@ -205,7 +205,6 @@ Zookeeper:
|
|||
id: 58
|
||||
languages: Java
|
||||
|
||||
|
||||
# .NET/.NET Core components
|
||||
# [3000, 4000) for C#/.NET only
|
||||
AspNetCore:
|
||||
|
|
|
|||
Loading…
Reference in New Issue