Correlate logs from different threads within the same request with sleuth or micrometer

21 views Asked by At

Using spring sleuth or micrometer, what happens if I have a class like this:

public class Class1{

    private Class2 class2;
    
    public ClientDataResponse find(List<ClientDataRequest> clientDataRequestList) {    
          //for each element in the clientDataRequestList I call find in the class Class2 in different thread;
    }   

}


public class Class2{

     public ClientDataResponse find(ClientDataRequest clientDataRequest) {
      //process in different thread 
      //some operations
      //call to rest service        
   } 

}

I can propagate traceId to all the threads and for each thread I create a new spanId. No problem here, traceId for all the request and spanId for each Thread but with sleuth o micrometer, the spanId is changed whenever a rest service call is made.

  • So how can I determine for example if a log from a http client request with its traceId and spanId is made from one thread o another if the rest call changed the spanId that had originally the thread?.

I think rest http clients should generate a new spanId but maintaining the parentSpanId from the thread but with this logging I dont see the parentId(its empty in the logs from the httpClient)

logging:
  pattern:
    level: "%5p [${spring.application.name:},%X{traceId:-},%X{spanId:-},%X{parentSpanId :-}]"

Thanks

0

There are 0 answers