yasuo-deng opened a new issue, #13032:
URL: https://github.com/apache/skywalking/issues/13032

   ### Search before asking
   
   - [x] I had searched in the 
[issues](https://github.com/apache/skywalking/issues?q=is%3Aissue) and found no 
similar issues.
   
   
   ### Apache SkyWalking Component
   
   OAP server (apache/skywalking)
   
   ### What happened
   
   
   
   
![Image](https://github.com/user-attachments/assets/023fd35e-91ba-4371-8fad-bc54119fe0c1),
   
   My application logback configuration:
   
   ```
   <?xml version="1.0" encoding="UTF-8"?>
   <!DOCTYPE configuration>
   <configuration>
       <appender name="kafkaAppender" 
class="net.trueland.logback.KafkaAppender">
           <encoder charset="UTF-8" 
class="net.logstash.logback.encoder.LogstashEncoder">
               <provider 
class="org.apache.skywalking.apm.toolkit.log.logback.v1.x.logstash.TraceIdJsonProvider"/>
               
<customFields>{"appname":"log-cdp-tag","version":"v-20241119"}</customFields>
               <includeMdc>true</includeMdc>
               <includeContext>true</includeContext>
               <throwableConverter 
class="net.logstash.logback.stacktrace.ShortenedThrowableConverter">
                   <maxDepthPerThrowable>30</maxDepthPerThrowable>
                   <rootCauseFirst>true</rootCauseFirst>
               </throwableConverter>
           </encoder>
           <topic>log-growth-cdp</topic>
           <keyingStrategy 
class="net.trueland.logback.keying.HostNameKeyingStrategy"/>
           <deliveryStrategy 
class="net.trueland.logback.delivery.AsynchronousDeliveryStrategy"/>
           <producerConfig>bootstrap.servers=kafka1:9092</producerConfig>
           <!-- don't wait for a broker to ack the reception of a batch.  -->
           <producerConfig>acks=0</producerConfig>
           <!-- wait up to 1000ms and collect log messages before sending them 
as a batch -->
           <producerConfig>linger.ms=1000</producerConfig>
           <!-- even if the producer buffer runs full, do not block the 
application but start to drop messages -->
           <!--<producerConfig>max.block.ms=0</producerConfig>-->
           <producerConfig>block.on.buffer.full=false</producerConfig>
       </appender>
       <include resource="org/springframework/boot/logging/logback/base.xml"/>
       <root level="INFO">
           <appender-ref ref="kafkaAppender"/>
       </root>
   </configuration>
   ```
   
   
   ### What you expected to happen
   
   It should be normal without any errors, and when I access my application 
interface, the interface will report that the traceId corresponding to 
skywalking is set to the requestId in ResponseMessage
   
   ### How to reproduce
   
   The command I executed is as follows ` java -Xms3072m -Xmx3072m 
-javaagent:/sky/agent/skywalking-agent.jar  
-javaagent:/tracing/agent/trace-agent.jar 
-Dskywalking.agent.is_cache_enhanced_class=true 
-Dskywalking.agent.class_cache_mode=MEMORY 
-Dskywalking.agent.service_name=cdp-tag 
-Dskywalking.collector.backend_service=192.168.245.88:11800 -jar 
/tmp/app.jar`,The skywaling version is 8.7.0, with error messages
   
   ### Anything else
   
   Customize agent code: 
   
   
   ```import net.bytebuddy.agent.builder.AgentBuilder;
   import net.bytebuddy.asm.Advice;
   import net.bytebuddy.description.type.TypeDescription;
   import net.bytebuddy.dynamic.DynamicType;
   import net.bytebuddy.matcher.ElementMatchers;
   import net.bytebuddy.utility.JavaModule;
   
   import java.lang.instrument.Instrumentation;
   import java.security.ProtectionDomain;
   import java.util.logging.Level;
   import java.util.logging.Logger;
   
   
   public class LoggingAgent {
   
       private static final Logger logger = 
Logger.getLogger(LoggingAgent.class.getName());
       private static boolean premainCalled = false;
   
       public static void premain(String agentArgs, Instrumentation inst) {
           if (premainCalled) {
               logger.log(Level.INFO, "agentmain method has already been 
called, skipping.");
               return;
           }
           premainCalled = true;
           try {
               new AgentBuilder.Default()
                       
.type(ElementMatchers.nameStartsWith("net.trueland.cdp.tag.controller"))
                       .transform(new AgentBuilder.Transformer() {
                           @Override
                           public DynamicType.Builder<?> transform(
                                   DynamicType.Builder<?> builder,
                                   TypeDescription typeDescription,
                                   ClassLoader classLoader,
                                   JavaModule module,
                                   ProtectionDomain protectionDomain
                           ) {
                               return 
builder.method(ElementMatchers.returns(net.trueland.common.ResponseMessage.class))
                                       
.intercept(Advice.to(ResponseInterceptor.class));
                           }
                       })
                       .with(new AgentBuilder.Listener.Adapter() {
                           @Override
                           public void onError(String typeName, ClassLoader 
classLoader, JavaModule module, boolean loaded, Throwable throwable) {
                               logger.log(Level.SEVERE, "处理类 {0} 时出错: {1}", new 
Object[]{typeName, throwable.getMessage()});
                           }
                       })
                       .installOn(inst);
           } catch (Exception e) {
               logger.log(Level.INFO, "Java Agent 初始化失败: {0}", e.getMessage());
               e.printStackTrace();
           }
   
           logger.log(Level.INFO, "Java Trace Agent initialized.");
       }
   }
   
   import net.bytebuddy.asm.Advice;
   import net.trueland.common.ResponseMessage;
   import org.apache.skywalking.apm.toolkit.trace.TraceContext;
   
   public class ResponseInterceptor {
   
       @Advice.OnMethodExit(onThrowable = Throwable.class)
       public static void intercept(@Advice.Return(readOnly = false) 
ResponseMessage<?> returnValue, @Advice.Origin Class<?> originClass) {
           try {
               if (returnValue == null) {
                   return;
               }
               String traceId = TraceContext.traceId();
               returnValue.setRequestId(traceId);
           } catch (Exception e) {
               e.printStackTrace();
           }
       }
   }```
   
   ### Are you willing to submit a pull request to fix on your own?
   
   - [ ] Yes I am willing to submit a pull request on my own!
   
   ### 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