yaboofzu opened a new issue, #10316:
URL: https://github.com/apache/skywalking/issues/10316

   ### Search before asking
   
   - [X] I had searched in the 
[issues](https://github.com/apache/skywalking/issues?q=is%3Aissue) and found no 
similar feature requirement.
   
   
   ### Description
   
   在bootstrap-plugin/jdk-threading-plugin,多线程实现类在执行Run 或 Call 
方法时,一定会产生Trace上下文(上游有则依赖,如果没有,则创建),但在bootstrap-plugin/[jdk-threadpool-plugin]中,线程池执行内部方法时,会依赖上游trace上下文,即如果没有Trace上下文,则不会创建trace上下文。这里存在类似场景但实现不一致的情况。
   
在我们实际项目中,我们并不希望多线程实现类在执行方法时创建Trace上下文,而是希望依赖上游的Trace上下文(有则创建,没有则无需创建),跟线程池增强保持一致。因此这里期望增加一个开关配置,由使用方来控制
 或者完全依赖上游的Trace上下文。
   In bootstrap-plugin/jdk-threading-plugin, multithreaded enhance must 
generate a Trace context,but In bootstrap-plugin/jdk-threadpool-plugin,the 
threadpool relies on the upstream trace context when executing internal 
methods, that is, if there is no Trace context, no trace context is created. 
There are similar scenarios but inconsistent implementations.
   In our actual project, we do not want a multithreaded implementation class 
to create a Trace context when executing  method. Instead, we want to rely on 
an upstream Trace context, consistent with  
bootstrap-plugin/jdk-threadpool-plugin,So it is expected to add a switch 
configuration that is controlled by the user or completely dependent on the 
upstream Trace context .
   
   ### Use case
   
   public class ThreadingMethodInterceptor implements 
InstanceMethodsAroundInterceptor {
   
       @Override
       public void beforeMethod(final EnhancedInstance objInst, final Method 
method, final Object[] allArguments,
           final Class<?>[] argumentsTypes, final MethodInterceptResult result) 
{
           //CN:没有判断Trace上下文是否存在,建议增加一个开关配置或者增加一个上下文依赖判断
          // En:do not judge the TraceContext exist, I advised to here add a 
switch configuration or add juage TraceContext exist
           AbstractSpan span = 
ContextManager.createLocalSpan(generateOperationName(objInst, method));
           span.setComponent(ComponentsDefine.JDK_THREADING);
   
           final Object storedField = objInst.getSkyWalkingDynamicField();
           if (storedField != null) {
               final ContextSnapshot contextSnapshot = (ContextSnapshot) 
storedField;
               ContextManager.continued(contextSnapshot);
           }
   
       }
   ....
   }
   
   
   ### Related issues
   
   多线程类执行内部Run方法如果有个Kafka consumer 消费消息时,会出现traceId 重复的情况。
   A multithreaded class executing an internal Run method will repeat the 
traceId if there is a Kafka consumer consumption message.
   
   ### Are you willing to submit a PR?
   
   - [X] Yes I am willing to submit a PR!
   
   ### Code of Conduct
   
   - [X] I agree to follow this project's [Code of 
Conduct](https://www.apache.org/foundation/policies/conduct)
   


-- 
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.

To unsubscribe, e-mail: 
[email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to