kezhenxu94 commented on a change in pull request #4327: Tag annotation supports 
returned expression
URL: https://github.com/apache/skywalking/pull/4327#discussion_r377997459
 
 

 ##########
 File path: 
apm-sniffer/apm-toolkit-activation/apm-toolkit-trace-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/trace/TagAnnotationMethodInterceptor.java
 ##########
 @@ -46,23 +46,47 @@ public void beforeMethod(final EnhancedInstance objInst, 
final Method method, fi
         final Tags tags = method.getAnnotation(Tags.class);
         if (tags != null && tags.value().length > 0) {
             for (final Tag tag : tags.value()) {
-                tagSpan(activeSpan, tag, context);
+                if (!TagUtil.isReturnTag(tag.value())) {
+                    TagUtil.tagParamsSpan(activeSpan, context, tag);
+                }
             }
         }
 
         final Tag tag = method.getAnnotation(Tag.class);
-        if (tag != null) {
-            tagSpan(activeSpan, tag, context);
+        if (tag != null && !TagUtil.isReturnTag(tag.value())) {
+            TagUtil.tagParamsSpan(activeSpan, context, tag);
         }
     }
 
-    private void tagSpan(final AbstractSpan span, final Tag tag, final 
Map<String, Object> context) {
-        new StringTag(tag.key()).set(span, 
CustomizeExpression.parseExpression(tag.value(), context));
-    }
 
     @Override
-    public Object afterMethod(final EnhancedInstance objInst, final Method 
method, final Object[] allArguments,
-        final Class<?>[] argumentsTypes, final Object ret) {
+    public Object afterMethod(
+        final EnhancedInstance objInst,
+        final Method method,
+        final Object[] allArguments,
+        final Class<?>[] argumentsTypes,
+        final Object ret) {
+        try {
+            if (ret == null || !ContextManager.isActive()) {
+                return ret;
+            }
+            final AbstractSpan localSpan = ContextManager.activeSpan();
+            final Map<String, Object> context = 
CustomizeExpression.evaluationReturnContext(ret);
+            final Tags tags = method.getAnnotation(Tags.class);
+            if (tags != null && tags.value().length > 0) {
+                for (final Tag tag : tags.value()) {
+                    if (TagUtil.isReturnTag(tag.value())) {
+                        TagUtil.tagReturnSpanSpan(localSpan, context, tag);
+                    }
+                }
+            }
+            final Tag tag = method.getAnnotation(Tag.class);
+            if (tag != null && TagUtil.isReturnTag(tag.value())) {
+                TagUtil.tagReturnSpanSpan(localSpan, context, tag);
+            }
+        } finally {
+            ContextManager.stopSpan();
 
 Review comment:
   We don't create span in the `#beforeMethod`, so please remove the 
`stopSpan()` here, we  cannot stop a span by mistake here

----------------------------------------------------------------
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:
[email protected]


With regards,
Apache Git Services

Reply via email to