xue2lang opened a new issue, #17834:
URL: https://github.com/apache/shardingsphere/issues/17834

   ## Question
   now, i use shardingsphere-agent in sharding-proxy to record trace, the trace 
plugin is zipkin, i want record traceid into log,  but don not know how to bury 
the code , please see the steps:
   
   
   * step 1 : add log support dependency
   ```java
   
       @Override
       public void start(final PluginConfiguration pluginConfig) {
           if (!checkConfig(pluginConfig)) {
               throw new PluginConfigurationException("zipkin config error, 
host is null or port is %s", pluginConfig.getPort());
           }
           Properties props = pluginConfig.getProps();
           String urlVersion = 
Optional.ofNullable(props.getProperty("URL_VERSION")).orElse("/api/v2/spans");
           String serviceName = 
Optional.ofNullable(props.getProperty("SERVICE_NAME")).orElse("shardingsphere-agent");
           String token = 
Optional.ofNullable(props.getProperty("TOKEN")).orElse("");
           sender = OkHttpSender.create(String.format("http://%s:%s%s%s";, 
pluginConfig.getHost(), pluginConfig.getPort(), token != null && token.length() 
> 0 ? "/" + token : token, urlVersion));
           Sampler sampler = createSampler(pluginConfig);
           zipkinSpanHandler = AsyncZipkinSpanHandler.create(sender);
           tracing = 
Tracing.newBuilder().localServiceName(serviceName).sampler(sampler).addSpanHandler(zipkinSpanHandler)
                 
                   //add MDCScopeDecorator for add trace to MDC 
                      .currentTraceContext(
                           ThreadLocalCurrentTraceContext.newBuilder()
                           .addScopeDecorator(MDCScopeDecorator.get())
                           .build()
                   )
   
   
               .build();
       }
   ```
   * step 2:how to bury the code  in agent plugin of zipkin ,have any suggest 
????
   if we want record trace , we must get the currentTraceContext from Tracing, 
then execute code like this 
   ```java
   
   Scope scope = currentTraceContext.newScope(span.context());
   try{
    //  .....  business code
   }finally{
    scope.close();
   }
   
   ```
   
   
   
   **For English only**, other languages will not accept.
   
   Before asking a question, make sure you have:
   
   - Googled your question.
   - Searched open and closed [GitHub 
issues](https://github.com/apache/shardingsphere/issues).
   - Read documentation: [ShardingSphere 
Doc](https://shardingsphere.apache.org/document/current/en/overview).
   
   Please pay attention on issues you submitted, because we maybe need more 
details. 
   If no response anymore and we cannot reproduce it on current information, we 
will **close it**.
   


-- 
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: 
notifications-unsubscr...@shardingsphere.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to