You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@skywalking.apache.org by GitBox <gi...@apache.org> on 2019/04/28 13:25:04 UTC

[GitHub] [skywalking] wu-sheng commented on a change in pull request #2551: Fix #2546

wu-sheng commented on a change in pull request #2551: Fix #2546
URL: https://github.com/apache/skywalking/pull/2551#discussion_r279194466
 
 

 ##########
 File path: apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-commons/src/main/java/org/apache/skywalking/apm/plugin/spring/mvc/commons/interceptor/AbstractMethodInterceptor.java
 ##########
 @@ -75,19 +79,44 @@ public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allAr
 
         HttpServletRequest request = (HttpServletRequest)ContextManager.getRuntimeContext().get(REQUEST_KEY_IN_RUNTIME_CONTEXT);
         if (request != null) {
-            ContextCarrier contextCarrier = new ContextCarrier();
-            CarrierItem next = contextCarrier.items();
-            while (next.hasNext()) {
-                next = next.next();
-                next.setHeadValue(request.getHeader(next.getHeadKey()));
+            Object stackDepth = ContextManager.getRuntimeContext().get(CONTROLLER_METHOD_STACK_DEPTH);
+            Integer depth = stackDepth == null ? 0 : Integer.parseInt(stackDepth.toString());
+
+            if (depth == 0) {
+                ContextCarrier contextCarrier = new ContextCarrier();
+                CarrierItem next = contextCarrier.items();
+                while (next.hasNext()) {
+                    next = next.next();
+                    next.setHeadValue(request.getHeader(next.getHeadKey()));
+                }
+
+                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);
+                SpanLayer.asHttp(span);
+            } else {
+                AbstractSpan span =
+                    ContextManager.createLocalSpan(buildOperationName(objInst, method));
+                span.setComponent(ComponentsDefine.SPRING_MVC_ANNOTATION);
             }
 
-            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);
-            SpanLayer.asHttp(span);
+            ContextManager.getRuntimeContext().put(CONTROLLER_METHOD_STACK_DEPTH, depth++);
 
 Review comment:
   Put depth in a ControllerDepth class, and polish the codes.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services