I am trying to setup tracing of multithread application. I have set up ThreadPool:
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
executor.setCorePoolSize(corePoolSize);
executor.setMaxPoolSize(maxPoolSize);
executor.setQueueCapacity(queueCapacity);
executor.setThreadNamePrefix("XXXXXX-");
executor.initialize();
so there are several threads. One of the threads is listening to the SQS queue:
@Scheduled(fixedRateString = "${processing.queue.period:60000}")
public void process() {
..........................................................................
for (SQSMessage sqsMessage : sqsMessages) {
String messageReceiptHandle = null;
try {
messageReceiptHandle = sqsMessage.getReceiptHandle();
processMessage(sqsMessage);
}
}
}
..........................................................................
public void processMessage(SQSMessage sqsMessage) throws InterruptedException {
log.debug("Start Processing request: '{}'.", sqsMessage);
monitoringWorker.addEntityForMonitoring(sqsMessage, processor);
processor.processMessage(sqsMessage);
monitoringWorker.removeEntityForMonitoring(sqsMessage.getStagingPrefix());
}
In this code snipet
monitoringWorker.addEntityForMonitoring(sqsMessage, processor);
sqsMessage is propagated to another scheduler:
@Component
public class MonitoringWorker {
private List<EntityToMonitor> entitiesForMonitoring = new ArrayList<>();
public void addEntityForMonitoring(AssetSQSMessage assetSQSMessage, AssetProcessorService service) {
entitiesForMonitoring.add(new EntityToMonitor(assetSQSMessage, service));
}
@Scheduled(fixedDelay = 1000)
public void monitor() {
for (EntityToMonitor entity : entitiesForMonitoring) {
log.info("testmessage");
}
}
the idea is to trace all the process from recieving message from SQS till the end of processing logic but all the thread has different trace ids, And when MonitoringWorker starts to process the message it takes another thread with different traceid:
How can I keep the same traceid, spanid could be different in Spring Cloud Sleuth 2.2.3